diff options
| author | Nikos Mavrogiannopoulos <nmav@gnutls.org> | 2010-09-06 22:02:15 +0200 |
|---|---|---|
| committer | Nikos Mavrogiannopoulos <nmav@gnutls.org> | 2010-09-06 22:02:38 +0200 |
| commit | a92443718f19ffc36fbe55d85a4785130a4b33c7 (patch) | |
| tree | 79850bdf3cd559d389b2908d17e0e21bdb893b20 /libtomcrypt/hashes | |
| parent | e6177630198eb1eea2def0374fae1196da0e40ec (diff) | |
| download | cryptodev-linux-a92443718f19ffc36fbe55d85a4785130a4b33c7.tar.gz cryptodev-linux-a92443718f19ffc36fbe55d85a4785130a4b33c7.tar.xz cryptodev-linux-a92443718f19ffc36fbe55d85a4785130a4b33c7.zip | |
Algorithm to OID discovery moved to a single place.
Diffstat (limited to 'libtomcrypt/hashes')
| -rw-r--r-- | libtomcrypt/hashes/crypt_hash_is_valid.c | 5 | ||||
| -rw-r--r-- | libtomcrypt/hashes/hash_get_oid.c | 55 |
2 files changed, 9 insertions, 51 deletions
diff --git a/libtomcrypt/hashes/crypt_hash_is_valid.c b/libtomcrypt/hashes/crypt_hash_is_valid.c index 59320a3..4912eb2 100644 --- a/libtomcrypt/hashes/crypt_hash_is_valid.c +++ b/libtomcrypt/hashes/crypt_hash_is_valid.c @@ -9,6 +9,7 @@ * Tom St Denis, tomstdenis@gmail.com, http://libtom.org */ #include "tomcrypt.h" +#include <ncr-int.h> /** @file crypt_hash_is_valid.c @@ -22,7 +23,9 @@ */ int hash_is_valid(const struct algo_properties_st *hash) { - return CRYPT_OK; + if (hash->can_digest == 0) return CRYPT_INVALID_ARG; + + return CRYPT_OK; } /* $Source: /cvs/libtom/libtomcrypt/src/misc/crypt/crypt_hash_is_valid.c,v $ */ diff --git a/libtomcrypt/hashes/hash_get_oid.c b/libtomcrypt/hashes/hash_get_oid.c index 835ffb1..e31e055 100644 --- a/libtomcrypt/hashes/hash_get_oid.c +++ b/libtomcrypt/hashes/hash_get_oid.c @@ -16,60 +16,15 @@ @return CRYPT_OK if valid */ -static const oid_st sha1_oid = { - .OIDlen = 6, - .OID = {1, 3, 14, 3, 2, 26}, -}; - -static const oid_st md5_oid = { - .OIDlen = 6, - .OID = {1, 2, 840, 113549, 2, 5,}, -}; - -static const oid_st sha224_oid = { - .OIDlen = 9, - .OID = {2, 16, 840, 1, 101, 3, 4, 2, 4,}, -}; - -static const oid_st sha256_oid = { - .OIDlen = 9, - .OID = {2, 16, 840, 1, 101, 3, 4, 2, 1,}, -}; - -static const oid_st sha384_oid = { - .OIDlen = 9, - .OID = {2, 16, 840, 1, 101, 3, 4, 2, 2,}, -}; - -static const oid_st sha512_oid = { - .OIDlen = 9, - .OID = {2, 16, 840, 1, 101, 3, 4, 2, 3,}, -}; - int hash_get_oid(const struct algo_properties_st *hash, oid_st * st) { - switch (hash->algo) { - 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: + if (hash->can_digest == 0 || hash->oids[0].key_size != -1) { + /* not a digest */ return CRYPT_INVALID_ARG; } + + memcpy(st, &hash->oids[0].oid, sizeof(*st)); + return CRYPT_OK; } |
