rfc3961: Add a kernel rfc3961 implementation
[openafs.git] / src / crypto / hcrypto / kernel / alloc.c
index 7ec6029..158d3bd 100644 (file)
@@ -50,3 +50,35 @@ _afscrypto_free(void *ptr)
     if (ptr != NULL)
        afs_osi_Free(ptr, 0);
 }
+
+char*
+_afscrypto_strdup(const char *str) {
+    char *ptr;
+
+    ptr = malloc(strlen(str));
+    if (ptr == NULL)
+       return ptr;
+    memcpy(ptr, str, strlen(str));
+
+    return ptr;
+}
+
+/* This is a horrible, horrible bodge, but the crypto code uses realloc,
+ * so we need to handle it too.
+ *
+ * There are two different call sites for realloc. Firstly, it's used
+ * in the decrypt case to shrink the size of the allotted buffer. In
+ * this case, we can just ignore the realloc and return the original
+ * pointer.
+ *
+ * Secondly, it's used when computing derived keys. In this case, the
+ * first call will be with a NULL input, and the size of a single
+ * derived key. So, we just give back space for 20 keys, and pray.
+ */
+
+void *
+_afscrypto_realloc(void *ptr, size_t len) {
+   if (ptr == NULL)
+       return calloc(20, len);
+   return ptr;
+}