Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Bug 1604596 - Update Wycheproof vectors and add support for CBC, P256…
…-ECDH, and CMAC tests r=franziskus

This patch updates to the latest Wycheproof vectors and adds Wycheproof support for CBC, CMAC, and P256-ECDH:

ChaCha20: +141 tests
Curve25519: +431 tests
GCM: +39 tests
CBC (new): +183 tests
CMAC (new): +308 tests
P256 ECDH (new): +460 tests

Differential Revision: https://phabricator.services.mozilla.com/D57477

--HG--
extra : moz-landing-system : lando
  • Loading branch information
Kevin Jacobs committed Jan 16, 2020
1 parent 80595a9 commit fdde600
Show file tree
Hide file tree
Showing 27 changed files with 50,396 additions and 4,965 deletions.
818 changes: 818 additions & 0 deletions gtests/common/testvectors/cbc-vectors.h

Large diffs are not rendered by default.

6,768 changes: 5,049 additions & 1,719 deletions gtests/common/testvectors/chachapoly-vectors.h

Large diffs are not rendered by default.

1,217 changes: 1,217 additions & 0 deletions gtests/common/testvectors/cmac-vectors.h

Large diffs are not rendered by default.

11,642 changes: 10,621 additions & 1,021 deletions gtests/common/testvectors/curve25519-vectors.h

Large diffs are not rendered by default.

831 changes: 588 additions & 243 deletions gtests/common/testvectors/gcm-vectors.h

Large diffs are not rendered by default.

13,487 changes: 13,487 additions & 0 deletions gtests/common/testvectors/p256ecdh-vectors.h

Large diffs are not rendered by default.

30 changes: 1 addition & 29 deletions gtests/common/testvectors_base/chachapoly-vectors_base.h
@@ -1,34 +1,8 @@
/* vim: set ts=2 et sw=2 tw=80: */
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this file,
* You can obtain one at http://mozilla.org/MPL/2.0/. */

/* This file is generated from sources in nss/gtests/common/wycheproof
* automatically and should not be touched manually.
* Generation is trigged by calling ./mach wycheproof */

#ifndef chachapoly_vectors_h__
#define chachapoly_vectors_h__

#include <string>
#include <vector>

typedef struct chaChaTestVectorStr {
uint32_t id;
std::vector<uint8_t> Data;
std::vector<uint8_t> AAD;
std::vector<uint8_t> Key;
std::vector<uint8_t> IV;
std::vector<uint8_t> CT;
bool invalidTag;
bool invalidIV;
} chaChaTestVector;

