diff options
author | Damjan Marion <damarion@cisco.com> | 2019-03-18 18:59:25 +0100 |
---|---|---|
committer | Neale Ranns <nranns@cisco.com> | 2019-03-19 16:29:43 +0000 |
commit | 91f17dc7c4e79343b8fba924e7cea6380a0e6653 (patch) | |
tree | a5c47649bcf8d6668dc509bbc6f7b67e45714784 /src/plugins/unittest/crypto/rfc4231.c | |
parent | 5daf0c55c094167ad590f683451239fa3e25c7fc (diff) |
crypto: introduce crypto infra
Change-Id: Ibf320b3e7b054b686f3af9a55afd5d5bda9b1048
Signed-off-by: Damjan Marion <damarion@cisco.com>
Signed-off-by: Filip Tehlar <ftehlar@cisco.com>
Diffstat (limited to 'src/plugins/unittest/crypto/rfc4231.c')
-rw-r--r-- | src/plugins/unittest/crypto/rfc4231.c | 197 |
1 files changed, 197 insertions, 0 deletions
diff --git a/src/plugins/unittest/crypto/rfc4231.c b/src/plugins/unittest/crypto/rfc4231.c new file mode 100644 index 00000000000..88a3debbe1e --- /dev/null +++ b/src/plugins/unittest/crypto/rfc4231.c @@ -0,0 +1,197 @@ +/* + * Copyright (c) 2019 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. + */ + +/* Test vectors published in RFC2202 */ + +#include <vppinfra/clib.h> +#include <vnet/crypto/crypto.h> +#include <unittest/crypto/crypto.h> + +static u8 tc1_key[] = { + 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, + 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, + 0x0b, 0x0b, 0x0b, 0x0b +}; + +static char tc1_data[8] = "Hi There"; + +static u8 tc1_digest_sha224[] = { + 0x89, 0x6f, 0xb1, 0x12, 0x8a, 0xbb, 0xdf, 0x19, + 0x68, 0x32, 0x10, 0x7c, 0xd4, 0x9d, 0xf3, 0x3f, + 0x47, 0xb4, 0xb1, 0x16, 0x99, 0x12, 0xba, 0x4f, + 0x53, 0x68, 0x4b, 0x22 +}; + +static u8 tc1_digest_sha256[] = { + 0xb0, 0x34, 0x4c, 0x61, 0xd8, 0xdb, 0x38, 0x53, + 0x5c, 0xa8, 0xaf, 0xce, 0xaf, 0x0b, 0xf1, 0x2b, + 0x88, 0x1d, 0xc2, 0x00, 0xc9, 0x83, 0x3d, 0xa7, + 0x26, 0xe9, 0x37, 0x6c, 0x2e, 0x32, 0xcf, 0xf7, +}; + +static u8 tc1_digest_sha384[] = { + 0xaf, 0xd0, 0x39, 0x44, 0xd8, 0x48, 0x95, 0x62, + 0x6b, 0x08, 0x25, 0xf4, 0xab, 0x46, 0x90, 0x7f, + 0x15, 0xf9, 0xda, 0xdb, 0xe4, 0x10, 0x1e, 0xc6, + 0x82, 0xaa, 0x03, 0x4c, 0x7c, 0xeb, 0xc5, 0x9c, + 0xfa, 0xea, 0x9e, 0xa9, 0x07, 0x6e, 0xde, 0x7f, + 0x4a, 0xf1, 0x52, 0xe8, 0xb2, 0xfa, 0x9c, 0xb6 +}; + +static u8 tc1_digest_sha512[] = { + 0x87, 0xaa, 0x7c, 0xde, 0xa5, 0xef, 0x61, 0x9d, + 0x4f, 0xf0, 0xb4, 0x24, 0x1a, 0x1d, 0x6c, 0xb0, + 0x23, 0x79, 0xf4, 0xe2, 0xce, 0x4e, 0xc2, 0x78, + 0x7a, 0xd0, 0xb3, 0x05, 0x45, 0xe1, 0x7c, 0xde, + 0xda, 0xa8, 0x33, 0xb7, 0xd6, 0xb8, 0xa7, 0x02, + 0x03, 0x8b, 0x27, 0x4e, 0xae, 0xa3, 0xf4, 0xe4, + 0xbe, 0x9d, 0x91, 0x4e, 0xeb, 0x61, 0xf1, 0x70, + 0x2e, 0x69, 0x6c, 0x20, 0x3a, 0x12, 0x68, 0x54 +}; + +/* *INDENT-OFF* */ +UNITTEST_REGISTER_CRYPTO_TEST (rfc4231_tc1_sha224) = { + .name = "RFC4231 TC1", + .op = VNET_CRYPTO_OP_SHA224_HMAC, + .key = TEST_DATA (tc1_key), + .data = TEST_DATA (tc1_data), + .expected = TEST_DATA (tc1_digest_sha224), +}; + +UNITTEST_REGISTER_CRYPTO_TEST (rfc4231_tc1_sha256) = { + .name = "RFC4231 TC1", + .op = VNET_CRYPTO_OP_SHA256_HMAC, + .key = TEST_DATA (tc1_key), + .data = TEST_DATA (tc1_data), + .expected = TEST_DATA (tc1_digest_sha256), +}; + +UNITTEST_REGISTER_CRYPTO_TEST (rfc4231_tc1_sha384) = { + .name = "RFC4231 TC1", + .op = VNET_CRYPTO_OP_SHA384_HMAC, + .key = TEST_DATA (tc1_key), + .data = TEST_DATA (tc1_data), + .expected = TEST_DATA (tc1_digest_sha384), +}; + +UNITTEST_REGISTER_CRYPTO_TEST (rfc4231_tc1_sha512) = { + .name = "RFC4231 TC1", + .op = VNET_CRYPTO_OP_SHA512_HMAC, + .key = TEST_DATA (tc1_key), + .data = TEST_DATA (tc1_data), + .expected = TEST_DATA (tc1_digest_sha512), +}; +/* *INDENT-ON* */ + +static u8 tc7_key[131] = { + 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, + 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, + 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, + 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, + 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, + 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, + 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, + 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, + 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, + 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, + 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, + 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, + 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, + 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, + 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, + 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, + 0xaa, 0xaa, 0xaa +}; + +static char tc7_data[152] = + "This is a test using a larger than block-size key and a larger than " + "block-size data. The key needs to be hashed before being used by the " + "HMAC algorithm."; + +static u8 tc7_digest_sha224[] = { + 0x3a, 0x85, 0x41, 0x66, 0xac, 0x5d, 0x9f, 0x02, + 0x3f, 0x54, 0xd5, 0x17, 0xd0, 0xb3, 0x9d, 0xbd, + 0x94, 0x67, 0x70, 0xdb, 0x9c, 0x2b, 0x95, 0xc9, + 0xf6, 0xf5, 0x65, 0xd1 +}; + +static u8 tc7_digest_sha256[] = { + 0x9b, 0x09, 0xff, 0xa7, 0x1b, 0x94, 0x2f, 0xcb, + 0x27, 0x63, 0x5f, 0xbc, 0xd5, 0xb0, 0xe9, 0x44, + 0xbf, 0xdc, 0x63, 0x64, 0x4f, 0x07, 0x13, 0x93, + 0x8a, 0x7f, 0x51, 0x53, 0x5c, 0x3a, 0x35, 0xe2 +}; + +static u8 tc7_digest_sha384[] = { + 0x66, 0x17, 0x17, 0x8e, 0x94, 0x1f, 0x02, 0x0d, + 0x35, 0x1e, 0x2f, 0x25, 0x4e, 0x8f, 0xd3, 0x2c, + 0x60, 0x24, 0x20, 0xfe, 0xb0, 0xb8, 0xfb, 0x9a, + 0xdc, 0xce, 0xbb, 0x82, 0x46, 0x1e, 0x99, 0xc5, + 0xa6, 0x78, 0xcc, 0x31, 0xe7, 0x99, 0x17, 0x6d, + 0x38, 0x60, 0xe6, 0x11, 0x0c, 0x46, 0x52, 0x3e +}; + +static u8 tc7_digest_sha512[] = { + 0xe3, 0x7b, 0x6a, 0x77, 0x5d, 0xc8, 0x7d, 0xba, + 0xa4, 0xdf, 0xa9, 0xf9, 0x6e, 0x5e, 0x3f, 0xfd, + 0xde, 0xbd, 0x71, 0xf8, 0x86, 0x72, 0x89, 0x86, + 0x5d, 0xf5, 0xa3, 0x2d, 0x20, 0xcd, 0xc9, 0x44, + 0xb6, 0x02, 0x2c, 0xac, 0x3c, 0x49, 0x82, 0xb1, + 0x0d, 0x5e, 0xeb, 0x55, 0xc3, 0xe4, 0xde, 0x15, + 0x13, 0x46, 0x76, 0xfb, 0x6d, 0xe0, 0x44, 0x60, + 0x65, 0xc9, 0x74, 0x40, 0xfa, 0x8c, 0x6a, 0x58 +}; + +/* *INDENT-OFF* */ +UNITTEST_REGISTER_CRYPTO_TEST (rfc4231_tc7_sha224) = { + .name = "RFC4231 TC7", + .op = VNET_CRYPTO_OP_SHA224_HMAC, + .key = TEST_DATA (tc7_key), + .data = TEST_DATA (tc7_data), + .expected = TEST_DATA (tc7_digest_sha224), +}; + +UNITTEST_REGISTER_CRYPTO_TEST (rfc4231_tc7_sha256) = { + .name = "RFC4231 TC7", + .op = VNET_CRYPTO_OP_SHA256_HMAC, + .key = TEST_DATA (tc7_key), + .data = TEST_DATA (tc7_data), + .expected = TEST_DATA (tc7_digest_sha256), +}; + +UNITTEST_REGISTER_CRYPTO_TEST (rfc4231_tc7_sha384) = { + .name = "RFC4231 TC7", + .op = VNET_CRYPTO_OP_SHA384_HMAC, + .key = TEST_DATA (tc7_key), + .data = TEST_DATA (tc7_data), + .expected = TEST_DATA (tc7_digest_sha384), +}; + +UNITTEST_REGISTER_CRYPTO_TEST (rfc4231_tc7_sha512) = { + .name = "RFC4231 TC7", + .op = VNET_CRYPTO_OP_SHA512_HMAC, + .key = TEST_DATA (tc7_key), + .data = TEST_DATA (tc7_data), + .expected = TEST_DATA (tc7_digest_sha512), +}; +/* *INDENT-ON* */ + +/* + * fd.io coding-style-patch-verification: ON + * + * Local Variables: + * eval: (c-set-style "gnu") + * End: + */ |