FD.io VPP  v21.10.1-2-g0a485f517
Vector Packet Processing
sha.c
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2021 Cisco and/or its affiliates.
3  * Licensed under the Apache License, Version 2.0 (the "License");
4  * you may not use this file except in compliance with the License.
5  * You may obtain a copy of the License at:
6  *
7  * http://www.apache.org/licenses/LICENSE-2.0
8  *
9  * Unless required by applicable law or agreed to in writing, software
10  * distributed under the License is distributed on an "AS IS" BASIS,
11  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12  * See the License for the specific language governing permissions and
13  * limitations under the License.
14  */
15 
16 #include <vnet/crypto/crypto.h>
17 #include <unittest/crypto/crypto.h>
18 
19 static char sha_data[3] = "abc";
20 
21 static u8 sha1_tc1_digest[20] = { 0xa9, 0x99, 0x3e, 0x36, 0x47, 0x06, 0x81,
22  0x6a, 0xba, 0x3e, 0x25, 0x71, 0x78, 0x50,
23  0xc2, 0x6c, 0x9c, 0xd0, 0xd8, 0x9d };
24 
25 static u8 sha224_digest[] = {
26  0x23, 0x09, 0x7D, 0x22, 0x34, 0x05, 0xD8, 0x22, 0x86, 0x42,
27  0xA4, 0x77, 0xBD, 0xA2, 0x55, 0xB3, 0x2A, 0xAD, 0xBC, 0xE4,
28  0xBD, 0xA0, 0xB3, 0xF7, 0xE3, 0x6C, 0x9D, 0xA7,
29 };
30 
31 static u8 sha256_digest[] = { 0xBA, 0x78, 0x16, 0xBF, 0x8F, 0x01, 0xCF, 0xEA,
32  0x41, 0x41, 0x40, 0xDE, 0x5D, 0xAE, 0x22, 0x23,
33  0xB0, 0x03, 0x61, 0xA3, 0x96, 0x17, 0x7A, 0x9C,
34  0xB4, 0x10, 0xFF, 0x61, 0xF2, 0x00, 0x15, 0xAD };
35 
36 static u8 sha384_digest[] = { 0xCB, 0x00, 0x75, 0x3F, 0x45, 0xA3, 0x5E, 0x8B,
37  0xB5, 0xA0, 0x3D, 0x69, 0x9A, 0xC6, 0x50, 0x07,
38  0x27, 0x2C, 0x32, 0xAB, 0x0E, 0xDE, 0xD1, 0x63,
39  0x1A, 0x8B, 0x60, 0x5A, 0x43, 0xFF, 0x5B, 0xED,
40  0x80, 0x86, 0x07, 0x2B, 0xA1, 0xE7, 0xCC, 0x23,
41  0x58, 0xBA, 0xEC, 0xA1, 0x34, 0xC8, 0x25, 0xA7 };
42 
43 static u8 sha512_digest[] = {
44  0xDD, 0xAF, 0x35, 0xA1, 0x93, 0x61, 0x7A, 0xBA, 0xCC, 0x41, 0x73, 0x49, 0xAE,
45  0x20, 0x41, 0x31, 0x12, 0xE6, 0xFA, 0x4E, 0x89, 0xA9, 0x7E, 0xA2, 0x0A, 0x9E,
46  0xEE, 0xE6, 0x4B, 0x55, 0xD3, 0x9A, 0x21, 0x92, 0x99, 0x2A, 0x27, 0x4F, 0xC1,
47  0xA8, 0x36, 0xBA, 0x3C, 0x23, 0xA3, 0xFE, 0xEB, 0xBD, 0x45, 0x4D, 0x44, 0x23,
48  0x64, 0x3C, 0xE8, 0x0E, 0x2A, 0x9A, 0xC9, 0x4F, 0xA5, 0x4C, 0xA4, 0x9F
49 };
50 
51 UNITTEST_REGISTER_CRYPTO_TEST (nist_sha1_tc1) = {
52  .name = "NIST SHA-1 TC1",
53  .alg = VNET_CRYPTO_ALG_HASH_SHA1,
54  .plaintext = TEST_DATA (sha_data),
55  .digest = TEST_DATA (sha1_tc1_digest),
56 };
57 
58 UNITTEST_REGISTER_CRYPTO_TEST (nist_sha224_tc1) = {
59  .name = "NIST SHA-224 TC1",
60  .alg = VNET_CRYPTO_ALG_HASH_SHA224,
61  .plaintext = TEST_DATA (sha_data),
62  .digest = TEST_DATA (sha224_digest),
63 };
64 
65 UNITTEST_REGISTER_CRYPTO_TEST (nist_sha256_tc1) = {
66  .name = "NIST SHA-256 TC1",
67  .alg = VNET_CRYPTO_ALG_HASH_SHA256,
68  .plaintext = TEST_DATA (sha_data),
69  .digest = TEST_DATA (sha256_digest),
70 };
71 
72 UNITTEST_REGISTER_CRYPTO_TEST (nist_sha384_tc1) = {
73  .name = "NIST SHA-384 TC1",
74  .alg = VNET_CRYPTO_ALG_HASH_SHA384,
75  .plaintext = TEST_DATA (sha_data),
76  .digest = TEST_DATA (sha384_digest),
77 };
78 
79 UNITTEST_REGISTER_CRYPTO_TEST (nist_sha512_tc1) = {
80  .name = "NIST SHA-512 TC1",
81  .alg = VNET_CRYPTO_ALG_HASH_SHA512,
82  .plaintext = TEST_DATA (sha_data),
83  .digest = TEST_DATA (sha512_digest),
84 };
85 
86 /*
87  * fd.io coding-style-patch-verification: ON
88  *
89  * Local Variables:
90  * eval: (c-set-style "gnu")
91  * End:
92  */
crypto.h
sha1_tc1_digest
static u8 sha1_tc1_digest[20]
Definition: sha.c:21
sha256_digest
static u8 sha256_digest[]
Definition: sha.c:31
sha512_digest
static u8 sha512_digest[]
Definition: sha.c:43
sha384_digest
static u8 sha384_digest[]
Definition: sha.c:36
UNITTEST_REGISTER_CRYPTO_TEST
UNITTEST_REGISTER_CRYPTO_TEST(nist_sha1_tc1)
crypto.h
u8
unsigned char u8
Definition: types.h:56
TEST_DATA
#define TEST_DATA(n)
Definition: crypto.h:63
sha224_digest
static u8 sha224_digest[]
Definition: sha.c:25
sha_data
static char sha_data[3]
Definition: sha.c:19