aboutsummaryrefslogtreecommitdiffstats
path: root/lib/crypto/c_src/digest.c
diff options
context:
space:
mode:
authorDoug Hogan <[email protected]>2018-12-20 02:01:41 -0800
committerDoug Hogan <[email protected]>2018-12-20 02:30:29 -0800
commit8943f7e510c9029ba01de480f63c6eaf670ee120 (patch)
tree7488ae4715d58b35052b651f18c22ba0be52ccdd /lib/crypto/c_src/digest.c
parent21cd1994c280c705e99d48ae09f2d94e348875a3 (diff)
downloadotp-8943f7e510c9029ba01de480f63c6eaf670ee120.tar.gz
otp-8943f7e510c9029ba01de480f63c6eaf670ee120.tar.bz2
otp-8943f7e510c9029ba01de480f63c6eaf670ee120.zip
Move digest types to a new file
Diffstat (limited to 'lib/crypto/c_src/digest.c')
-rw-r--r--lib/crypto/c_src/digest.c91
1 files changed, 91 insertions, 0 deletions
diff --git a/lib/crypto/c_src/digest.c b/lib/crypto/c_src/digest.c
new file mode 100644
index 0000000000..ba879ab464
--- /dev/null
+++ b/lib/crypto/c_src/digest.c
@@ -0,0 +1,91 @@
+#include "digest.h"
+
+static struct digest_type_t digest_types[] =
+{
+ {{"md4"}, {&EVP_md4}},
+ {{"md5"}, {&EVP_md5}},
+ {{"ripemd160"}, {&EVP_ripemd160}},
+ {{"sha"}, {&EVP_sha1}},
+ {{"sha224"},
+#ifdef HAVE_SHA224
+ {&EVP_sha224}
+#else
+ {NULL}
+#endif
+ },
+ {{"sha256"},
+#ifdef HAVE_SHA256
+ {&EVP_sha256}
+#else
+ {NULL}
+#endif
+ },
+ {{"sha384"},
+#ifdef HAVE_SHA384
+ {&EVP_sha384}
+#else
+ {NULL}
+#endif
+ },
+ {{"sha512"},
+#ifdef HAVE_SHA512
+ {&EVP_sha512}
+#else
+ {NULL}
+#endif
+ },
+ {{"sha3_224"},
+#ifdef HAVE_SHA3_224
+ {&EVP_sha3_224}
+#else
+ {NULL}
+#endif
+ },
+ {{"sha3_256"},
+#ifdef HAVE_SHA3_256
+ {&EVP_sha3_256}
+#else
+ {NULL}
+#endif
+ },
+ {{"sha3_384"},
+#ifdef HAVE_SHA3_384
+ {&EVP_sha3_384}
+#else
+ {NULL}
+#endif
+ },
+ {{"sha3_512"},
+#ifdef HAVE_SHA3_512
+ {&EVP_sha3_512}
+#else
+ {NULL}
+#endif
+ },
+
+ {{NULL}}
+};
+
+void init_digest_types(ErlNifEnv* env)
+{
+ struct digest_type_t* p = digest_types;
+
+ for (p = digest_types; p->type.str; p++) {
+ p->type.atom = enif_make_atom(env, p->type.str);
+ if (p->md.funcp)
+ p->md.p = p->md.funcp();
+ }
+ p->type.atom = atom_false; /* end marker */
+}
+
+struct digest_type_t* get_digest_type(ERL_NIF_TERM type)
+{
+ struct digest_type_t* p = NULL;
+ for (p = digest_types; p->type.atom != atom_false; p++) {
+ if (type == p->type.atom) {
+ return p;
+ }
+ }
+ return NULL;
+}
+