// ChaCha20/Poly1305 Test Vector 1, RFC 7539
// <http://tools.ietf.org/html/rfc7539#section-2.8.2>
// ChaCha20/Poly1305 Test Vector 2, RFC 7539
// <http://tools.ietf.org/html/rfc7539#appendix-A.5>
const chaChaTestVector kChaCha20Vectors[] = {
const ChaChaTestVector kChaCha20Vectors[] = {
{0,
{0x4c, 0x61, 0x64, 0x69, 0x65, 0x73, 0x20, 0x61, 0x6e, 0x64, 0x20, 0x47,
0x65, 0x6e, 0x74, 0x6c, 0x65, 0x6d, 0x65, 0x6e, 0x20, 0x6f, 0x66, 0x20,
Expand Down Expand Up @@ -113,5 +87,3 @@ const chaChaTestVector kChaCha20Vectors[] = {
0xfe, 0xa1, 0x85, 0x1f, 0x38},
false,
false}};

#endif // chachapoly_vectors_h__
34 changes: 10 additions & 24 deletions gtests/common/testvectors_base/curve25519-vectors_base.h
@@ -1,23 +1,6 @@
/* vim: set ts=2 et sw=2 tw=80: */
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this file,
* You can obtain one at http://mozilla.org/MPL/2.0/. */

#ifndef curve25519_vectors_h__
#define curve25519_vectors_h__

#include <string>
#include <vector>

typedef struct curve25519_testvector_str {
std::vector<uint8_t> private_key;
std::vector<uint8_t> public_key;
std::vector<uint8_t> secret;
bool valid;
} curve25519_testvector;

const curve25519_testvector kCurve25519Vectors[] = {
{{0x30, 0x67, 0x02, 0x01, 0x00, 0x30, 0x14, 0x06, 0x07, 0x2a, 0x86, 0x48,
const EcdhTestVectorStr kCurve25519Vectors[] = {
{0,
{0x30, 0x67, 0x02, 0x01, 0x00, 0x30, 0x14, 0x06, 0x07, 0x2a, 0x86, 0x48,
0xce, 0x3d, 0x02, 0x01, 0x06, 0x09, 0x2b, 0x06, 0x01, 0x04, 0x01, 0xda,
0x47, 0x0f, 0x01, 0x04, 0x4c, 0x30, 0x4a, 0x02, 0x01, 0x01, 0x04, 0x20,
0x77, 0x07, 0x6d, 0x0a, 0x73, 0x18, 0xa5, 0x7d, 0x3c, 0x16, 0xc1, 0x72,
Expand All @@ -34,10 +17,12 @@ const curve25519_testvector kCurve25519Vectors[] = {
{0x4a, 0x5d, 0x9d, 0x5b, 0xa4, 0xce, 0x2d, 0xe1, 0x72, 0x8e, 0x3b,
0xf4, 0x80, 0x35, 0x0f, 0x25, 0xe0, 0x7e, 0x21, 0xc9, 0x47, 0xd1,
0x9e, 0x33, 0x76, 0xf0, 0x9b, 0x3c, 0x1e, 0x16, 0x17, 0x42},
false,
true},

// A public key that's too short (31 bytes).
{{0x30, 0x67, 0x02, 0x01, 0x00, 0x30, 0x14, 0x06, 0x07, 0x2a, 0x86, 0x48,
{1,
{0x30, 0x67, 0x02, 0x01, 0x00, 0x30, 0x14, 0x06, 0x07, 0x2a, 0x86, 0x48,
0xce, 0x3d, 0x02, 0x01, 0x06, 0x09, 0x2b, 0x06, 0x01, 0x04, 0x01, 0xda,
0x47, 0x0f, 0x01, 0x04, 0x4c, 0x30, 0x4a, 0x02, 0x01, 0x01, 0x04, 0x20,
0x77, 0x07, 0x6d, 0x0a, 0x73, 0x18, 0xa5, 0x7d, 0x3c, 0x16, 0xc1, 0x72,
Expand All @@ -52,10 +37,12 @@ const curve25519_testvector kCurve25519Vectors[] = {
0x61, 0xc2, 0xec, 0xe4, 0x35, 0x37, 0x3f, 0x83, 0x43, 0xc8, 0x5b, 0x78,
0x67, 0x4d, 0xad, 0xfc, 0x7e, 0x14, 0x6f, 0x88, 0x2b, 0x4f},
{},
false,
false},

// A public key that's too long (33 bytes).
{{0x30, 0x67, 0x02, 0x01, 0x00, 0x30, 0x14, 0x06, 0x07, 0x2a, 0x86, 0x48,
{2,
{0x30, 0x67, 0x02, 0x01, 0x00, 0x30, 0x14, 0x06, 0x07, 0x2a, 0x86, 0x48,
0xce, 0x3d, 0x02, 0x01, 0x06, 0x09, 0x2b, 0x06, 0x01, 0x04, 0x01, 0xda,
0x47, 0x0f, 0x01, 0x04, 0x4c, 0x30, 0x4a, 0x02, 0x01, 0x01, 0x04, 0x20,
0x77, 0x07, 0x6d, 0x0a, 0x73, 0x18, 0xa5, 0x7d, 0x3c, 0x16, 0xc1, 0x72,
Expand All @@ -70,6 +57,5 @@ const curve25519_testvector kCurve25519Vectors[] = {
0x5b, 0x61, 0xc2, 0xec, 0xe4, 0x35, 0x37, 0x3f, 0x83, 0x43, 0xc8, 0x5b,
0x78, 0x67, 0x4d, 0xad, 0xfc, 0x7e, 0x14, 0x6f, 0x88, 0x2b, 0x4f, 0x34},
{},
false,
false}};

#endif // curve25519_vectors_h__
31 changes: 1 addition & 30 deletions gtests/common/testvectors_base/gcm-vectors_base.h
@@ -1,34 +1,7 @@
/* vim: set ts=2 et sw=2 tw=80: */
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this file,
* You can obtain one at http://mozilla.org/MPL/2.0/. */

/* This file is generated from sources in nss/gtests/common/wycheproof
* automatically and should not be touched manually.
* Generation is trigged by calling ./mach wycheproof */

#ifndef gcm_vectors_h__
#define gcm_vectors_h__

#include <string>

typedef struct gcm_kat_str {
uint32_t test_id;
std::string key;
std::string plaintext;
std::string additional_data;
std::string iv;
std::string hash_key;
std::string ghash;
std::string result;
bool invalid_ct;
bool invalid_iv;
} gcm_kat_value;

/*
* http://csrc.nist.gov/groups/ST/toolkit/BCM/documents/proposedmodes/gcm/gcm-revised-spec.pdf
*/
const gcm_kat_value kGcmKatValues[] = {
const AesGcmKatValue kGcmKatValues[] = {
{1, "00000000000000000000000000000000", "", "", "000000000000000000000000",
"66e94bd4ef8a2c3b884cfa59ca342b2e", "00000000000000000000000000000000",
"58e2fccefa7e3061367f1d57a4e7455a", false, false},
Expand Down Expand Up @@ -193,5 +166,3 @@ const gcm_kat_value kGcmKatValues[] = {
"3561e34e52d8b598f9937982512fff27",
"0000000000000000ffcef9ebbffdbd8b00000000000000000000000000000000", false,
false}};

#endif // gcm_vectors_h__
67 changes: 67 additions & 0 deletions gtests/common/testvectors_base/test-structs.h
@@ -0,0 +1,67 @@
/* vim: set ts=2 et sw=2 tw=80: */
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this file,
* You can obtain one at http://mozilla.org/MPL/2.0/. */

/* This file is generated from sources in nss/gtests/common/wycheproof
* automatically and should not be touched manually.
* Generation is trigged by calling ./mach wycheproof */

#ifndef test_structs_h__
#define test_structs_h__

#include <string>
#include <vector>

typedef struct AesCbcTestVectorStr {
uint32_t id;
std::string key;
std::string msg;
std::string iv;
std::string ciphertext;
bool valid;
} AesCbcTestVector;

typedef struct AesCmacTestVectorStr {
uint32_t id;
std::string comment;
std::string key;
std::string msg;
std::string tag;
bool invalid;
} AesCmacTestVector;

typedef struct AesGcmKatValueStr {
uint32_t id;
std::string key;
std::string plaintext;
std::string additional_data;
std::string iv;
std::string hash_key;
std::string ghash;
std::string result;
bool invalid_ct;
bool invalid_iv;
} AesGcmKatValue;

typedef struct ChaChaTestVectorStr {
uint32_t id;
std::vector<uint8_t> plaintext;
std::vector<uint8_t> aad;
std::vector<uint8_t> key;
std::vector<uint8_t> iv;
std::vector<uint8_t> ciphertext;
bool invalid_tag;
bool invalid_iv;
} ChaChaTestVector;

typedef struct EcdhTestVectorStr {
uint32_t id;
std::vector<uint8_t> private_key;
std::vector<uint8_t> public_key;
std::vector<uint8_t> secret;
bool invalid_asn;
bool valid;
} EcdhTestVector;

#endif // test_structs_h__

0 comments on commit fdde600

Please sign in to comment.