summaryrefslogtreecommitdiffstats
path: root/src/cls_crypto.cc
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-27 18:24:20 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-27 18:24:20 +0000
commit483eb2f56657e8e7f419ab1a4fab8dce9ade8609 (patch)
treee5d88d25d870d5dedacb6bbdbe2a966086a0a5cf /src/cls_crypto.cc
parentInitial commit. (diff)
downloadceph-483eb2f56657e8e7f419ab1a4fab8dce9ade8609.tar.xz
ceph-483eb2f56657e8e7f419ab1a4fab8dce9ade8609.zip
Adding upstream version 14.2.21.upstream/14.2.21upstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'src/cls_crypto.cc')
-rw-r--r--src/cls_crypto.cc77
1 files changed, 77 insertions, 0 deletions
diff --git a/src/cls_crypto.cc b/src/cls_crypto.cc
new file mode 100644
index 00000000..2c93e06e
--- /dev/null
+++ b/src/cls_crypto.cc
@@ -0,0 +1,77 @@
+// -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*-
+// vim: ts=8 sw=2 smarttab
+#include <iostream>
+#include <string.h>
+#include <stdlib.h>
+#include <errno.h>
+
+#include <openssl/md5.h>
+#include <openssl/sha.h>
+
+#include "include/types.h"
+#include "objclass/objclass.h"
+
+CLS_VER(1,0)
+CLS_NAME(crypto)
+
+int md5_method(cls_method_context_t ctx, char *indata, int datalen,
+ char **outdata, int *outdatalen)
+{
+ MD5_CTX c;
+ unsigned char *md;
+
+ cls_log("md5 method");
+ cls_log("indata=%.*s data_len=%d", datalen, indata, datalen);
+
+ md = (unsigned char *)cls_alloc(MD5_DIGEST_LENGTH);
+ if (!md)
+ return -ENOMEM;
+
+ MD5_Init(&c);
+ MD5_Update(&c, indata, (unsigned long)datalen);
+ MD5_Final(md,&c);
+
+ *outdata = (char *)md;
+ *outdatalen = MD5_DIGEST_LENGTH;
+
+ return 0;
+}
+
+int sha1_method(cls_method_context_t ctx, char *indata, int datalen,
+ char **outdata, int *outdatalen)
+{
+ SHA_CTX c;
+ unsigned char *md;
+
+ cls_log("sha1 method");
+ cls_log("indata=%.*s data_len=%d", datalen, indata, datalen);
+
+ md = (unsigned char *)cls_alloc(SHA_DIGEST_LENGTH);
+ if (!md)
+ return -ENOMEM;
+
+ SHA1_Init(&c);
+ SHA1_Update(&c, indata, (unsigned long)datalen);
+ SHA1_Final(md,&c);
+
+ *outdata = (char *)md;
+ *outdatalen = SHA_DIGEST_LENGTH;
+
+ return 0;
+}
+
+CLS_INIT(crypto)
+{
+ cls_log("Loaded crypto class!");
+
+ cls_handle_t h_class;
+ cls_method_handle_t h_md5;
+ cls_method_handle_t h_sha1;
+
+ cls_register("crypto", &h_class);
+ cls_register_method(h_class, "md5", CLS_METHOD_RD, md5_method, &h_md5);
+ cls_register_method(h_class, "sha1", CLS_METHOD_RD, sha1_method, &h_sha1);
+
+ return;
+}
+