mbed TLS Build
tests/suites/test_suite_shax.function@0:cdf462088d13, 2017-01-05 (annotated)
- Committer:
- markrad
- Date:
- Thu Jan 05 00:18:44 2017 +0000
- Revision:
- 0:cdf462088d13
Initial commit
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
markrad | 0:cdf462088d13 | 1 | /* BEGIN_HEADER */ |
markrad | 0:cdf462088d13 | 2 | #include "mbedtls/sha1.h" |
markrad | 0:cdf462088d13 | 3 | #include "mbedtls/sha256.h" |
markrad | 0:cdf462088d13 | 4 | #include "mbedtls/sha512.h" |
markrad | 0:cdf462088d13 | 5 | /* END_HEADER */ |
markrad | 0:cdf462088d13 | 6 | |
markrad | 0:cdf462088d13 | 7 | /* BEGIN_CASE depends_on:MBEDTLS_SHA1_C */ |
markrad | 0:cdf462088d13 | 8 | void mbedtls_sha1( char *hex_src_string, char *hex_hash_string ) |
markrad | 0:cdf462088d13 | 9 | { |
markrad | 0:cdf462088d13 | 10 | unsigned char src_str[10000]; |
markrad | 0:cdf462088d13 | 11 | unsigned char hash_str[10000]; |
markrad | 0:cdf462088d13 | 12 | unsigned char output[41]; |
markrad | 0:cdf462088d13 | 13 | int src_len; |
markrad | 0:cdf462088d13 | 14 | |
markrad | 0:cdf462088d13 | 15 | memset(src_str, 0x00, 10000); |
markrad | 0:cdf462088d13 | 16 | memset(hash_str, 0x00, 10000); |
markrad | 0:cdf462088d13 | 17 | memset(output, 0x00, 41); |
markrad | 0:cdf462088d13 | 18 | |
markrad | 0:cdf462088d13 | 19 | src_len = unhexify( src_str, hex_src_string ); |
markrad | 0:cdf462088d13 | 20 | |
markrad | 0:cdf462088d13 | 21 | mbedtls_sha1( src_str, src_len, output ); |
markrad | 0:cdf462088d13 | 22 | hexify( hash_str, output, 20 ); |
markrad | 0:cdf462088d13 | 23 | |
markrad | 0:cdf462088d13 | 24 | TEST_ASSERT( strcmp( (char *) hash_str, hex_hash_string ) == 0 ); |
markrad | 0:cdf462088d13 | 25 | } |
markrad | 0:cdf462088d13 | 26 | /* END_CASE */ |
markrad | 0:cdf462088d13 | 27 | |
markrad | 0:cdf462088d13 | 28 | /* BEGIN_CASE depends_on:MBEDTLS_SHA256_C */ |
markrad | 0:cdf462088d13 | 29 | void sha224(char *hex_src_string, char *hex_hash_string ) |
markrad | 0:cdf462088d13 | 30 | { |
markrad | 0:cdf462088d13 | 31 | unsigned char src_str[10000]; |
markrad | 0:cdf462088d13 | 32 | unsigned char hash_str[10000]; |
markrad | 0:cdf462088d13 | 33 | unsigned char output[57]; |
markrad | 0:cdf462088d13 | 34 | int src_len; |
markrad | 0:cdf462088d13 | 35 | |
markrad | 0:cdf462088d13 | 36 | memset(src_str, 0x00, 10000); |
markrad | 0:cdf462088d13 | 37 | memset(hash_str, 0x00, 10000); |
markrad | 0:cdf462088d13 | 38 | memset(output, 0x00, 57); |
markrad | 0:cdf462088d13 | 39 | |
markrad | 0:cdf462088d13 | 40 | src_len = unhexify( src_str, hex_src_string ); |
markrad | 0:cdf462088d13 | 41 | |
markrad | 0:cdf462088d13 | 42 | mbedtls_sha256( src_str, src_len, output, 1 ); |
markrad | 0:cdf462088d13 | 43 | hexify( hash_str, output, 28 ); |
markrad | 0:cdf462088d13 | 44 | |
markrad | 0:cdf462088d13 | 45 | TEST_ASSERT( strcmp( (char *) hash_str, hex_hash_string ) == 0 ); |
markrad | 0:cdf462088d13 | 46 | } |
markrad | 0:cdf462088d13 | 47 | /* END_CASE */ |
markrad | 0:cdf462088d13 | 48 | |
markrad | 0:cdf462088d13 | 49 | /* BEGIN_CASE depends_on:MBEDTLS_SHA256_C */ |
markrad | 0:cdf462088d13 | 50 | void mbedtls_sha256(char *hex_src_string, char *hex_hash_string ) |
markrad | 0:cdf462088d13 | 51 | { |
markrad | 0:cdf462088d13 | 52 | unsigned char src_str[10000]; |
markrad | 0:cdf462088d13 | 53 | unsigned char hash_str[10000]; |
markrad | 0:cdf462088d13 | 54 | unsigned char output[65]; |
markrad | 0:cdf462088d13 | 55 | int src_len; |
markrad | 0:cdf462088d13 | 56 | |
markrad | 0:cdf462088d13 | 57 | memset(src_str, 0x00, 10000); |
markrad | 0:cdf462088d13 | 58 | memset(hash_str, 0x00, 10000); |
markrad | 0:cdf462088d13 | 59 | memset(output, 0x00, 65); |
markrad | 0:cdf462088d13 | 60 | |
markrad | 0:cdf462088d13 | 61 | src_len = unhexify( src_str, hex_src_string ); |
markrad | 0:cdf462088d13 | 62 | |
markrad | 0:cdf462088d13 | 63 | mbedtls_sha256( src_str, src_len, output, 0 ); |
markrad | 0:cdf462088d13 | 64 | hexify( hash_str, output, 32 ); |
markrad | 0:cdf462088d13 | 65 | |
markrad | 0:cdf462088d13 | 66 | TEST_ASSERT( strcmp( (char *) hash_str, hex_hash_string ) == 0 ); |
markrad | 0:cdf462088d13 | 67 | } |
markrad | 0:cdf462088d13 | 68 | /* END_CASE */ |
markrad | 0:cdf462088d13 | 69 | |
markrad | 0:cdf462088d13 | 70 | /* BEGIN_CASE depends_on:MBEDTLS_SHA512_C */ |
markrad | 0:cdf462088d13 | 71 | void sha384(char *hex_src_string, char *hex_hash_string ) |
markrad | 0:cdf462088d13 | 72 | { |
markrad | 0:cdf462088d13 | 73 | unsigned char src_str[10000]; |
markrad | 0:cdf462088d13 | 74 | unsigned char hash_str[10000]; |
markrad | 0:cdf462088d13 | 75 | unsigned char output[97]; |
markrad | 0:cdf462088d13 | 76 | int src_len; |
markrad | 0:cdf462088d13 | 77 | |
markrad | 0:cdf462088d13 | 78 | memset(src_str, 0x00, 10000); |
markrad | 0:cdf462088d13 | 79 | memset(hash_str, 0x00, 10000); |
markrad | 0:cdf462088d13 | 80 | memset(output, 0x00, 97); |
markrad | 0:cdf462088d13 | 81 | |
markrad | 0:cdf462088d13 | 82 | src_len = unhexify( src_str, hex_src_string ); |
markrad | 0:cdf462088d13 | 83 | |
markrad | 0:cdf462088d13 | 84 | mbedtls_sha512( src_str, src_len, output, 1 ); |
markrad | 0:cdf462088d13 | 85 | hexify( hash_str, output, 48 ); |
markrad | 0:cdf462088d13 | 86 | |
markrad | 0:cdf462088d13 | 87 | TEST_ASSERT( strcmp( (char *) hash_str, hex_hash_string ) == 0 ); |
markrad | 0:cdf462088d13 | 88 | } |
markrad | 0:cdf462088d13 | 89 | /* END_CASE */ |
markrad | 0:cdf462088d13 | 90 | |
markrad | 0:cdf462088d13 | 91 | /* BEGIN_CASE depends_on:MBEDTLS_SHA512_C */ |
markrad | 0:cdf462088d13 | 92 | void mbedtls_sha512(char *hex_src_string, char *hex_hash_string ) |
markrad | 0:cdf462088d13 | 93 | { |
markrad | 0:cdf462088d13 | 94 | unsigned char src_str[10000]; |
markrad | 0:cdf462088d13 | 95 | unsigned char hash_str[10000]; |
markrad | 0:cdf462088d13 | 96 | unsigned char output[129]; |
markrad | 0:cdf462088d13 | 97 | int src_len; |
markrad | 0:cdf462088d13 | 98 | |
markrad | 0:cdf462088d13 | 99 | memset(src_str, 0x00, 10000); |
markrad | 0:cdf462088d13 | 100 | memset(hash_str, 0x00, 10000); |
markrad | 0:cdf462088d13 | 101 | memset(output, 0x00, 129); |
markrad | 0:cdf462088d13 | 102 | |
markrad | 0:cdf462088d13 | 103 | src_len = unhexify( src_str, hex_src_string ); |
markrad | 0:cdf462088d13 | 104 | |
markrad | 0:cdf462088d13 | 105 | mbedtls_sha512( src_str, src_len, output, 0); |
markrad | 0:cdf462088d13 | 106 | hexify( hash_str, output, 64 ); |
markrad | 0:cdf462088d13 | 107 | |
markrad | 0:cdf462088d13 | 108 | TEST_ASSERT( strcmp( (char *) hash_str, hex_hash_string ) == 0 ); |
markrad | 0:cdf462088d13 | 109 | } |
markrad | 0:cdf462088d13 | 110 | /* END_CASE */ |
markrad | 0:cdf462088d13 | 111 | |
markrad | 0:cdf462088d13 | 112 | /* BEGIN_CASE depends_on:MBEDTLS_SHA1_C:MBEDTLS_SELF_TEST */ |
markrad | 0:cdf462088d13 | 113 | void sha1_selftest() |
markrad | 0:cdf462088d13 | 114 | { |
markrad | 0:cdf462088d13 | 115 | TEST_ASSERT( mbedtls_sha1_self_test( 1 ) == 0 ); |
markrad | 0:cdf462088d13 | 116 | } |
markrad | 0:cdf462088d13 | 117 | /* END_CASE */ |
markrad | 0:cdf462088d13 | 118 | |
markrad | 0:cdf462088d13 | 119 | /* BEGIN_CASE depends_on:MBEDTLS_SHA256_C:MBEDTLS_SELF_TEST */ |
markrad | 0:cdf462088d13 | 120 | void sha256_selftest() |
markrad | 0:cdf462088d13 | 121 | { |
markrad | 0:cdf462088d13 | 122 | TEST_ASSERT( mbedtls_sha256_self_test( 1 ) == 0 ); |
markrad | 0:cdf462088d13 | 123 | } |
markrad | 0:cdf462088d13 | 124 | /* END_CASE */ |
markrad | 0:cdf462088d13 | 125 | |
markrad | 0:cdf462088d13 | 126 | /* BEGIN_CASE depends_on:MBEDTLS_SHA512_C:MBEDTLS_SELF_TEST */ |
markrad | 0:cdf462088d13 | 127 | void sha512_selftest() |
markrad | 0:cdf462088d13 | 128 | { |
markrad | 0:cdf462088d13 | 129 | TEST_ASSERT( mbedtls_sha512_self_test( 1 ) == 0 ); |
markrad | 0:cdf462088d13 | 130 | } |
markrad | 0:cdf462088d13 | 131 | /* END_CASE */ |