Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/openssl/openssl.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authorMatt Caswell <matt@openssl.org>2020-03-18 01:40:33 +0300
committerShane Lontis <shane.lontis@oracle.com>2020-03-18 01:40:33 +0300
commit244bc29746c83e76e2fba542ca87552b8aef5c5f (patch)
tree5e2391571abf8ea2d69d8f8c14c49ff044f49b7f /test
parentb3e6d666e351d45e93d29fe3813245b92a0f5815 (diff)
Implement serializers for ED25519 and ED448
This is largely based on the existing X25519 and X448 serializers - but a few adjustments were necessary so that we can identify what type of key we are using. Previously we used the keylen for this but X25519 and ED25519 have the same keylen. Reviewed-by: Shane Lontis <shane.lontis@oracle.com> (Merged from https://github.com/openssl/openssl/pull/11272)
Diffstat (limited to 'test')
-rw-r--r--test/evp_pkey_provided_test.c96
-rw-r--r--test/recipes/30-test_evp_pkey_provided/ED25519.priv.derbin0 -> 48 bytes
-rw-r--r--test/recipes/30-test_evp_pkey_provided/ED25519.priv.pem3
-rw-r--r--test/recipes/30-test_evp_pkey_provided/ED25519.priv.txt9
-rw-r--r--test/recipes/30-test_evp_pkey_provided/ED25519.pub.derbin0 -> 44 bytes
-rw-r--r--test/recipes/30-test_evp_pkey_provided/ED25519.pub.pem3
-rw-r--r--test/recipes/30-test_evp_pkey_provided/ED25519.pub.txt5
-rw-r--r--test/recipes/30-test_evp_pkey_provided/ED448.priv.derbin0 -> 73 bytes
-rw-r--r--test/recipes/30-test_evp_pkey_provided/ED448.priv.pem4
-rw-r--r--test/recipes/30-test_evp_pkey_provided/ED448.priv.txt11
-rw-r--r--test/recipes/30-test_evp_pkey_provided/ED448.pub.derbin0 -> 69 bytes
-rw-r--r--test/recipes/30-test_evp_pkey_provided/ED448.pub.pem4
-rw-r--r--test/recipes/30-test_evp_pkey_provided/ED448.pub.txt6
13 files changed, 133 insertions, 8 deletions
diff --git a/test/evp_pkey_provided_test.c b/test/evp_pkey_provided_test.c
index c395f185dd..d0a87b08d3 100644
--- a/test/evp_pkey_provided_test.c
+++ b/test/evp_pkey_provided_test.c
@@ -392,16 +392,18 @@ static int test_fromdata_dh(void)
# define X25519_IDX 0
# define X448_IDX 1
+# define ED25519_IDX 2
+# define ED448_IDX 3
static int test_fromdata_ecx(int tst)
{
int ret = 0;
EVP_PKEY_CTX *ctx = NULL;
EVP_PKEY *pk = NULL;
- const char *alg = (tst == X25519_IDX) ? "X25519" : "X448";
+ const char *alg = NULL;
- /* X448_KEYLEN > X25519_KEYLEN */
- static unsigned char key_numbers[2][2][X448_KEYLEN] = {
+ /* ED448_KEYLEN > X448_KEYLEN > X25519_KEYLEN == ED25519_KEYLEN */
+ static unsigned char key_numbers[4][2][ED448_KEYLEN] = {
/* X25519: Keys from RFC 7748 6.1 */
{
/* Private Key */
@@ -439,6 +441,44 @@ static int test_fromdata_ecx(int tst)
0x0c, 0x5b, 0x12, 0xda, 0x88, 0x12, 0x0d, 0x53, 0x17, 0x7f,
0x80, 0xe5, 0x32, 0xc4, 0x1f, 0xa0
}
+ },
+ /* ED25519: Keys from RFC 8032 */
+ {
+ /* Private Key */
+ {
+ 0x9d, 0x61, 0xb1, 0x9d, 0xef, 0xfd, 0x5a, 0x60, 0xba, 0x84,
+ 0x4a, 0xf4, 0x92, 0xec, 0x2c, 0xc4, 0x44, 0x49, 0xc5, 0x69,
+ 0x7b, 0x32, 0x69, 0x19, 0x70, 0x3b, 0xac, 0x03, 0x1c, 0xae,
+ 0x7f, 0x60
+ },
+ /* Public Key */
+ {
+ 0xd7, 0x5a, 0x98, 0x01, 0x82, 0xb1, 0x0a, 0xb7, 0xd5, 0x4b,
+ 0xfe, 0xd3, 0xc9, 0x64, 0x07, 0x3a, 0x0e, 0xe1, 0x72, 0xf3,
+ 0xda, 0xa6, 0x23, 0x25, 0xaf, 0x02, 0x1a, 0x68, 0xf7, 0x07,
+ 0x51, 0x1a
+ }
+ },
+ /* ED448: Keys from RFC 8032 */
+ {
+ /* Private Key */
+ {
+ 0x6c, 0x82, 0xa5, 0x62, 0xcb, 0x80, 0x8d, 0x10, 0xd6, 0x32,
+ 0xbe, 0x89, 0xc8, 0x51, 0x3e, 0xbf, 0x6c, 0x92, 0x9f, 0x34,
+ 0xdd, 0xfa, 0x8c, 0x9f, 0x63, 0xc9, 0x96, 0x0e, 0xf6, 0xe3,
+ 0x48, 0xa3, 0x52, 0x8c, 0x8a, 0x3f, 0xcc, 0x2f, 0x04, 0x4e,
+ 0x39, 0xa3, 0xfc, 0x5b, 0x94, 0x49, 0x2f, 0x8f, 0x03, 0x2e,
+ 0x75, 0x49, 0xa2, 0x00, 0x98, 0xf9, 0x5b
+ },
+ /* Public Key */
+ {
+ 0x5f, 0xd7, 0x44, 0x9b, 0x59, 0xb4, 0x61, 0xfd, 0x2c, 0xe7,
+ 0x87, 0xec, 0x61, 0x6a, 0xd4, 0x6a, 0x1d, 0xa1, 0x34, 0x24,
+ 0x85, 0xa7, 0x0e, 0x1f, 0x8a, 0x0e, 0xa7, 0x5d, 0x80, 0xe9,
+ 0x67, 0x78, 0xed, 0xf1, 0x24, 0x76, 0x9b, 0x46, 0xc7, 0x06,
+ 0x1b, 0xd6, 0x78, 0x3d, 0xf1, 0xe5, 0x0f, 0x6c, 0xd1, 0xfa,
+ 0x1a, 0xbe, 0xaf, 0xe8, 0x25, 0x61, 0x80
+ }
}
};
OSSL_PARAM x25519_fromdata_params[] = {
@@ -459,19 +499,59 @@ static int test_fromdata_ecx(int tst)
X448_KEYLEN),
OSSL_PARAM_END
};
- OSSL_PARAM *fromdata_params;
- int bits, security_bits, size;
+ OSSL_PARAM ed25519_fromdata_params[] = {
+ OSSL_PARAM_octet_string(OSSL_PKEY_PARAM_PRIV_KEY,
+ key_numbers[ED25519_IDX][PRIV_KEY],
+ ED25519_KEYLEN),
+ OSSL_PARAM_octet_string(OSSL_PKEY_PARAM_PUB_KEY,
+ key_numbers[ED25519_IDX][PUB_KEY],
+ ED25519_KEYLEN),
+ OSSL_PARAM_END
+ };
+ OSSL_PARAM ed448_fromdata_params[] = {
+ OSSL_PARAM_octet_string(OSSL_PKEY_PARAM_PRIV_KEY,
+ key_numbers[ED448_IDX][PRIV_KEY],
+ ED448_KEYLEN),
+ OSSL_PARAM_octet_string(OSSL_PKEY_PARAM_PUB_KEY,
+ key_numbers[ED448_IDX][PUB_KEY],
+ ED448_KEYLEN),
+ OSSL_PARAM_END
+ };
+ OSSL_PARAM *fromdata_params = NULL;
+ int bits = 0, security_bits = 0, size = 0;
- if (tst == X25519_IDX) {
+ switch (tst) {
+ case X25519_IDX:
fromdata_params = x25519_fromdata_params;
bits = X25519_BITS;
security_bits = X25519_SECURITY_BITS;
size = X25519_KEYLEN;
- } else {
+ alg = "X25519";
+ break;
+
+ case X448_IDX:
fromdata_params = x448_fromdata_params;
bits = X448_BITS;
security_bits = X448_SECURITY_BITS;
size = X448_KEYLEN;
+ alg = "X448";
+ break;
+
+ case ED25519_IDX:
+ fromdata_params = ed25519_fromdata_params;
+ bits = ED25519_BITS;
+ security_bits = ED25519_SECURITY_BITS;
+ size = ED25519_KEYLEN;
+ alg = "ED25519";
+ break;
+
+ case ED448_IDX:
+ fromdata_params = ed448_fromdata_params;
+ bits = ED448_BITS;
+ security_bits = ED448_SECURITY_BITS;
+ size = ED448_KEYLEN;
+ alg = "ED448";
+ break;
}
ctx = EVP_PKEY_CTX_new_from_name(NULL, alg, NULL);
@@ -577,7 +657,7 @@ int setup_tests(void)
ADD_TEST(test_fromdata_dh);
#endif
#ifndef OPENSSL_NO_EC
- ADD_ALL_TESTS(test_fromdata_ecx, 2);
+ ADD_ALL_TESTS(test_fromdata_ecx, 4);
ADD_TEST(test_fromdata_ec);
#endif
return 1;
diff --git a/test/recipes/30-test_evp_pkey_provided/ED25519.priv.der b/test/recipes/30-test_evp_pkey_provided/ED25519.priv.der
new file mode 100644
index 0000000000..71783b74d3
--- /dev/null
+++ b/test/recipes/30-test_evp_pkey_provided/ED25519.priv.der
Binary files differ
diff --git a/test/recipes/30-test_evp_pkey_provided/ED25519.priv.pem b/test/recipes/30-test_evp_pkey_provided/ED25519.priv.pem
new file mode 100644
index 0000000000..7cf2b728c9
--- /dev/null
+++ b/test/recipes/30-test_evp_pkey_provided/ED25519.priv.pem
@@ -0,0 +1,3 @@
+-----BEGIN PRIVATE KEY-----
+MC4CAQAwBQYDK2VwBCIEIJ1hsZ3v/VpguoRK9JLsLMREScVpezJpGXA7rAMcrn9g
+-----END PRIVATE KEY-----
diff --git a/test/recipes/30-test_evp_pkey_provided/ED25519.priv.txt b/test/recipes/30-test_evp_pkey_provided/ED25519.priv.txt
new file mode 100644
index 0000000000..43ed486f40
--- /dev/null
+++ b/test/recipes/30-test_evp_pkey_provided/ED25519.priv.txt
@@ -0,0 +1,9 @@
+ED25519 Private-Key:
+priv:
+ 9d:61:b1:9d:ef:fd:5a:60:ba:84:4a:f4:92:ec:2c:
+ c4:44:49:c5:69:7b:32:69:19:70:3b:ac:03:1c:ae:
+ 7f:60
+pub:
+ d7:5a:98:01:82:b1:0a:b7:d5:4b:fe:d3:c9:64:07:
+ 3a:0e:e1:72:f3:da:a6:23:25:af:02:1a:68:f7:07:
+ 51:1a
diff --git a/test/recipes/30-test_evp_pkey_provided/ED25519.pub.der b/test/recipes/30-test_evp_pkey_provided/ED25519.pub.der
new file mode 100644
index 0000000000..5b33e7546d
--- /dev/null
+++ b/test/recipes/30-test_evp_pkey_provided/ED25519.pub.der
Binary files differ
diff --git a/test/recipes/30-test_evp_pkey_provided/ED25519.pub.pem b/test/recipes/30-test_evp_pkey_provided/ED25519.pub.pem
new file mode 100644
index 0000000000..9749b691de
--- /dev/null
+++ b/test/recipes/30-test_evp_pkey_provided/ED25519.pub.pem
@@ -0,0 +1,3 @@
+-----BEGIN PUBLIC KEY-----
+MCowBQYDK2VwAyEA11qYAYKxCrfVS/7TyWQHOg7hcvPapiMlrwIaaPcHURo=
+-----END PUBLIC KEY-----
diff --git a/test/recipes/30-test_evp_pkey_provided/ED25519.pub.txt b/test/recipes/30-test_evp_pkey_provided/ED25519.pub.txt
new file mode 100644
index 0000000000..7456dfc252
--- /dev/null
+++ b/test/recipes/30-test_evp_pkey_provided/ED25519.pub.txt
@@ -0,0 +1,5 @@
+ED25519 Public-Key:
+pub:
+ d7:5a:98:01:82:b1:0a:b7:d5:4b:fe:d3:c9:64:07:
+ 3a:0e:e1:72:f3:da:a6:23:25:af:02:1a:68:f7:07:
+ 51:1a
diff --git a/test/recipes/30-test_evp_pkey_provided/ED448.priv.der b/test/recipes/30-test_evp_pkey_provided/ED448.priv.der
new file mode 100644
index 0000000000..5718a54734
--- /dev/null
+++ b/test/recipes/30-test_evp_pkey_provided/ED448.priv.der
Binary files differ
diff --git a/test/recipes/30-test_evp_pkey_provided/ED448.priv.pem b/test/recipes/30-test_evp_pkey_provided/ED448.priv.pem
new file mode 100644
index 0000000000..98af16420a
--- /dev/null
+++ b/test/recipes/30-test_evp_pkey_provided/ED448.priv.pem
@@ -0,0 +1,4 @@
+-----BEGIN PRIVATE KEY-----
+MEcCAQAwBQYDK2VxBDsEOWyCpWLLgI0Q1jK+ichRPr9skp803fqMn2PJlg7240ij
+UoyKP8wvBE45o/xblEkvjwMudUmiAJj5Ww==
+-----END PRIVATE KEY-----
diff --git a/test/recipes/30-test_evp_pkey_provided/ED448.priv.txt b/test/recipes/30-test_evp_pkey_provided/ED448.priv.txt
new file mode 100644
index 0000000000..071ee6c5f7
--- /dev/null
+++ b/test/recipes/30-test_evp_pkey_provided/ED448.priv.txt
@@ -0,0 +1,11 @@
+ED448 Private-Key:
+priv:
+ 6c:82:a5:62:cb:80:8d:10:d6:32:be:89:c8:51:3e:
+ bf:6c:92:9f:34:dd:fa:8c:9f:63:c9:96:0e:f6:e3:
+ 48:a3:52:8c:8a:3f:cc:2f:04:4e:39:a3:fc:5b:94:
+ 49:2f:8f:03:2e:75:49:a2:00:98:f9:5b
+pub:
+ 5f:d7:44:9b:59:b4:61:fd:2c:e7:87:ec:61:6a:d4:
+ 6a:1d:a1:34:24:85:a7:0e:1f:8a:0e:a7:5d:80:e9:
+ 67:78:ed:f1:24:76:9b:46:c7:06:1b:d6:78:3d:f1:
+ e5:0f:6c:d1:fa:1a:be:af:e8:25:61:80
diff --git a/test/recipes/30-test_evp_pkey_provided/ED448.pub.der b/test/recipes/30-test_evp_pkey_provided/ED448.pub.der
new file mode 100644
index 0000000000..bd2a95530b
--- /dev/null
+++ b/test/recipes/30-test_evp_pkey_provided/ED448.pub.der
Binary files differ
diff --git a/test/recipes/30-test_evp_pkey_provided/ED448.pub.pem b/test/recipes/30-test_evp_pkey_provided/ED448.pub.pem
new file mode 100644
index 0000000000..640da6f2be
--- /dev/null
+++ b/test/recipes/30-test_evp_pkey_provided/ED448.pub.pem
@@ -0,0 +1,4 @@
+-----BEGIN PUBLIC KEY-----
+MEMwBQYDK2VxAzoAX9dEm1m0Yf0s54fsYWrUah2hNCSFpw4fig6nXYDpZ3jt8SR2
+m0bHBhvWeD3x5Q9s0foavq/oJWGA
+-----END PUBLIC KEY-----
diff --git a/test/recipes/30-test_evp_pkey_provided/ED448.pub.txt b/test/recipes/30-test_evp_pkey_provided/ED448.pub.txt
new file mode 100644
index 0000000000..06a2967b44
--- /dev/null
+++ b/test/recipes/30-test_evp_pkey_provided/ED448.pub.txt
@@ -0,0 +1,6 @@
+ED448 Public-Key:
+pub:
+ 5f:d7:44:9b:59:b4:61:fd:2c:e7:87:ec:61:6a:d4:
+ 6a:1d:a1:34:24:85:a7:0e:1f:8a:0e:a7:5d:80:e9:
+ 67:78:ed:f1:24:76:9b:46:c7:06:1b:d6:78:3d:f1:
+ e5:0f:6c:d1:fa:1a:be:af:e8:25:61:80