summaryrefslogtreecommitdiffstats
path: root/libtomcrypt/hashes
diff options
context:
space:
mode:
authorNikos Mavrogiannopoulos <nmav@gnutls.org>2010-07-07 10:40:37 +0200
committerNikos Mavrogiannopoulos <nmav@gnutls.org>2010-07-07 10:41:04 +0200
commit115f165b6e3bb74f45e13a65c5f4f82f28664a2c (patch)
treeec55b63c736b5bef6061202c8bd31b08796fa2dc /libtomcrypt/hashes
parent58a20b797e5a987fc8f7c5bea3be24d754908bf5 (diff)
downloadcryptodev-linux-115f165b6e3bb74f45e13a65c5f4f82f28664a2c.tar.gz
cryptodev-linux-115f165b6e3bb74f45e13a65c5f4f82f28664a2c.tar.xz
cryptodev-linux-115f165b6e3bb74f45e13a65c5f4f82f28664a2c.zip
Added a modified libtomcrypt with DSA and RSA algorithms.
Diffstat (limited to 'libtomcrypt/hashes')
-rw-r--r--libtomcrypt/hashes/hash_get_oid.c78
-rw-r--r--libtomcrypt/hashes/hash_memory.c6
-rw-r--r--libtomcrypt/hashes/hash_memory_multi.c8
3 files changed, 83 insertions, 9 deletions
diff --git a/libtomcrypt/hashes/hash_get_oid.c b/libtomcrypt/hashes/hash_get_oid.c
new file mode 100644
index 0000000..0a761b1
--- /dev/null
+++ b/libtomcrypt/hashes/hash_get_oid.c
@@ -0,0 +1,78 @@
+/* LibTomCrypt, modular cryptographic library
+ *
+ * LibTomCrypt is a library that provides various cryptographic
+ * algorithms in a highly modular and flexible manner.
+ *
+ * The library is free for all purposes without any express
+ * guarantee it works.
+ *
+ */
+#include "tomcrypt.h"
+#include <ncr_int.h>
+
+/*
+ Returns the OID of the hash.
+ @param idx The hash identifier of the hash to search for
+ @return CRYPT_OK if valid
+*/
+
+const oid_st sha1_oid = {
+ .OIDlen = 6,
+ .OID = { 1, 3, 14, 3, 2, 26 },
+};
+
+const oid_st md5_oid = {
+ .OIDlen = 6,
+ .OID = { 1, 2, 840, 113549, 2, 5, },
+};
+
+const oid_st sha224_oid = {
+ .OIDlen = 9,
+ .OID = { 2, 16, 840, 1, 101, 3, 4, 2, 4, },
+};
+
+const oid_st sha256_oid = {
+ .OIDlen = 9,
+ .OID = { 2, 16, 840, 1, 101, 3, 4, 2, 1, },
+};
+
+const oid_st sha384_oid = {
+ .OIDlen = 9,
+ .OID = { 2, 16, 840, 1, 101, 3, 4, 2, 2, },
+};
+
+const oid_st sha512_oid = {
+ .OIDlen = 9,
+ .OID = { 2, 16, 840, 1, 101, 3, 4, 2, 3, },
+};
+
+int hash_get_oid(int hash, oid_st *st)
+{
+ switch (hash) {
+ case NCR_ALG_SHA1:
+ memcpy(st, &sha1_oid, sizeof(*st));
+ break;
+ case NCR_ALG_MD5:
+ memcpy(st, &md5_oid, sizeof(*st));
+ break;
+ case NCR_ALG_SHA2_224:
+ memcpy(st, &sha224_oid, sizeof(*st));
+ break;
+ case NCR_ALG_SHA2_256:
+ memcpy(st, &sha256_oid, sizeof(*st));
+ break;
+ case NCR_ALG_SHA2_384:
+ memcpy(st, &sha384_oid, sizeof(*st));
+ break;
+ case NCR_ALG_SHA2_512:
+ memcpy(st, &sha512_oid, sizeof(*st));
+ break;
+ default:
+ return CRYPT_INVALID_ARG;
+ }
+ return CRYPT_OK;
+}
+
+/* $Source: /cvs/libtom/libtomcrypt/src/misc/crypt/crypt_hash_is_valid.c,v $ */
+/* $Revision: 1.6 $ */
+/* $Date: 2006/12/28 01:27:24 $ */
diff --git a/libtomcrypt/hashes/hash_memory.c b/libtomcrypt/hashes/hash_memory.c
index 8775355..274c208 100644
--- a/libtomcrypt/hashes/hash_memory.c
+++ b/libtomcrypt/hashes/hash_memory.c
@@ -29,7 +29,6 @@
int hash_memory(int hash, const unsigned char *in, unsigned long inlen, unsigned char *out, unsigned long *outlen)
{
int err;
- const char* str;
struct hash_data hdata;
int digest_size;
@@ -47,7 +46,7 @@ int hash_memory(int hash, const unsigned char *in, unsigned long inlen, unsigned
return CRYPT_BUFFER_OVERFLOW;
}
- err = cryptodev_hash_init( &data, _ncr_algo_to_str(hash), 0, NULL, 0);
+ err = cryptodev_hash_init( &hdata, _ncr_algo_to_str(hash), 0, NULL, 0);
if (err < 0) {
err = CRYPT_INVALID_HASH;
goto LBL_ERR;
@@ -63,9 +62,6 @@ int hash_memory(int hash, const unsigned char *in, unsigned long inlen, unsigned
*outlen = digest_size;
LBL_ERR:
cryptodev_hash_deinit(&hdata);
-#ifdef LTC_CLEAN_STACK
- zeromem(md, sizeof(hash_state));
-#endif
return err;
}
diff --git a/libtomcrypt/hashes/hash_memory_multi.c b/libtomcrypt/hashes/hash_memory_multi.c
index c9fafc7..6a85f65 100644
--- a/libtomcrypt/hashes/hash_memory_multi.c
+++ b/libtomcrypt/hashes/hash_memory_multi.c
@@ -10,6 +10,9 @@
*/
#include "tomcrypt.h"
#include <stdarg.h>
+#include <ncr_int.h>
+#include <cryptodev_int.h>
+
/**
@file hash_memory_multi.c
Hash (multiple buffers) memory helper, Tom St Denis
@@ -49,7 +52,7 @@ int hash_memory_multi(int hash, unsigned char *out, unsigned long *outlen,
return CRYPT_BUFFER_OVERFLOW;
}
- err = cryptodev_hash_init( &data, _ncr_algo_to_str(hash), 0, NULL, 0);
+ err = cryptodev_hash_init( &hdata, _ncr_algo_to_str(hash), 0, NULL, 0);
if (err < 0) {
err = CRYPT_INVALID_HASH;
goto LBL_ERR;
@@ -76,9 +79,6 @@ int hash_memory_multi(int hash, unsigned char *out, unsigned long *outlen,
*outlen = digest_size;
LBL_ERR:
-#ifdef LTC_CLEAN_STACK
- zeromem(md, sizeof(hash_state));
-#endif
cryptodev_hash_deinit(&hdata);
va_end(args);
return err;