diff options
Diffstat (limited to 'src/plugins/unittest')
-rw-r--r-- | src/plugins/unittest/CMakeLists.txt | 1 | ||||
-rw-r--r-- | src/plugins/unittest/crypto/sha.c | 92 | ||||
-rw-r--r-- | src/plugins/unittest/crypto_test.c | 13 |
3 files changed, 106 insertions, 0 deletions
diff --git a/src/plugins/unittest/CMakeLists.txt b/src/plugins/unittest/CMakeLists.txt index b6322cddf09..6276a92d749 100644 --- a/src/plugins/unittest/CMakeLists.txt +++ b/src/plugins/unittest/CMakeLists.txt @@ -29,6 +29,7 @@ add_vpp_plugin(unittest crypto/rfc2202_hmac_md5.c crypto/rfc2202_hmac_sha1.c crypto/rfc4231.c + crypto/sha.c crypto_test.c fib_test.c interface_test.c diff --git a/src/plugins/unittest/crypto/sha.c b/src/plugins/unittest/crypto/sha.c new file mode 100644 index 00000000000..384e359980d --- /dev/null +++ b/src/plugins/unittest/crypto/sha.c @@ -0,0 +1,92 @@ +/* + * Copyright (c) 2021 Cisco and/or its affiliates. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at: + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include <vnet/crypto/crypto.h> +#include <unittest/crypto/crypto.h> + +static char sha_data[3] = "abc"; + +static u8 sha1_tc1_digest[20] = { 0xa9, 0x99, 0x3e, 0x36, 0x47, 0x06, 0x81, + 0x6a, 0xba, 0x3e, 0x25, 0x71, 0x78, 0x50, + 0xc2, 0x6c, 0x9c, 0xd0, 0xd8, 0x9d }; + +static u8 sha224_digest[] = { + 0x23, 0x09, 0x7D, 0x22, 0x34, 0x05, 0xD8, 0x22, 0x86, 0x42, + 0xA4, 0x77, 0xBD, 0xA2, 0x55, 0xB3, 0x2A, 0xAD, 0xBC, 0xE4, + 0xBD, 0xA0, 0xB3, 0xF7, 0xE3, 0x6C, 0x9D, 0xA7, +}; + +static u8 sha256_digest[] = { 0xBA, 0x78, 0x16, 0xBF, 0x8F, 0x01, 0xCF, 0xEA, + 0x41, 0x41, 0x40, 0xDE, 0x5D, 0xAE, 0x22, 0x23, + 0xB0, 0x03, 0x61, 0xA3, 0x96, 0x17, 0x7A, 0x9C, + 0xB4, 0x10, 0xFF, 0x61, 0xF2, 0x00, 0x15, 0xAD }; + +static u8 sha384_digest[] = { 0xCB, 0x00, 0x75, 0x3F, 0x45, 0xA3, 0x5E, 0x8B, + 0xB5, 0xA0, 0x3D, 0x69, 0x9A, 0xC6, 0x50, 0x07, + 0x27, 0x2C, 0x32, 0xAB, 0x0E, 0xDE, 0xD1, 0x63, + 0x1A, 0x8B, 0x60, 0x5A, 0x43, 0xFF, 0x5B, 0xED, + 0x80, 0x86, 0x07, 0x2B, 0xA1, 0xE7, 0xCC, 0x23, + 0x58, 0xBA, 0xEC, 0xA1, 0x34, 0xC8, 0x25, 0xA7 }; + +static u8 sha512_digest[] = { + 0xDD, 0xAF, 0x35, 0xA1, 0x93, 0x61, 0x7A, 0xBA, 0xCC, 0x41, 0x73, 0x49, 0xAE, + 0x20, 0x41, 0x31, 0x12, 0xE6, 0xFA, 0x4E, 0x89, 0xA9, 0x7E, 0xA2, 0x0A, 0x9E, + 0xEE, 0xE6, 0x4B, 0x55, 0xD3, 0x9A, 0x21, 0x92, 0x99, 0x2A, 0x27, 0x4F, 0xC1, + 0xA8, 0x36, 0xBA, 0x3C, 0x23, 0xA3, 0xFE, 0xEB, 0xBD, 0x45, 0x4D, 0x44, 0x23, + 0x64, 0x3C, 0xE8, 0x0E, 0x2A, 0x9A, 0xC9, 0x4F, 0xA5, 0x4C, 0xA4, 0x9F +}; + +UNITTEST_REGISTER_CRYPTO_TEST (nist_sha1_tc1) = { + .name = "NIST SHA-1 TC1", + .alg = VNET_CRYPTO_ALG_HASH_SHA1, + .plaintext = TEST_DATA (sha_data), + .digest = TEST_DATA (sha1_tc1_digest), +}; + +UNITTEST_REGISTER_CRYPTO_TEST (nist_sha224_tc1) = { + .name = "NIST SHA-224 TC1", + .alg = VNET_CRYPTO_ALG_HASH_SHA224, + .plaintext = TEST_DATA (sha_data), + .digest = TEST_DATA (sha224_digest), +}; + +UNITTEST_REGISTER_CRYPTO_TEST (nist_sha256_tc1) = { + .name = "NIST SHA-256 TC1", + .alg = VNET_CRYPTO_ALG_HASH_SHA256, + .plaintext = TEST_DATA (sha_data), + .digest = TEST_DATA (sha256_digest), +}; + +UNITTEST_REGISTER_CRYPTO_TEST (nist_sha384_tc1) = { + .name = "NIST SHA-384 TC1", + .alg = VNET_CRYPTO_ALG_HASH_SHA384, + .plaintext = TEST_DATA (sha_data), + .digest = TEST_DATA (sha384_digest), +}; + +UNITTEST_REGISTER_CRYPTO_TEST (nist_sha512_tc1) = { + .name = "NIST SHA-512 TC1", + .alg = VNET_CRYPTO_ALG_HASH_SHA512, + .plaintext = TEST_DATA (sha_data), + .digest = TEST_DATA (sha512_digest), +}; + +/* + * fd.io coding-style-patch-verification: ON + * + * Local Variables: + * eval: (c-set-style "gnu") + * End: + */ diff --git a/src/plugins/unittest/crypto_test.c b/src/plugins/unittest/crypto_test.c index f08b253dd19..ed21e86b8d7 100644 --- a/src/plugins/unittest/crypto_test.c +++ b/src/plugins/unittest/crypto_test.c @@ -75,6 +75,9 @@ print_results (vlib_main_t * vm, unittest_crypto_test_registration_t ** rv, case VNET_CRYPTO_OP_TYPE_HMAC: exp_digest = &r->digest; break; + case VNET_CRYPTO_OP_TYPE_HASH: + exp_digest = &r->digest; + break; default: ASSERT (0); } @@ -629,6 +632,12 @@ test_crypto_static (vlib_main_t * vm, crypto_test_main_t * tm, op->len = r->plaintext.length; } break; + case VNET_CRYPTO_OP_TYPE_HASH: + op->digest = computed_data + computed_data_total_len; + computed_data_total_len += r->digest.length; + op->src = r->plaintext.data; + op->len = r->plaintext.length; + break; default: break; }; @@ -802,6 +811,10 @@ test_crypto (vlib_main_t * vm, crypto_test_main_t * tm) n_ops_static += 1; } break; + case VNET_CRYPTO_OP_TYPE_HASH: + computed_data_total_len += r->digest.length; + n_ops_static += 1; + break; default: break; }; |