diff options
Diffstat (limited to 'recipes-connectivity/openssl/openssl-qoriq/qoriq')
68 files changed, 7655 insertions, 6275 deletions
diff --git a/recipes-connectivity/openssl/openssl-qoriq/qoriq/0001-remove-double-initialization-of-cryptodev-engine.patch b/recipes-connectivity/openssl/openssl-qoriq/qoriq/0001-remove-double-initialization-of-cryptodev-engine.patch index e7b874f5f..5e99d912b 100644 --- a/recipes-connectivity/openssl/openssl-qoriq/qoriq/0001-remove-double-initialization-of-cryptodev-engine.patch +++ b/recipes-connectivity/openssl/openssl-qoriq/qoriq/0001-remove-double-initialization-of-cryptodev-engine.patch | |||
| @@ -1,7 +1,7 @@ | |||
| 1 | From 9297e3834518ff0558d6e7004a62adfd107e659a Mon Sep 17 00:00:00 2001 | 1 | From 45e4b0835ad965cf9cc813a31df354f1e6d14513 Mon Sep 17 00:00:00 2001 |
| 2 | From: Cristian Stoica <cristian.stoica@freescale.com> | 2 | From: Cristian Stoica <cristian.stoica@freescale.com> |
| 3 | Date: Tue, 10 Sep 2013 12:46:46 +0300 | 3 | Date: Tue, 10 Sep 2013 12:46:46 +0300 |
| 4 | Subject: [PATCH 01/26] remove double initialization of cryptodev engine | 4 | Subject: [PATCH 01/48] remove double initialization of cryptodev engine |
| 5 | 5 | ||
| 6 | cryptodev engine is initialized together with the other engines in | 6 | cryptodev engine is initialized together with the other engines in |
| 7 | ENGINE_load_builtin_engines. The initialization done through | 7 | ENGINE_load_builtin_engines. The initialization done through |
| @@ -11,65 +11,66 @@ Change-Id: Ic9488500967595543ff846f147b36f383db7cb27 | |||
| 11 | Signed-off-by: Cristian Stoica <cristian.stoica@freescale.com> | 11 | Signed-off-by: Cristian Stoica <cristian.stoica@freescale.com> |
| 12 | Reviewed-on: http://git.am.freescale.net:8181/17222 | 12 | Reviewed-on: http://git.am.freescale.net:8181/17222 |
| 13 | --- | 13 | --- |
| 14 | crypto/engine/eng_all.c | 11 ----------- | 14 | crypto/engine/eng_all.c | 12 ------------ |
| 15 | crypto/engine/engine.h | 4 ---- | 15 | crypto/engine/engine.h | 4 ---- |
| 16 | crypto/evp/c_all.c | 5 ----- | 16 | crypto/evp/c_all.c | 5 ----- |
| 17 | util/libeay.num | 2 +- | 17 | util/libeay.num | 2 +- |
| 18 | 4 files changed, 1 insertion(+), 21 deletions(-) | 18 | 4 files changed, 1 insertion(+), 22 deletions(-) |
| 19 | 19 | ||
| 20 | diff --git a/crypto/engine/eng_all.c b/crypto/engine/eng_all.c | 20 | diff --git a/crypto/engine/eng_all.c b/crypto/engine/eng_all.c |
| 21 | index 6093376..f16c043 100644 | 21 | index 48ad0d2..a198c5f 100644 |
| 22 | --- a/crypto/engine/eng_all.c | 22 | --- a/crypto/engine/eng_all.c |
| 23 | +++ b/crypto/engine/eng_all.c | 23 | +++ b/crypto/engine/eng_all.c |
| 24 | @@ -122,14 +122,3 @@ void ENGINE_load_builtin_engines(void) | 24 | @@ -122,15 +122,3 @@ void ENGINE_load_builtin_engines(void) |
| 25 | #endif | 25 | #endif |
| 26 | ENGINE_register_all_complete(); | 26 | ENGINE_register_all_complete(); |
| 27 | } | 27 | } |
| 28 | - | 28 | - |
| 29 | -#if defined(__OpenBSD__) || defined(__FreeBSD__) || defined(HAVE_CRYPTODEV) | 29 | -#if defined(__OpenBSD__) || defined(__FreeBSD__) || defined(HAVE_CRYPTODEV) |
| 30 | -void ENGINE_setup_bsd_cryptodev(void) { | 30 | -void ENGINE_setup_bsd_cryptodev(void) |
| 31 | - static int bsd_cryptodev_default_loaded = 0; | 31 | -{ |
| 32 | - if (!bsd_cryptodev_default_loaded) { | 32 | - static int bsd_cryptodev_default_loaded = 0; |
| 33 | - ENGINE_load_cryptodev(); | 33 | - if (!bsd_cryptodev_default_loaded) { |
| 34 | - ENGINE_register_all_complete(); | 34 | - ENGINE_load_cryptodev(); |
| 35 | - } | 35 | - ENGINE_register_all_complete(); |
| 36 | - bsd_cryptodev_default_loaded=1; | 36 | - } |
| 37 | - bsd_cryptodev_default_loaded = 1; | ||
| 37 | -} | 38 | -} |
| 38 | -#endif | 39 | -#endif |
| 39 | diff --git a/crypto/engine/engine.h b/crypto/engine/engine.h | 40 | diff --git a/crypto/engine/engine.h b/crypto/engine/engine.h |
| 40 | index f8be497..237a6c9 100644 | 41 | index bd7b591..020d912 100644 |
| 41 | --- a/crypto/engine/engine.h | 42 | --- a/crypto/engine/engine.h |
| 42 | +++ b/crypto/engine/engine.h | 43 | +++ b/crypto/engine/engine.h |
| 43 | @@ -740,10 +740,6 @@ typedef int (*dynamic_bind_engine)(ENGINE *e, const char *id, | 44 | @@ -857,10 +857,6 @@ typedef int (*dynamic_bind_engine) (ENGINE *e, const char *id, |
| 44 | * values. */ | 45 | */ |
| 45 | void *ENGINE_get_static_state(void); | 46 | void *ENGINE_get_static_state(void); |
| 46 | 47 | ||
| 47 | -#if defined(__OpenBSD__) || defined(__FreeBSD__) || defined(HAVE_CRYPTODEV) | 48 | -# if defined(__OpenBSD__) || defined(__FreeBSD__) || defined(HAVE_CRYPTODEV) |
| 48 | -void ENGINE_setup_bsd_cryptodev(void); | 49 | -void ENGINE_setup_bsd_cryptodev(void); |
| 49 | -#endif | 50 | -# endif |
| 50 | - | 51 | - |
| 51 | /* BEGIN ERROR CODES */ | 52 | /* BEGIN ERROR CODES */ |
| 52 | /* The following lines are auto generated by the script mkerr.pl. Any changes | 53 | /* |
| 53 | * made after this point may be overwritten when the script is next run. | 54 | * The following lines are auto generated by the script mkerr.pl. Any changes |
| 54 | diff --git a/crypto/evp/c_all.c b/crypto/evp/c_all.c | 55 | diff --git a/crypto/evp/c_all.c b/crypto/evp/c_all.c |
| 55 | index 766c4ce..5d6c21b 100644 | 56 | index a3ed00d..719e34d 100644 |
| 56 | --- a/crypto/evp/c_all.c | 57 | --- a/crypto/evp/c_all.c |
| 57 | +++ b/crypto/evp/c_all.c | 58 | +++ b/crypto/evp/c_all.c |
| 58 | @@ -82,9 +82,4 @@ void OPENSSL_add_all_algorithms_noconf(void) | 59 | @@ -82,9 +82,4 @@ void OPENSSL_add_all_algorithms_noconf(void) |
| 59 | OPENSSL_cpuid_setup(); | 60 | OPENSSL_cpuid_setup(); |
| 60 | OpenSSL_add_all_ciphers(); | 61 | OpenSSL_add_all_ciphers(); |
| 61 | OpenSSL_add_all_digests(); | 62 | OpenSSL_add_all_digests(); |
| 62 | -#ifndef OPENSSL_NO_ENGINE | 63 | -#ifndef OPENSSL_NO_ENGINE |
| 63 | -# if defined(__OpenBSD__) || defined(__FreeBSD__) || defined(HAVE_CRYPTODEV) | 64 | -# if defined(__OpenBSD__) || defined(__FreeBSD__) || defined(HAVE_CRYPTODEV) |
| 64 | - ENGINE_setup_bsd_cryptodev(); | 65 | - ENGINE_setup_bsd_cryptodev(); |
| 65 | -# endif | 66 | -# endif |
| 66 | -#endif | 67 | -#endif |
| 67 | } | 68 | } |
| 68 | diff --git a/util/libeay.num b/util/libeay.num | 69 | diff --git a/util/libeay.num b/util/libeay.num |
| 69 | index aa86b2b..ae50040 100755 | 70 | index 2094ab3..2742cf5 100755 |
| 70 | --- a/util/libeay.num | 71 | --- a/util/libeay.num |
| 71 | +++ b/util/libeay.num | 72 | +++ b/util/libeay.num |
| 72 | @@ -2801,7 +2801,7 @@ BIO_indent 3242 EXIST::FUNCTION: | 73 | @@ -2805,7 +2805,7 @@ BIO_indent 3242 EXIST::FUNCTION: |
| 73 | BUF_strlcpy 3243 EXIST::FUNCTION: | 74 | BUF_strlcpy 3243 EXIST::FUNCTION: |
| 74 | OpenSSLDie 3244 EXIST::FUNCTION: | 75 | OpenSSLDie 3244 EXIST::FUNCTION: |
| 75 | OPENSSL_cleanse 3245 EXIST::FUNCTION: | 76 | OPENSSL_cleanse 3245 EXIST::FUNCTION: |
| @@ -79,5 +80,5 @@ index aa86b2b..ae50040 100755 | |||
| 79 | EVP_aes_128_cfb8 3248 EXIST::FUNCTION:AES | 80 | EVP_aes_128_cfb8 3248 EXIST::FUNCTION:AES |
| 80 | FIPS_corrupt_rsa 3249 NOEXIST::FUNCTION: | 81 | FIPS_corrupt_rsa 3249 NOEXIST::FUNCTION: |
| 81 | -- | 82 | -- |
| 82 | 2.3.5 | 83 | 2.7.0 |
| 83 | 84 | ||
diff --git a/recipes-connectivity/openssl/openssl-qoriq/qoriq/0002-eng_cryptodev-add-support-for-TLS-algorithms-offload.patch b/recipes-connectivity/openssl/openssl-qoriq/qoriq/0002-eng_cryptodev-add-support-for-TLS-algorithms-offload.patch index ab2b7ea91..d59078928 100644 --- a/recipes-connectivity/openssl/openssl-qoriq/qoriq/0002-eng_cryptodev-add-support-for-TLS-algorithms-offload.patch +++ b/recipes-connectivity/openssl/openssl-qoriq/qoriq/0002-eng_cryptodev-add-support-for-TLS-algorithms-offload.patch | |||
| @@ -1,7 +1,7 @@ | |||
| 1 | From dfd6ba263dc25ea2a4bbc32448b24ca2b1fc40e8 Mon Sep 17 00:00:00 2001 | 1 | From e7c630f8417b6f4e1bf2466e545ffe04af2eff00 Mon Sep 17 00:00:00 2001 |
| 2 | From: Cristian Stoica <cristian.stoica@freescale.com> | 2 | From: Cristian Stoica <cristian.stoica@freescale.com> |
| 3 | Date: Thu, 29 Aug 2013 16:51:18 +0300 | 3 | Date: Thu, 29 Aug 2013 16:51:18 +0300 |
| 4 | Subject: [PATCH 02/26] eng_cryptodev: add support for TLS algorithms offload | 4 | Subject: [PATCH 02/48] eng_cryptodev: add support for TLS algorithms offload |
| 5 | 5 | ||
| 6 | - aes-128-cbc-hmac-sha1 | 6 | - aes-128-cbc-hmac-sha1 |
| 7 | - aes-256-cbc-hmac-sha1 | 7 | - aes-256-cbc-hmac-sha1 |
| @@ -9,309 +9,335 @@ Subject: [PATCH 02/26] eng_cryptodev: add support for TLS algorithms offload | |||
| 9 | Requires TLS patches on cryptodev and TLS algorithm support in Linux | 9 | Requires TLS patches on cryptodev and TLS algorithm support in Linux |
| 10 | kernel driver. | 10 | kernel driver. |
| 11 | 11 | ||
| 12 | Change-Id: I43048caa348414daddd6c1a5cdc55e769ac1945f | ||
| 13 | Signed-off-by: Cristian Stoica <cristian.stoica@freescale.com> | 12 | Signed-off-by: Cristian Stoica <cristian.stoica@freescale.com> |
| 14 | Reviewed-on: http://git.am.freescale.net:8181/17223 | ||
| 15 | --- | 13 | --- |
| 16 | crypto/engine/eng_cryptodev.c | 222 +++++++++++++++++++++++++++++++++++++++--- | 14 | crypto/engine/eng_cryptodev.c | 226 ++++++++++++++++++++++++++++++++++++++++-- |
| 17 | 1 file changed, 211 insertions(+), 11 deletions(-) | 15 | 1 file changed, 215 insertions(+), 11 deletions(-) |
| 18 | 16 | ||
| 19 | diff --git a/crypto/engine/eng_cryptodev.c b/crypto/engine/eng_cryptodev.c | 17 | diff --git a/crypto/engine/eng_cryptodev.c b/crypto/engine/eng_cryptodev.c |
| 20 | index 5a715ac..7588a28 100644 | 18 | index 8fb9c33..4d783d4 100644 |
| 21 | --- a/crypto/engine/eng_cryptodev.c | 19 | --- a/crypto/engine/eng_cryptodev.c |
| 22 | +++ b/crypto/engine/eng_cryptodev.c | 20 | +++ b/crypto/engine/eng_cryptodev.c |
| 23 | @@ -72,6 +72,9 @@ ENGINE_load_cryptodev(void) | 21 | @@ -71,6 +71,9 @@ void ENGINE_load_cryptodev(void) |
| 24 | struct dev_crypto_state { | 22 | struct dev_crypto_state { |
| 25 | struct session_op d_sess; | 23 | struct session_op d_sess; |
| 26 | int d_fd; | 24 | int d_fd; |
| 27 | + unsigned char *aad; | 25 | + unsigned char *aad; |
| 28 | + unsigned int aad_len; | 26 | + unsigned int aad_len; |
| 29 | + unsigned int len; | 27 | + unsigned int len; |
| 30 | 28 | # ifdef USE_CRYPTODEV_DIGESTS | |
| 31 | #ifdef USE_CRYPTODEV_DIGESTS | 29 | char dummy_mac_key[HASH_MAX_LEN]; |
| 32 | char dummy_mac_key[HASH_MAX_LEN]; | 30 | unsigned char digest_res[HASH_MAX_LEN]; |
| 33 | @@ -140,17 +143,20 @@ static struct { | 31 | @@ -141,24 +144,25 @@ static struct { |
| 34 | int nid; | 32 | int nid; |
| 35 | int ivmax; | 33 | int ivmax; |
| 36 | int keylen; | 34 | int keylen; |
| 37 | + int mackeylen; | 35 | + int mackeylen; |
| 38 | } ciphers[] = { | 36 | } ciphers[] = { |
| 39 | - { CRYPTO_ARC4, NID_rc4, 0, 16, }, | 37 | { |
| 40 | - { CRYPTO_DES_CBC, NID_des_cbc, 8, 8, }, | 38 | - CRYPTO_ARC4, NID_rc4, 0, 16, |
| 41 | - { CRYPTO_3DES_CBC, NID_des_ede3_cbc, 8, 24, }, | 39 | + CRYPTO_ARC4, NID_rc4, 0, 16, 0 |
| 42 | - { CRYPTO_AES_CBC, NID_aes_128_cbc, 16, 16, }, | 40 | }, |
| 43 | - { CRYPTO_AES_CBC, NID_aes_192_cbc, 16, 24, }, | 41 | { |
| 44 | - { CRYPTO_AES_CBC, NID_aes_256_cbc, 16, 32, }, | 42 | - CRYPTO_DES_CBC, NID_des_cbc, 8, 8, |
| 45 | - { CRYPTO_BLF_CBC, NID_bf_cbc, 8, 16, }, | 43 | + CRYPTO_DES_CBC, NID_des_cbc, 8, 8, 0 |
| 46 | - { CRYPTO_CAST_CBC, NID_cast5_cbc, 8, 16, }, | 44 | }, |
| 47 | - { CRYPTO_SKIPJACK_CBC, NID_undef, 0, 0, }, | 45 | { |
| 48 | - { 0, NID_undef, 0, 0, }, | 46 | - CRYPTO_3DES_CBC, NID_des_ede3_cbc, 8, 24, |
| 49 | + { CRYPTO_ARC4, NID_rc4, 0, 16, 0}, | 47 | + CRYPTO_3DES_CBC, NID_des_ede3_cbc, 8, 24, 0 |
| 50 | + { CRYPTO_DES_CBC, NID_des_cbc, 8, 8, 0}, | 48 | }, |
| 51 | + { CRYPTO_3DES_CBC, NID_des_ede3_cbc, 8, 24, 0}, | 49 | { |
| 52 | + { CRYPTO_AES_CBC, NID_aes_128_cbc, 16, 16, 0}, | 50 | - CRYPTO_AES_CBC, NID_aes_128_cbc, 16, 16, |
| 53 | + { CRYPTO_AES_CBC, NID_aes_192_cbc, 16, 24, 0}, | 51 | + CRYPTO_AES_CBC, NID_aes_128_cbc, 16, 16, 0 |
| 54 | + { CRYPTO_AES_CBC, NID_aes_256_cbc, 16, 32, 0}, | 52 | }, |
| 55 | + { CRYPTO_BLF_CBC, NID_bf_cbc, 8, 16, 0}, | 53 | { |
| 56 | + { CRYPTO_CAST_CBC, NID_cast5_cbc, 8, 16, 0}, | 54 | - CRYPTO_AES_CBC, NID_aes_192_cbc, 16, 24, |
| 57 | + { CRYPTO_SKIPJACK_CBC, NID_undef, 0, 0, 0}, | 55 | + CRYPTO_AES_CBC, NID_aes_192_cbc, 16, 24, 0 |
| 58 | + { CRYPTO_TLS10_AES_CBC_HMAC_SHA1, NID_aes_128_cbc_hmac_sha1, 16, 16, 20}, | 56 | }, |
| 59 | + { CRYPTO_TLS10_AES_CBC_HMAC_SHA1, NID_aes_256_cbc_hmac_sha1, 16, 32, 20}, | 57 | { |
| 60 | + { 0, NID_undef, 0, 0, 0}, | 58 | - CRYPTO_AES_CBC, NID_aes_256_cbc, 16, 32, |
| 59 | + CRYPTO_AES_CBC, NID_aes_256_cbc, 16, 32, 0 | ||
| 60 | }, | ||
| 61 | # ifdef CRYPTO_AES_CTR | ||
| 62 | { | ||
| 63 | @@ -172,16 +176,22 @@ static struct { | ||
| 64 | }, | ||
| 65 | # endif | ||
| 66 | { | ||
| 67 | - CRYPTO_BLF_CBC, NID_bf_cbc, 8, 16, | ||
| 68 | + CRYPTO_BLF_CBC, NID_bf_cbc, 8, 16, 0 | ||
| 69 | }, | ||
| 70 | { | ||
| 71 | - CRYPTO_CAST_CBC, NID_cast5_cbc, 8, 16, | ||
| 72 | + CRYPTO_CAST_CBC, NID_cast5_cbc, 8, 16, 0 | ||
| 73 | }, | ||
| 74 | { | ||
| 75 | - CRYPTO_SKIPJACK_CBC, NID_undef, 0, 0, | ||
| 76 | + CRYPTO_SKIPJACK_CBC, NID_undef, 0, 0, 0 | ||
| 77 | }, | ||
| 78 | { | ||
| 79 | - 0, NID_undef, 0, 0, | ||
| 80 | + CRYPTO_TLS10_AES_CBC_HMAC_SHA1, NID_aes_128_cbc_hmac_sha1, 16, 16, 20 | ||
| 81 | + }, | ||
| 82 | + { | ||
| 83 | + CRYPTO_TLS10_AES_CBC_HMAC_SHA1, NID_aes_256_cbc_hmac_sha1, 16, 32, 20 | ||
| 84 | + }, | ||
| 85 | + { | ||
| 86 | + 0, NID_undef, 0, 0, 0 | ||
| 87 | }, | ||
| 61 | }; | 88 | }; |
| 62 | 89 | ||
| 63 | #ifdef USE_CRYPTODEV_DIGESTS | 90 | @@ -295,13 +305,15 @@ static int get_cryptodev_ciphers(const int **cnids) |
| 64 | @@ -250,13 +256,15 @@ get_cryptodev_ciphers(const int **cnids) | 91 | } |
| 65 | } | 92 | memset(&sess, 0, sizeof(sess)); |
| 66 | memset(&sess, 0, sizeof(sess)); | 93 | sess.key = (caddr_t) "123456789abcdefghijklmno"; |
| 67 | sess.key = (caddr_t)"123456789abcdefghijklmno"; | 94 | + sess.mackey = (caddr_t) "123456789ABCDEFGHIJKLMNO"; |
| 68 | + sess.mackey = (caddr_t)"123456789ABCDEFGHIJKLMNO"; | ||
| 69 | 95 | ||
| 70 | for (i = 0; ciphers[i].id && count < CRYPTO_ALGORITHM_MAX; i++) { | 96 | for (i = 0; ciphers[i].id && count < CRYPTO_ALGORITHM_MAX; i++) { |
| 71 | if (ciphers[i].nid == NID_undef) | 97 | if (ciphers[i].nid == NID_undef) |
| 72 | continue; | 98 | continue; |
| 73 | sess.cipher = ciphers[i].id; | 99 | sess.cipher = ciphers[i].id; |
| 74 | sess.keylen = ciphers[i].keylen; | 100 | sess.keylen = ciphers[i].keylen; |
| 75 | - sess.mac = 0; | 101 | - sess.mac = 0; |
| 76 | + sess.mackeylen = ciphers[i].mackeylen; | 102 | + sess.mackeylen = ciphers[i].mackeylen; |
| 77 | + | 103 | + |
| 78 | if (ioctl(fd, CIOCGSESSION, &sess) != -1 && | 104 | if (ioctl(fd, CIOCGSESSION, &sess) != -1 && |
| 79 | ioctl(fd, CIOCFSESSION, &sess.ses) != -1) | 105 | ioctl(fd, CIOCFSESSION, &sess.ses) != -1) |
| 80 | nids[count++] = ciphers[i].nid; | 106 | nids[count++] = ciphers[i].nid; |
| 81 | @@ -414,6 +422,67 @@ cryptodev_cipher(EVP_CIPHER_CTX *ctx, unsigned char *out, | 107 | @@ -457,6 +469,66 @@ cryptodev_cipher(EVP_CIPHER_CTX *ctx, unsigned char *out, |
| 82 | return (1); | 108 | return (1); |
| 83 | } | 109 | } |
| 84 | 110 | ||
| 85 | + | ||
| 86 | +static int cryptodev_aead_cipher(EVP_CIPHER_CTX *ctx, unsigned char *out, | 111 | +static int cryptodev_aead_cipher(EVP_CIPHER_CTX *ctx, unsigned char *out, |
| 87 | + const unsigned char *in, size_t len) | 112 | + const unsigned char *in, size_t len) |
| 88 | +{ | 113 | +{ |
| 89 | + struct crypt_auth_op cryp; | 114 | + struct crypt_auth_op cryp; |
| 90 | + struct dev_crypto_state *state = ctx->cipher_data; | 115 | + struct dev_crypto_state *state = ctx->cipher_data; |
| 91 | + struct session_op *sess = &state->d_sess; | 116 | + struct session_op *sess = &state->d_sess; |
| 92 | + const void *iiv; | 117 | + const void *iiv; |
| 93 | + unsigned char save_iv[EVP_MAX_IV_LENGTH]; | 118 | + unsigned char save_iv[EVP_MAX_IV_LENGTH]; |
| 94 | + | 119 | + |
| 95 | + if (state->d_fd < 0) | 120 | + if (state->d_fd < 0) |
| 96 | + return (0); | 121 | + return (0); |
| 97 | + if (!len) | 122 | + if (!len) |
| 98 | + return (1); | 123 | + return (1); |
| 99 | + if ((len % ctx->cipher->block_size) != 0) | 124 | + if ((len % ctx->cipher->block_size) != 0) |
| 100 | + return (0); | 125 | + return (0); |
| 101 | + | 126 | + |
| 102 | + memset(&cryp, 0, sizeof(cryp)); | 127 | + memset(&cryp, 0, sizeof(cryp)); |
| 103 | + | 128 | + |
| 104 | + /* TODO: make a seamless integration with cryptodev flags */ | 129 | + /* TODO: make a seamless integration with cryptodev flags */ |
| 105 | + switch (ctx->cipher->nid) { | 130 | + switch (ctx->cipher->nid) { |
| 106 | + case NID_aes_128_cbc_hmac_sha1: | 131 | + case NID_aes_128_cbc_hmac_sha1: |
| 107 | + case NID_aes_256_cbc_hmac_sha1: | 132 | + case NID_aes_256_cbc_hmac_sha1: |
| 108 | + cryp.flags = COP_FLAG_AEAD_TLS_TYPE; | 133 | + cryp.flags = COP_FLAG_AEAD_TLS_TYPE; |
| 109 | + } | 134 | + } |
| 110 | + cryp.ses = sess->ses; | 135 | + cryp.ses = sess->ses; |
| 111 | + cryp.len = state->len; | 136 | + cryp.len = state->len; |
| 112 | + cryp.src = (caddr_t) in; | 137 | + cryp.src = (caddr_t) in; |
| 113 | + cryp.dst = (caddr_t) out; | 138 | + cryp.dst = (caddr_t) out; |
| 114 | + cryp.auth_src = state->aad; | 139 | + cryp.auth_src = state->aad; |
| 115 | + cryp.auth_len = state->aad_len; | 140 | + cryp.auth_len = state->aad_len; |
| 116 | + | 141 | + |
| 117 | + cryp.op = ctx->encrypt ? COP_ENCRYPT : COP_DECRYPT; | 142 | + cryp.op = ctx->encrypt ? COP_ENCRYPT : COP_DECRYPT; |
| 118 | + | 143 | + |
| 119 | + if (ctx->cipher->iv_len) { | 144 | + if (ctx->cipher->iv_len) { |
| 120 | + cryp.iv = (caddr_t) ctx->iv; | 145 | + cryp.iv = (caddr_t) ctx->iv; |
| 121 | + if (!ctx->encrypt) { | 146 | + if (!ctx->encrypt) { |
| 122 | + iiv = in + len - ctx->cipher->iv_len; | 147 | + iiv = in + len - ctx->cipher->iv_len; |
| 123 | + memcpy(save_iv, iiv, ctx->cipher->iv_len); | 148 | + memcpy(save_iv, iiv, ctx->cipher->iv_len); |
| 124 | + } | 149 | + } |
| 125 | + } else | 150 | + } else |
| 126 | + cryp.iv = NULL; | 151 | + cryp.iv = NULL; |
| 127 | + | 152 | + |
| 128 | + if (ioctl(state->d_fd, CIOCAUTHCRYPT, &cryp) == -1) { | 153 | + if (ioctl(state->d_fd, CIOCAUTHCRYPT, &cryp) == -1) { |
| 129 | + /* XXX need better errror handling | 154 | + /* |
| 130 | + * this can fail for a number of different reasons. | 155 | + * XXX need better errror handling this can fail for a number of |
| 131 | + */ | 156 | + * different reasons. |
| 132 | + return (0); | 157 | + */ |
| 133 | + } | 158 | + return (0); |
| 159 | + } | ||
| 134 | + | 160 | + |
| 135 | + if (ctx->cipher->iv_len) { | 161 | + if (ctx->cipher->iv_len) { |
| 136 | + if (ctx->encrypt) | 162 | + if (ctx->encrypt) |
| 137 | + iiv = out + len - ctx->cipher->iv_len; | 163 | + iiv = out + len - ctx->cipher->iv_len; |
| 138 | + else | 164 | + else |
| 139 | + iiv = save_iv; | 165 | + iiv = save_iv; |
| 140 | + memcpy(ctx->iv, iiv, ctx->cipher->iv_len); | 166 | + memcpy(ctx->iv, iiv, ctx->cipher->iv_len); |
| 141 | + } | 167 | + } |
| 142 | + return (1); | 168 | + return (1); |
| 143 | +} | 169 | +} |
| 144 | + | 170 | + |
| 145 | + | ||
| 146 | static int | 171 | static int |
| 147 | cryptodev_init_key(EVP_CIPHER_CTX *ctx, const unsigned char *key, | 172 | cryptodev_init_key(EVP_CIPHER_CTX *ctx, const unsigned char *key, |
| 148 | const unsigned char *iv, int enc) | 173 | const unsigned char *iv, int enc) |
| 149 | @@ -452,6 +521,45 @@ cryptodev_init_key(EVP_CIPHER_CTX *ctx, const unsigned char *key, | 174 | @@ -496,6 +568,45 @@ cryptodev_init_key(EVP_CIPHER_CTX *ctx, const unsigned char *key, |
| 150 | return (1); | ||
| 151 | } | 175 | } |
| 152 | 176 | ||
| 153 | +/* Save the encryption key provided by upper layers. | 177 | /* |
| 154 | + * | 178 | + * Save the encryption key provided by upper layers. This function is called |
| 155 | + * This function is called by EVP_CipherInit_ex to initialize the algorithm's | 179 | + * by EVP_CipherInit_ex to initialize the algorithm's extra data. We can't do |
| 156 | + * extra data. We can't do much here because the mac key is not available. | 180 | + * much here because the mac key is not available. The next call should/will |
| 157 | + * The next call should/will be to cryptodev_cbc_hmac_sha1_ctrl with parameter | 181 | + * be to cryptodev_cbc_hmac_sha1_ctrl with parameter |
| 158 | + * EVP_CTRL_AEAD_SET_MAC_KEY, to set the hmac key. There we call CIOCGSESSION | 182 | + * EVP_CTRL_AEAD_SET_MAC_KEY, to set the hmac key. There we call CIOCGSESSION |
| 159 | + * with both the crypto and hmac keys. | 183 | + * with both the crypto and hmac keys. |
| 160 | + */ | 184 | + */ |
| 161 | +static int cryptodev_init_aead_key(EVP_CIPHER_CTX *ctx, | 185 | +static int cryptodev_init_aead_key(EVP_CIPHER_CTX *ctx, |
| 162 | + const unsigned char *key, const unsigned char *iv, int enc) | 186 | + const unsigned char *key, |
| 187 | + const unsigned char *iv, int enc) | ||
| 163 | +{ | 188 | +{ |
| 164 | + struct dev_crypto_state *state = ctx->cipher_data; | 189 | + struct dev_crypto_state *state = ctx->cipher_data; |
| 165 | + struct session_op *sess = &state->d_sess; | 190 | + struct session_op *sess = &state->d_sess; |
| 166 | + int cipher = -1, i; | 191 | + int cipher = -1, i; |
| 167 | + | 192 | + |
| 168 | + for (i = 0; ciphers[i].id; i++) | 193 | + for (i = 0; ciphers[i].id; i++) |
| 169 | + if (ctx->cipher->nid == ciphers[i].nid && | 194 | + if (ctx->cipher->nid == ciphers[i].nid && |
| 170 | + ctx->cipher->iv_len <= ciphers[i].ivmax && | 195 | + ctx->cipher->iv_len <= ciphers[i].ivmax && |
| 171 | + ctx->key_len == ciphers[i].keylen) { | 196 | + ctx->key_len == ciphers[i].keylen) { |
| 172 | + cipher = ciphers[i].id; | 197 | + cipher = ciphers[i].id; |
| 173 | + break; | 198 | + break; |
| 174 | + } | 199 | + } |
| 175 | + | 200 | + |
| 176 | + if (!ciphers[i].id) { | 201 | + if (!ciphers[i].id) { |
| 177 | + state->d_fd = -1; | 202 | + state->d_fd = -1; |
| 178 | + return (0); | 203 | + return (0); |
| 179 | + } | 204 | + } |
| 180 | + | 205 | + |
| 181 | + memset(sess, 0, sizeof(struct session_op)); | 206 | + memset(sess, 0, sizeof(struct session_op)); |
| 182 | + | 207 | + |
| 183 | + sess->key = (caddr_t)key; | 208 | + sess->key = (caddr_t) key; |
| 184 | + sess->keylen = ctx->key_len; | 209 | + sess->keylen = ctx->key_len; |
| 185 | + sess->cipher = cipher; | 210 | + sess->cipher = cipher; |
| 186 | + | 211 | + |
| 187 | + /* for whatever reason, (1) means success */ | 212 | + /* for whatever reason, (1) means success */ |
| 188 | + return (1); | 213 | + return (1); |
| 189 | +} | 214 | +} |
| 190 | + | 215 | + |
| 191 | + | 216 | +/* |
| 192 | /* | ||
| 193 | * free anything we allocated earlier when initting a | 217 | * free anything we allocated earlier when initting a |
| 194 | * session, and close the session. | 218 | * session, and close the session. |
| 195 | @@ -488,6 +596,63 @@ cryptodev_cleanup(EVP_CIPHER_CTX *ctx) | 219 | */ |
| 196 | return (ret); | 220 | @@ -529,6 +640,63 @@ static int cryptodev_cleanup(EVP_CIPHER_CTX *ctx) |
| 221 | return (ret); | ||
| 197 | } | 222 | } |
| 198 | 223 | ||
| 199 | +static int cryptodev_cbc_hmac_sha1_ctrl(EVP_CIPHER_CTX *ctx, int type, int arg, | 224 | +static int cryptodev_cbc_hmac_sha1_ctrl(EVP_CIPHER_CTX *ctx, int type, |
| 200 | + void *ptr) | 225 | + int arg, void *ptr) |
| 201 | +{ | 226 | +{ |
| 202 | + switch (type) { | 227 | + switch (type) { |
| 203 | + case EVP_CTRL_AEAD_SET_MAC_KEY: | 228 | + case EVP_CTRL_AEAD_SET_MAC_KEY: |
| 204 | + { | 229 | + { |
| 205 | + /* TODO: what happens with hmac keys larger than 64 bytes? */ | 230 | + /* TODO: what happens with hmac keys larger than 64 bytes? */ |
| 206 | + struct dev_crypto_state *state = ctx->cipher_data; | 231 | + struct dev_crypto_state *state = ctx->cipher_data; |
| 207 | + struct session_op *sess = &state->d_sess; | 232 | + struct session_op *sess = &state->d_sess; |
| 208 | + | 233 | + |
| 209 | + if ((state->d_fd = get_dev_crypto()) < 0) | 234 | + if ((state->d_fd = get_dev_crypto()) < 0) |
| 210 | + return (0); | 235 | + return (0); |
| 211 | + | 236 | + |
| 212 | + /* the rest should have been set in cryptodev_init_aead_key */ | 237 | + /* the rest should have been set in cryptodev_init_aead_key */ |
| 213 | + sess->mackey = ptr; | 238 | + sess->mackey = ptr; |
| 214 | + sess->mackeylen = arg; | 239 | + sess->mackeylen = arg; |
| 215 | + | 240 | + |
| 216 | + if (ioctl(state->d_fd, CIOCGSESSION, sess) == -1) { | 241 | + if (ioctl(state->d_fd, CIOCGSESSION, sess) == -1) { |
| 217 | + put_dev_crypto(state->d_fd); | 242 | + put_dev_crypto(state->d_fd); |
| 218 | + state->d_fd = -1; | 243 | + state->d_fd = -1; |
| 219 | + return (0); | 244 | + return (0); |
| 220 | + } | 245 | + } |
| 221 | + return (1); | 246 | + return (1); |
| 222 | + } | 247 | + } |
| 223 | + case EVP_CTRL_AEAD_TLS1_AAD: | 248 | + case EVP_CTRL_AEAD_TLS1_AAD: |
| 224 | + { | 249 | + { |
| 225 | + /* ptr points to the associated data buffer of 13 bytes */ | 250 | + /* ptr points to the associated data buffer of 13 bytes */ |
| 226 | + struct dev_crypto_state *state = ctx->cipher_data; | 251 | + struct dev_crypto_state *state = ctx->cipher_data; |
| 227 | + unsigned char *p = ptr; | 252 | + unsigned char *p = ptr; |
| 228 | + unsigned int cryptlen = p[arg - 2] << 8 | p[arg - 1]; | 253 | + unsigned int cryptlen = p[arg - 2] << 8 | p[arg - 1]; |
| 229 | + unsigned int maclen, padlen; | 254 | + unsigned int maclen, padlen; |
| 230 | + unsigned int bs = ctx->cipher->block_size; | 255 | + unsigned int bs = ctx->cipher->block_size; |
| 231 | + | 256 | + |
| 232 | + state->aad = ptr; | 257 | + state->aad = ptr; |
| 233 | + state->aad_len = arg; | 258 | + state->aad_len = arg; |
| 234 | + state->len = cryptlen; | 259 | + state->len = cryptlen; |
| 235 | + | 260 | + |
| 236 | + /* TODO: this should be an extension of EVP_CIPHER struct */ | 261 | + /* TODO: this should be an extension of EVP_CIPHER struct */ |
| 237 | + switch (ctx->cipher->nid) { | 262 | + switch (ctx->cipher->nid) { |
| 238 | + case NID_aes_128_cbc_hmac_sha1: | 263 | + case NID_aes_128_cbc_hmac_sha1: |
| 239 | + case NID_aes_256_cbc_hmac_sha1: | 264 | + case NID_aes_256_cbc_hmac_sha1: |
| 240 | + maclen = SHA_DIGEST_LENGTH; | 265 | + maclen = SHA_DIGEST_LENGTH; |
| 241 | + } | 266 | + } |
| 242 | + | 267 | + |
| 243 | + /* space required for encryption (not only TLS padding) */ | 268 | + /* space required for encryption (not only TLS padding) */ |
| 244 | + padlen = maclen; | 269 | + padlen = maclen; |
| 245 | + if (ctx->encrypt) { | 270 | + if (ctx->encrypt) { |
| 246 | + cryptlen += maclen; | 271 | + cryptlen += maclen; |
| 247 | + padlen += bs - (cryptlen % bs); | 272 | + padlen += bs - (cryptlen % bs); |
| 248 | + } | 273 | + } |
| 249 | + return padlen; | 274 | + return padlen; |
| 250 | + } | 275 | + } |
| 251 | + default: | 276 | + default: |
| 252 | + return -1; | 277 | + return -1; |
| 253 | + } | 278 | + } |
| 254 | +} | 279 | +} |
| 255 | + | 280 | + |
| 256 | /* | 281 | /* |
| 257 | * libcrypto EVP stuff - this is how we get wired to EVP so the engine | 282 | * libcrypto EVP stuff - this is how we get wired to EVP so the engine |
| 258 | * gets called when libcrypto requests a cipher NID. | 283 | * gets called when libcrypto requests a cipher NID. |
| 259 | @@ -600,6 +765,33 @@ const EVP_CIPHER cryptodev_aes_256_cbc = { | 284 | @@ -641,6 +809,34 @@ const EVP_CIPHER cryptodev_aes_256_cbc = { |
| 260 | NULL | 285 | NULL |
| 261 | }; | 286 | }; |
| 262 | 287 | ||
| 263 | +const EVP_CIPHER cryptodev_aes_128_cbc_hmac_sha1 = { | 288 | +const EVP_CIPHER cryptodev_aes_128_cbc_hmac_sha1 = { |
| 264 | + NID_aes_128_cbc_hmac_sha1, | 289 | + NID_aes_128_cbc_hmac_sha1, |
| 265 | + 16, 16, 16, | 290 | + 16, 16, 16, |
| 266 | + EVP_CIPH_CBC_MODE | EVP_CIPH_FLAG_AEAD_CIPHER, | 291 | + EVP_CIPH_CBC_MODE | EVP_CIPH_FLAG_AEAD_CIPHER, |
| 267 | + cryptodev_init_aead_key, | 292 | + cryptodev_init_aead_key, |
| 268 | + cryptodev_aead_cipher, | 293 | + cryptodev_aead_cipher, |
| 269 | + cryptodev_cleanup, | 294 | + cryptodev_cleanup, |
| 270 | + sizeof(struct dev_crypto_state), | 295 | + sizeof(struct dev_crypto_state), |
| 271 | + EVP_CIPHER_set_asn1_iv, | 296 | + EVP_CIPHER_set_asn1_iv, |
| 272 | + EVP_CIPHER_get_asn1_iv, | 297 | + EVP_CIPHER_get_asn1_iv, |
| 273 | + cryptodev_cbc_hmac_sha1_ctrl, | 298 | + cryptodev_cbc_hmac_sha1_ctrl, |
| 274 | + NULL | 299 | + NULL |
| 275 | +}; | 300 | +}; |
| 276 | + | 301 | + |
| 277 | +const EVP_CIPHER cryptodev_aes_256_cbc_hmac_sha1 = { | 302 | +const EVP_CIPHER cryptodev_aes_256_cbc_hmac_sha1 = { |
| 278 | + NID_aes_256_cbc_hmac_sha1, | 303 | + NID_aes_256_cbc_hmac_sha1, |
| 279 | + 16, 32, 16, | 304 | + 16, 32, 16, |
| 280 | + EVP_CIPH_CBC_MODE | EVP_CIPH_FLAG_AEAD_CIPHER, | 305 | + EVP_CIPH_CBC_MODE | EVP_CIPH_FLAG_AEAD_CIPHER, |
| 281 | + cryptodev_init_aead_key, | 306 | + cryptodev_init_aead_key, |
| 282 | + cryptodev_aead_cipher, | 307 | + cryptodev_aead_cipher, |
| 283 | + cryptodev_cleanup, | 308 | + cryptodev_cleanup, |
| 284 | + sizeof(struct dev_crypto_state), | 309 | + sizeof(struct dev_crypto_state), |
| 285 | + EVP_CIPHER_set_asn1_iv, | 310 | + EVP_CIPHER_set_asn1_iv, |
| 286 | + EVP_CIPHER_get_asn1_iv, | 311 | + EVP_CIPHER_get_asn1_iv, |
| 287 | + cryptodev_cbc_hmac_sha1_ctrl, | 312 | + cryptodev_cbc_hmac_sha1_ctrl, |
| 288 | + NULL | 313 | + NULL |
| 289 | +}; | 314 | +}; |
| 290 | /* | 315 | + |
| 291 | * Registered by the ENGINE when used to find out how to deal with | 316 | # ifdef CRYPTO_AES_CTR |
| 292 | * a particular NID in the ENGINE. this says what we'll do at the | 317 | const EVP_CIPHER cryptodev_aes_ctr = { |
| 293 | @@ -637,6 +829,12 @@ cryptodev_engine_ciphers(ENGINE *e, const EVP_CIPHER **cipher, | 318 | NID_aes_128_ctr, |
| 294 | case NID_aes_256_cbc: | 319 | @@ -729,6 +925,12 @@ cryptodev_engine_ciphers(ENGINE *e, const EVP_CIPHER **cipher, |
| 295 | *cipher = &cryptodev_aes_256_cbc; | 320 | *cipher = &cryptodev_aes_ctr_256; |
| 296 | break; | 321 | break; |
| 297 | + case NID_aes_128_cbc_hmac_sha1: | 322 | # endif |
| 298 | + *cipher = &cryptodev_aes_128_cbc_hmac_sha1; | 323 | + case NID_aes_128_cbc_hmac_sha1: |
| 299 | + break; | 324 | + *cipher = &cryptodev_aes_128_cbc_hmac_sha1; |
| 300 | + case NID_aes_256_cbc_hmac_sha1: | 325 | + break; |
| 301 | + *cipher = &cryptodev_aes_256_cbc_hmac_sha1; | 326 | + case NID_aes_256_cbc_hmac_sha1: |
| 302 | + break; | 327 | + *cipher = &cryptodev_aes_256_cbc_hmac_sha1; |
| 303 | default: | 328 | + break; |
| 304 | *cipher = NULL; | 329 | default: |
| 305 | break; | 330 | *cipher = NULL; |
| 306 | @@ -1384,6 +1582,8 @@ ENGINE_load_cryptodev(void) | 331 | break; |
| 307 | } | 332 | @@ -1472,6 +1674,8 @@ void ENGINE_load_cryptodev(void) |
| 308 | put_dev_crypto(fd); | 333 | } |
| 334 | put_dev_crypto(fd); | ||
| 309 | 335 | ||
| 310 | + EVP_add_cipher(&cryptodev_aes_128_cbc_hmac_sha1); | 336 | + EVP_add_cipher(&cryptodev_aes_128_cbc_hmac_sha1); |
| 311 | + EVP_add_cipher(&cryptodev_aes_256_cbc_hmac_sha1); | 337 | + EVP_add_cipher(&cryptodev_aes_256_cbc_hmac_sha1); |
| 312 | if (!ENGINE_set_id(engine, "cryptodev") || | 338 | if (!ENGINE_set_id(engine, "cryptodev") || |
| 313 | !ENGINE_set_name(engine, "BSD cryptodev engine") || | 339 | !ENGINE_set_name(engine, "BSD cryptodev engine") || |
| 314 | !ENGINE_set_ciphers(engine, cryptodev_engine_ciphers) || | 340 | !ENGINE_set_ciphers(engine, cryptodev_engine_ciphers) || |
| 315 | -- | 341 | -- |
| 316 | 2.3.5 | 342 | 2.7.0 |
| 317 | 343 | ||
diff --git a/recipes-connectivity/openssl/openssl-qoriq/qoriq/0003-cryptodev-fix-algorithm-registration.patch b/recipes-connectivity/openssl/openssl-qoriq/qoriq/0003-cryptodev-fix-algorithm-registration.patch index f0d97e9a1..9d30cc321 100644 --- a/recipes-connectivity/openssl/openssl-qoriq/qoriq/0003-cryptodev-fix-algorithm-registration.patch +++ b/recipes-connectivity/openssl/openssl-qoriq/qoriq/0003-cryptodev-fix-algorithm-registration.patch | |||
| @@ -1,64 +1,61 @@ | |||
| 1 | From 084fa469a8fef530d71a0870364df1c7997f6465 Mon Sep 17 00:00:00 2001 | 1 | From 36bb0879b498f8e87798848dafa058476f723165 Mon Sep 17 00:00:00 2001 |
| 2 | From: Cristian Stoica <cristian.stoica@freescale.com> | 2 | From: Cristian Stoica <cristian.stoica@freescale.com> |
| 3 | Date: Thu, 31 Jul 2014 14:06:19 +0300 | 3 | Date: Thu, 31 Jul 2014 14:06:19 +0300 |
| 4 | Subject: [PATCH 03/26] cryptodev: fix algorithm registration | 4 | Subject: [PATCH 03/48] cryptodev: fix algorithm registration |
| 5 | 5 | ||
| 6 | Cryptodev specific algorithms must register only if available in kernel. | 6 | Cryptodev specific algorithms must register only if available in kernel. |
| 7 | 7 | ||
| 8 | Change-Id: Iec5af8f4f3138357e4b96f2ec1627278134e4808 | ||
| 9 | Signed-off-by: Cristian Stoica <cristian.stoica@freescale.com> | 8 | Signed-off-by: Cristian Stoica <cristian.stoica@freescale.com> |
| 10 | Reviewed-on: http://git.am.freescale.net:8181/15326 | ||
| 11 | Reviewed-by: Horia Ioan Geanta Neag <horia.geanta@freescale.com> | 9 | Reviewed-by: Horia Ioan Geanta Neag <horia.geanta@freescale.com> |
| 12 | Reviewed-on: http://git.am.freescale.net:8181/17224 | ||
| 13 | --- | 10 | --- |
| 14 | crypto/engine/eng_cryptodev.c | 20 +++++++++++++++++--- | 11 | crypto/engine/eng_cryptodev.c | 20 +++++++++++++++++--- |
| 15 | 1 file changed, 17 insertions(+), 3 deletions(-) | 12 | 1 file changed, 17 insertions(+), 3 deletions(-) |
| 16 | 13 | ||
| 17 | diff --git a/crypto/engine/eng_cryptodev.c b/crypto/engine/eng_cryptodev.c | 14 | diff --git a/crypto/engine/eng_cryptodev.c b/crypto/engine/eng_cryptodev.c |
| 18 | index 7588a28..e3eb98b 100644 | 15 | index 4d783d4..3b6515e 100644 |
| 19 | --- a/crypto/engine/eng_cryptodev.c | 16 | --- a/crypto/engine/eng_cryptodev.c |
| 20 | +++ b/crypto/engine/eng_cryptodev.c | 17 | +++ b/crypto/engine/eng_cryptodev.c |
| 21 | @@ -133,6 +133,8 @@ static int cryptodev_dh_compute_key(unsigned char *key, | 18 | @@ -134,6 +134,8 @@ static int cryptodev_dh_compute_key(unsigned char *key, const BIGNUM *pub_key, |
| 22 | static int cryptodev_ctrl(ENGINE *e, int cmd, long i, void *p, | 19 | static int cryptodev_ctrl(ENGINE *e, int cmd, long i, void *p, |
| 23 | void (*f)(void)); | 20 | void (*f) (void)); |
| 24 | void ENGINE_load_cryptodev(void); | 21 | void ENGINE_load_cryptodev(void); |
| 25 | +const EVP_CIPHER cryptodev_aes_128_cbc_hmac_sha1; | 22 | +const EVP_CIPHER cryptodev_aes_128_cbc_hmac_sha1; |
| 26 | +const EVP_CIPHER cryptodev_aes_256_cbc_hmac_sha1; | 23 | +const EVP_CIPHER cryptodev_aes_256_cbc_hmac_sha1; |
| 27 | 24 | ||
| 28 | static const ENGINE_CMD_DEFN cryptodev_defns[] = { | 25 | static const ENGINE_CMD_DEFN cryptodev_defns[] = { |
| 29 | { 0, NULL, NULL, 0 } | 26 | {0, NULL, NULL, 0} |
| 30 | @@ -342,7 +344,21 @@ get_cryptodev_digests(const int **cnids) | 27 | @@ -389,7 +391,21 @@ static int get_cryptodev_digests(const int **cnids) |
| 31 | static int | 28 | */ |
| 32 | cryptodev_usable_ciphers(const int **nids) | 29 | static int cryptodev_usable_ciphers(const int **nids) |
| 33 | { | 30 | { |
| 34 | - return (get_cryptodev_ciphers(nids)); | 31 | - return (get_cryptodev_ciphers(nids)); |
| 35 | + int i, count; | 32 | + int i, count; |
| 36 | + | 33 | + |
| 37 | + count = get_cryptodev_ciphers(nids); | 34 | + count = get_cryptodev_ciphers(nids); |
| 38 | + /* add ciphers specific to cryptodev if found in kernel */ | 35 | + /* add ciphers specific to cryptodev if found in kernel */ |
| 39 | + for(i = 0; i < count; i++) { | 36 | + for (i = 0; i < count; i++) { |
| 40 | + switch (*(*nids + i)) { | 37 | + switch (*(*nids + i)) { |
| 41 | + case NID_aes_128_cbc_hmac_sha1: | 38 | + case NID_aes_128_cbc_hmac_sha1: |
| 42 | + EVP_add_cipher(&cryptodev_aes_128_cbc_hmac_sha1); | 39 | + EVP_add_cipher(&cryptodev_aes_128_cbc_hmac_sha1); |
| 43 | + break; | 40 | + break; |
| 44 | + case NID_aes_256_cbc_hmac_sha1: | 41 | + case NID_aes_256_cbc_hmac_sha1: |
| 45 | + EVP_add_cipher(&cryptodev_aes_256_cbc_hmac_sha1); | 42 | + EVP_add_cipher(&cryptodev_aes_256_cbc_hmac_sha1); |
| 46 | + break; | 43 | + break; |
| 47 | + } | 44 | + } |
| 48 | + } | 45 | + } |
| 49 | + return count; | 46 | + return count; |
| 50 | } | 47 | } |
| 51 | 48 | ||
| 52 | static int | 49 | static int cryptodev_usable_digests(const int **nids) |
| 53 | @@ -1582,8 +1598,6 @@ ENGINE_load_cryptodev(void) | 50 | @@ -1674,8 +1690,6 @@ void ENGINE_load_cryptodev(void) |
| 54 | } | 51 | } |
| 55 | put_dev_crypto(fd); | 52 | put_dev_crypto(fd); |
| 56 | 53 | ||
| 57 | - EVP_add_cipher(&cryptodev_aes_128_cbc_hmac_sha1); | 54 | - EVP_add_cipher(&cryptodev_aes_128_cbc_hmac_sha1); |
| 58 | - EVP_add_cipher(&cryptodev_aes_256_cbc_hmac_sha1); | 55 | - EVP_add_cipher(&cryptodev_aes_256_cbc_hmac_sha1); |
| 59 | if (!ENGINE_set_id(engine, "cryptodev") || | 56 | if (!ENGINE_set_id(engine, "cryptodev") || |
| 60 | !ENGINE_set_name(engine, "BSD cryptodev engine") || | 57 | !ENGINE_set_name(engine, "BSD cryptodev engine") || |
| 61 | !ENGINE_set_ciphers(engine, cryptodev_engine_ciphers) || | 58 | !ENGINE_set_ciphers(engine, cryptodev_engine_ciphers) || |
| 62 | -- | 59 | -- |
| 63 | 2.3.5 | 60 | 2.7.0 |
| 64 | 61 | ||
diff --git a/recipes-connectivity/openssl/openssl-qoriq/qoriq/0005-ECC-Support-header-for-Cryptodev-Engine.patch b/recipes-connectivity/openssl/openssl-qoriq/qoriq/0004-ECC-Support-header-for-Cryptodev-Engine.patch index c9ff5aa8c..64a5c704c 100644 --- a/recipes-connectivity/openssl/openssl-qoriq/qoriq/0005-ECC-Support-header-for-Cryptodev-Engine.patch +++ b/recipes-connectivity/openssl/openssl-qoriq/qoriq/0004-ECC-Support-header-for-Cryptodev-Engine.patch | |||
| @@ -1,22 +1,22 @@ | |||
| 1 | From 15abbcd740eafbf2a46b5da24be76acf4982743d Mon Sep 17 00:00:00 2001 | 1 | From 0a9f99574266225c6fa1a10d91eb3fdc755140b8 Mon Sep 17 00:00:00 2001 |
| 2 | From: Yashpal Dutta <yashpal.dutta@freescale.com> | 2 | From: Yashpal Dutta <yashpal.dutta@freescale.com> |
| 3 | Date: Tue, 11 Mar 2014 05:56:54 +0545 | 3 | Date: Tue, 11 Mar 2014 05:56:54 +0545 |
| 4 | Subject: [PATCH 05/26] ECC Support header for Cryptodev Engine | 4 | Subject: [PATCH 04/48] ECC Support header for Cryptodev Engine |
| 5 | 5 | ||
| 6 | Upstream-status: Pending | 6 | Upstream-status: Pending |
| 7 | 7 | ||
| 8 | Signed-off-by: Yashpal Dutta <yashpal.dutta@freescale.com> | 8 | Signed-off-by: Yashpal Dutta <yashpal.dutta@freescale.com> |
| 9 | --- | 9 | --- |
| 10 | crypto/engine/eng_cryptodev_ec.h | 296 +++++++++++++++++++++++++++++++++++++++ | 10 | crypto/engine/eng_cryptodev_ec.h | 297 +++++++++++++++++++++++++++++++++++++++ |
| 11 | 1 file changed, 296 insertions(+) | 11 | 1 file changed, 297 insertions(+) |
| 12 | create mode 100644 crypto/engine/eng_cryptodev_ec.h | 12 | create mode 100644 crypto/engine/eng_cryptodev_ec.h |
| 13 | 13 | ||
| 14 | diff --git a/crypto/engine/eng_cryptodev_ec.h b/crypto/engine/eng_cryptodev_ec.h | 14 | diff --git a/crypto/engine/eng_cryptodev_ec.h b/crypto/engine/eng_cryptodev_ec.h |
| 15 | new file mode 100644 | 15 | new file mode 100644 |
| 16 | index 0000000..77aee71 | 16 | index 0000000..af54c51 |
| 17 | --- /dev/null | 17 | --- /dev/null |
| 18 | +++ b/crypto/engine/eng_cryptodev_ec.h | 18 | +++ b/crypto/engine/eng_cryptodev_ec.h |
| 19 | @@ -0,0 +1,296 @@ | 19 | @@ -0,0 +1,297 @@ |
| 20 | +/* | 20 | +/* |
| 21 | + * Copyright (C) 2012 Freescale Semiconductor, Inc. | 21 | + * Copyright (C) 2012 Freescale Semiconductor, Inc. |
| 22 | + * | 22 | + * |
| @@ -29,16 +29,17 @@ index 0000000..77aee71 | |||
| 29 | + * notice, this list of conditions and the following disclaimer in the | 29 | + * notice, this list of conditions and the following disclaimer in the |
| 30 | + * documentation and/or other materials provided with the distribution. | 30 | + * documentation and/or other materials provided with the distribution. |
| 31 | + * | 31 | + * |
| 32 | + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR | 32 | + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND ANY |
| 33 | + * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES | 33 | + * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED |
| 34 | + * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN | 34 | + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE |
| 35 | + * NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, | 35 | + * DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR ANY |
| 36 | + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED | 36 | + * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES |
| 37 | + * TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR | 37 | + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; |
| 38 | + * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF | 38 | + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND |
| 39 | + * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING | 39 | + * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
| 40 | + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS | 40 | + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF |
| 41 | + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | 41 | + * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 42 | + * | ||
| 42 | + */ | 43 | + */ |
| 43 | +#ifndef __ENG_EC_H | 44 | +#ifndef __ENG_EC_H |
| 44 | +#define __ENG_EC_H | 45 | +#define __ENG_EC_H |
| @@ -314,5 +315,5 @@ index 0000000..77aee71 | |||
| 314 | +}; | 315 | +}; |
| 315 | +#endif | 316 | +#endif |
| 316 | -- | 317 | -- |
| 317 | 2.3.5 | 318 | 2.7.0 |
| 318 | 319 | ||
diff --git a/recipes-connectivity/openssl/openssl-qoriq/qoriq/0004-linux-pcc-make-it-more-robust-and-recognize-KERNEL_B.patch b/recipes-connectivity/openssl/openssl-qoriq/qoriq/0004-linux-pcc-make-it-more-robust-and-recognize-KERNEL_B.patch deleted file mode 100644 index 2d722d8a2..000000000 --- a/recipes-connectivity/openssl/openssl-qoriq/qoriq/0004-linux-pcc-make-it-more-robust-and-recognize-KERNEL_B.patch +++ /dev/null | |||
| @@ -1,74 +0,0 @@ | |||
| 1 | From 7d770f0324498d1fa78300cc5cecc8c1dcd3b788 Mon Sep 17 00:00:00 2001 | ||
| 2 | From: Andy Polyakov <appro@openssl.org> | ||
| 3 | Date: Sun, 21 Oct 2012 18:19:41 +0000 | ||
| 4 | Subject: [PATCH 04/26] linux-pcc: make it more robust and recognize | ||
| 5 | KERNEL_BITS variable. | ||
| 6 | |||
| 7 | (cherry picked from commit 78c3e20579d3baa159c8b51b59d415b6e521614b) | ||
| 8 | |||
| 9 | Change-Id: I769c466f052305681ab54a1b6545d94c7fbf5a9d | ||
| 10 | Signed-off-by: Cristian Stoica <cristian.stoica@freescale.com> | ||
| 11 | --- | ||
| 12 | config | 19 +++++++++++++------ | ||
| 13 | crypto/ppccap.c | 7 +++++++ | ||
| 14 | 2 files changed, 20 insertions(+), 6 deletions(-) | ||
| 15 | |||
| 16 | diff --git a/config b/config | ||
| 17 | index 41fa2a6..f37b9e6 100755 | ||
| 18 | --- a/config | ||
| 19 | +++ b/config | ||
| 20 | @@ -587,13 +587,20 @@ case "$GUESSOS" in | ||
| 21 | fi | ||
| 22 | ;; | ||
| 23 | ppc64-*-linux2) | ||
| 24 | - echo "WARNING! If you wish to build 64-bit library, then you have to" | ||
| 25 | - echo " invoke './Configure linux-ppc64' *manually*." | ||
| 26 | - if [ "$TEST" = "false" -a -t 1 ]; then | ||
| 27 | - echo " You have about 5 seconds to press Ctrl-C to abort." | ||
| 28 | - (trap "stty `stty -g`" 2 0; stty -icanon min 0 time 50; read waste) <&1 | ||
| 29 | + if [ -z "$KERNEL_BITS" ]; then | ||
| 30 | + echo "WARNING! If you wish to build 64-bit library, then you have to" | ||
| 31 | + echo " invoke './Configure linux-ppc64' *manually*." | ||
| 32 | + if [ "$TEST" = "false" -a -t 1 ]; then | ||
| 33 | + echo " You have about 5 seconds to press Ctrl-C to abort." | ||
| 34 | + (trap "stty `stty -g`" 2 0; stty -icanon min 0 time 50; read waste) <&1 | ||
| 35 | + fi | ||
| 36 | + fi | ||
| 37 | + if [ "$KERNEL_BITS" = "64" ]; then | ||
| 38 | + OUT="linux-ppc64" | ||
| 39 | + else | ||
| 40 | + OUT="linux-ppc" | ||
| 41 | + (echo "__LP64__" | gcc -E -x c - 2>/dev/null | grep "^__LP64__" 2>&1 > /dev/null) || options="$options -m32" | ||
| 42 | fi | ||
| 43 | - OUT="linux-ppc" | ||
| 44 | ;; | ||
| 45 | ppc-*-linux2) OUT="linux-ppc" ;; | ||
| 46 | ppc60x-*-vxworks*) OUT="vxworks-ppc60x" ;; | ||
| 47 | diff --git a/crypto/ppccap.c b/crypto/ppccap.c | ||
| 48 | index f71ba66..531f1b3 100644 | ||
| 49 | --- a/crypto/ppccap.c | ||
| 50 | +++ b/crypto/ppccap.c | ||
| 51 | @@ -4,6 +4,9 @@ | ||
| 52 | #include <setjmp.h> | ||
| 53 | #include <signal.h> | ||
| 54 | #include <unistd.h> | ||
| 55 | +#ifdef __linux | ||
| 56 | +#include <sys/utsname.h> | ||
| 57 | +#endif | ||
| 58 | #include <crypto.h> | ||
| 59 | #include <openssl/bn.h> | ||
| 60 | |||
| 61 | @@ -102,6 +105,10 @@ void OPENSSL_cpuid_setup(void) | ||
| 62 | |||
| 63 | if (sizeof(size_t)==4) | ||
| 64 | { | ||
| 65 | +#ifdef __linux | ||
| 66 | + struct utsname uts; | ||
| 67 | + if (uname(&uts)==0 && strcmp(uts.machine,"ppc64")==0) | ||
| 68 | +#endif | ||
| 69 | if (sigsetjmp(ill_jmp,1) == 0) | ||
| 70 | { | ||
| 71 | OPENSSL_ppc64_probe(); | ||
| 72 | -- | ||
| 73 | 2.3.5 | ||
| 74 | |||
diff --git a/recipes-connectivity/openssl/openssl-qoriq/qoriq/0005-Initial-support-for-PKC-in-cryptodev-engine.patch b/recipes-connectivity/openssl/openssl-qoriq/qoriq/0005-Initial-support-for-PKC-in-cryptodev-engine.patch new file mode 100644 index 000000000..ad253064e --- /dev/null +++ b/recipes-connectivity/openssl/openssl-qoriq/qoriq/0005-Initial-support-for-PKC-in-cryptodev-engine.patch | |||
| @@ -0,0 +1,1578 @@ | |||
| 1 | From e28df2a5c63dc6195a6065bfd7de9fc860129f56 Mon Sep 17 00:00:00 2001 | ||
| 2 | From: Yashpal Dutta <yashpal.dutta@freescale.com> | ||
| 3 | Date: Tue, 11 Mar 2014 06:29:52 +0545 | ||
| 4 | Subject: [PATCH 05/48] Initial support for PKC in cryptodev engine | ||
| 5 | |||
| 6 | Upstream-status: Pending | ||
| 7 | |||
| 8 | Signed-off-by: Yashpal Dutta <yashpal.dutta@freescale.com> | ||
| 9 | --- | ||
| 10 | crypto/engine/eng_cryptodev.c | 1365 ++++++++++++++++++++++++++++++++++++----- | ||
| 11 | 1 file changed, 1202 insertions(+), 163 deletions(-) | ||
| 12 | |||
| 13 | diff --git a/crypto/engine/eng_cryptodev.c b/crypto/engine/eng_cryptodev.c | ||
| 14 | index 3b6515e..0b41bb2 100644 | ||
| 15 | --- a/crypto/engine/eng_cryptodev.c | ||
| 16 | +++ b/crypto/engine/eng_cryptodev.c | ||
| 17 | @@ -58,6 +58,10 @@ void ENGINE_load_cryptodev(void) | ||
| 18 | # include <openssl/dsa.h> | ||
| 19 | # include <openssl/err.h> | ||
| 20 | # include <openssl/rsa.h> | ||
| 21 | +# include <crypto/ecdsa/ecs_locl.h> | ||
| 22 | +# include <crypto/ecdh/ech_locl.h> | ||
| 23 | +# include <crypto/ec/ec_lcl.h> | ||
| 24 | +# include <crypto/ec/ec.h> | ||
| 25 | # include <sys/ioctl.h> | ||
| 26 | # include <errno.h> | ||
| 27 | # include <stdio.h> | ||
| 28 | @@ -67,6 +71,7 @@ void ENGINE_load_cryptodev(void) | ||
| 29 | # include <syslog.h> | ||
| 30 | # include <errno.h> | ||
| 31 | # include <string.h> | ||
| 32 | +# include "eng_cryptodev_ec.h" | ||
| 33 | |||
| 34 | struct dev_crypto_state { | ||
| 35 | struct session_op d_sess; | ||
| 36 | @@ -115,20 +120,10 @@ static int cryptodev_rsa_nocrt_mod_exp(BIGNUM *r0, const BIGNUM *I, RSA *rsa, | ||
| 37 | BN_CTX *ctx); | ||
| 38 | static int cryptodev_rsa_mod_exp(BIGNUM *r0, const BIGNUM *I, RSA *rsa, | ||
| 39 | BN_CTX *ctx); | ||
| 40 | -static int cryptodev_dsa_bn_mod_exp(DSA *dsa, BIGNUM *r, BIGNUM *a, | ||
| 41 | - const BIGNUM *p, const BIGNUM *m, | ||
| 42 | - BN_CTX *ctx, BN_MONT_CTX *m_ctx); | ||
| 43 | -static int cryptodev_dsa_dsa_mod_exp(DSA *dsa, BIGNUM *t1, BIGNUM *g, | ||
| 44 | - BIGNUM *u1, BIGNUM *pub_key, BIGNUM *u2, | ||
| 45 | - BIGNUM *p, BN_CTX *ctx, | ||
| 46 | - BN_MONT_CTX *mont); | ||
| 47 | static DSA_SIG *cryptodev_dsa_do_sign(const unsigned char *dgst, int dlen, | ||
| 48 | DSA *dsa); | ||
| 49 | static int cryptodev_dsa_verify(const unsigned char *dgst, int dgst_len, | ||
| 50 | DSA_SIG *sig, DSA *dsa); | ||
| 51 | -static int cryptodev_mod_exp_dh(const DH *dh, BIGNUM *r, const BIGNUM *a, | ||
| 52 | - const BIGNUM *p, const BIGNUM *m, BN_CTX *ctx, | ||
| 53 | - BN_MONT_CTX *m_ctx); | ||
| 54 | static int cryptodev_dh_compute_key(unsigned char *key, const BIGNUM *pub_key, | ||
| 55 | DH *dh); | ||
| 56 | static int cryptodev_ctrl(ENGINE *e, int cmd, long i, void *p, | ||
| 57 | @@ -137,6 +132,105 @@ void ENGINE_load_cryptodev(void); | ||
| 58 | const EVP_CIPHER cryptodev_aes_128_cbc_hmac_sha1; | ||
| 59 | const EVP_CIPHER cryptodev_aes_256_cbc_hmac_sha1; | ||
| 60 | |||
| 61 | +inline int spcf_bn2bin(BIGNUM *bn, unsigned char **bin, int *bin_len) | ||
| 62 | +{ | ||
| 63 | + int len; | ||
| 64 | + unsigned char *p; | ||
| 65 | + | ||
| 66 | + len = BN_num_bytes(bn); | ||
| 67 | + | ||
| 68 | + if (!len) | ||
| 69 | + return -1; | ||
| 70 | + | ||
| 71 | + p = malloc(len); | ||
| 72 | + if (!p) | ||
| 73 | + return -1; | ||
| 74 | + | ||
| 75 | + BN_bn2bin(bn, p); | ||
| 76 | + | ||
| 77 | + *bin = p; | ||
| 78 | + *bin_len = len; | ||
| 79 | + | ||
| 80 | + return 0; | ||
| 81 | +} | ||
| 82 | + | ||
| 83 | +inline int spcf_bn2bin_ex(BIGNUM *bn, unsigned char **bin, int *bin_len) | ||
| 84 | +{ | ||
| 85 | + int len; | ||
| 86 | + unsigned char *p; | ||
| 87 | + | ||
| 88 | + len = BN_num_bytes(bn); | ||
| 89 | + | ||
| 90 | + if (!len) | ||
| 91 | + return -1; | ||
| 92 | + | ||
| 93 | + if (len < *bin_len) | ||
| 94 | + p = malloc(*bin_len); | ||
| 95 | + else | ||
| 96 | + p = malloc(len); | ||
| 97 | + | ||
| 98 | + if (!p) | ||
| 99 | + return -ENOMEM; | ||
| 100 | + | ||
| 101 | + if (len < *bin_len) { | ||
| 102 | + /* place padding */ | ||
| 103 | + memset(p, 0, (*bin_len - len)); | ||
| 104 | + BN_bn2bin(bn, p + (*bin_len - len)); | ||
| 105 | + } else { | ||
| 106 | + BN_bn2bin(bn, p); | ||
| 107 | + } | ||
| 108 | + | ||
| 109 | + *bin = p; | ||
| 110 | + if (len >= *bin_len) | ||
| 111 | + *bin_len = len; | ||
| 112 | + | ||
| 113 | + return 0; | ||
| 114 | +} | ||
| 115 | + | ||
| 116 | +/** | ||
| 117 | + * Convert an ECC F2m 'b' parameter into the 'c' parameter. | ||
| 118 | + *Inputs: | ||
| 119 | + * q, the curve's modulus | ||
| 120 | + * b, the curve's b parameter | ||
| 121 | + * (a bignum for b, a buffer for c) | ||
| 122 | + * Output: | ||
| 123 | + * c, written into bin, right-adjusted to fill q_len bytes. | ||
| 124 | + */ | ||
| 125 | +static int | ||
| 126 | +eng_ec_compute_cparam(const BIGNUM *b, const BIGNUM *q, | ||
| 127 | + unsigned char **bin, int *bin_len) | ||
| 128 | +{ | ||
| 129 | + BIGNUM *c = BN_new(); | ||
| 130 | + BIGNUM *exp = BN_new(); | ||
| 131 | + BN_CTX *ctx = BN_CTX_new(); | ||
| 132 | + int m = BN_num_bits(q) - 1; | ||
| 133 | + int ok = 0; | ||
| 134 | + | ||
| 135 | + if (!c || !exp || !ctx || *bin) | ||
| 136 | + goto err; | ||
| 137 | + | ||
| 138 | + /* | ||
| 139 | + * We have to compute c, where b = c^4, i.e., the fourth root of b. | ||
| 140 | + * The equation for c is c = b^(2^(m-2)) | ||
| 141 | + * Compute exp = 2^(m-2) | ||
| 142 | + * (1 << x) == 2^x | ||
| 143 | + * and then compute c = b^exp | ||
| 144 | + */ | ||
| 145 | + BN_lshift(exp, BN_value_one(), m - 2); | ||
| 146 | + BN_GF2m_mod_exp(c, b, exp, q, ctx); | ||
| 147 | + /* Store c */ | ||
| 148 | + spcf_bn2bin_ex(c, bin, bin_len); | ||
| 149 | + ok = 1; | ||
| 150 | + err: | ||
| 151 | + if (ctx) | ||
| 152 | + BN_CTX_free(ctx); | ||
| 153 | + if (c) | ||
| 154 | + BN_free(c); | ||
| 155 | + if (exp) | ||
| 156 | + BN_free(exp); | ||
| 157 | + return ok; | ||
| 158 | +} | ||
| 159 | + | ||
| 160 | static const ENGINE_CMD_DEFN cryptodev_defns[] = { | ||
| 161 | {0, NULL, NULL, 0} | ||
| 162 | }; | ||
| 163 | @@ -1225,7 +1319,6 @@ cryptodev_engine_digests(ENGINE *e, const EVP_MD **digest, | ||
| 164 | */ | ||
| 165 | static int bn2crparam(const BIGNUM *a, struct crparam *crp) | ||
| 166 | { | ||
| 167 | - int i, j, k; | ||
| 168 | ssize_t bytes, bits; | ||
| 169 | u_char *b; | ||
| 170 | |||
| 171 | @@ -1243,36 +1336,21 @@ static int bn2crparam(const BIGNUM *a, struct crparam *crp) | ||
| 172 | crp->crp_p = (caddr_t) b; | ||
| 173 | crp->crp_nbits = bits; | ||
| 174 | |||
| 175 | - for (i = 0, j = 0; i < a->top; i++) { | ||
| 176 | - for (k = 0; k < BN_BITS2 / 8; k++) { | ||
| 177 | - if ((j + k) >= bytes) | ||
| 178 | - return (0); | ||
| 179 | - b[j + k] = a->d[i] >> (k * 8); | ||
| 180 | - } | ||
| 181 | - j += BN_BITS2 / 8; | ||
| 182 | - } | ||
| 183 | + BN_bn2bin(a, crp->crp_p); | ||
| 184 | return (0); | ||
| 185 | } | ||
| 186 | |||
| 187 | /* Convert a /dev/crypto parameter to a BIGNUM */ | ||
| 188 | static int crparam2bn(struct crparam *crp, BIGNUM *a) | ||
| 189 | { | ||
| 190 | - u_int8_t *pd; | ||
| 191 | - int i, bytes; | ||
| 192 | + int bytes; | ||
| 193 | |||
| 194 | bytes = (crp->crp_nbits + 7) / 8; | ||
| 195 | |||
| 196 | if (bytes == 0) | ||
| 197 | return (-1); | ||
| 198 | |||
| 199 | - if ((pd = (u_int8_t *) malloc(bytes)) == NULL) | ||
| 200 | - return (-1); | ||
| 201 | - | ||
| 202 | - for (i = 0; i < bytes; i++) | ||
| 203 | - pd[i] = crp->crp_p[bytes - i - 1]; | ||
| 204 | - | ||
| 205 | - BN_bin2bn(pd, bytes, a); | ||
| 206 | - free(pd); | ||
| 207 | + BN_bin2bn(crp->crp_p, bytes, a); | ||
| 208 | |||
| 209 | return (0); | ||
| 210 | } | ||
| 211 | @@ -1321,6 +1399,32 @@ cryptodev_asym(struct crypt_kop *kop, int rlen, BIGNUM *r, int slen, | ||
| 212 | return (ret); | ||
| 213 | } | ||
| 214 | |||
| 215 | +/* Close an opened instance of cryptodev engine */ | ||
| 216 | +void cryptodev_close_instance(void *handle) | ||
| 217 | +{ | ||
| 218 | + int fd; | ||
| 219 | + | ||
| 220 | + if (handle) { | ||
| 221 | + fd = *(int *)handle; | ||
| 222 | + close(fd); | ||
| 223 | + free(handle); | ||
| 224 | + } | ||
| 225 | +} | ||
| 226 | + | ||
| 227 | +/* Create an instance of cryptodev for asynchronous interface */ | ||
| 228 | +void *cryptodev_init_instance(void) | ||
| 229 | +{ | ||
| 230 | + int *fd = malloc(sizeof(int)); | ||
| 231 | + | ||
| 232 | + if (fd) { | ||
| 233 | + if ((*fd = open("/dev/crypto", O_RDWR, 0)) == -1) { | ||
| 234 | + free(fd); | ||
| 235 | + return NULL; | ||
| 236 | + } | ||
| 237 | + } | ||
| 238 | + return fd; | ||
| 239 | +} | ||
| 240 | + | ||
| 241 | static int | ||
| 242 | cryptodev_bn_mod_exp(BIGNUM *r, const BIGNUM *a, const BIGNUM *p, | ||
| 243 | const BIGNUM *m, BN_CTX *ctx, BN_MONT_CTX *in_mont) | ||
| 244 | @@ -1337,8 +1441,9 @@ cryptodev_bn_mod_exp(BIGNUM *r, const BIGNUM *a, const BIGNUM *p, | ||
| 245 | return (ret); | ||
| 246 | } | ||
| 247 | |||
| 248 | - memset(&kop, 0, sizeof kop); | ||
| 249 | kop.crk_op = CRK_MOD_EXP; | ||
| 250 | + kop.crk_oparams = 0; | ||
| 251 | + kop.crk_status = 0; | ||
| 252 | |||
| 253 | /* inputs: a^p % m */ | ||
| 254 | if (bn2crparam(a, &kop.crk_param[0])) | ||
| 255 | @@ -1381,28 +1486,39 @@ static int | ||
| 256 | cryptodev_rsa_mod_exp(BIGNUM *r0, const BIGNUM *I, RSA *rsa, BN_CTX *ctx) | ||
| 257 | { | ||
| 258 | struct crypt_kop kop; | ||
| 259 | - int ret = 1; | ||
| 260 | + int ret = 1, f_len, p_len, q_len; | ||
| 261 | + unsigned char *f = NULL, *p = NULL, *q = NULL, *dp = NULL, *dq = | ||
| 262 | + NULL, *c = NULL; | ||
| 263 | |||
| 264 | if (!rsa->p || !rsa->q || !rsa->dmp1 || !rsa->dmq1 || !rsa->iqmp) { | ||
| 265 | /* XXX 0 means failure?? */ | ||
| 266 | return (0); | ||
| 267 | } | ||
| 268 | |||
| 269 | - memset(&kop, 0, sizeof kop); | ||
| 270 | + kop.crk_oparams = 0; | ||
| 271 | + kop.crk_status = 0; | ||
| 272 | kop.crk_op = CRK_MOD_EXP_CRT; | ||
| 273 | + f_len = BN_num_bytes(rsa->n); | ||
| 274 | + spcf_bn2bin_ex(I, &f, &f_len); | ||
| 275 | + spcf_bn2bin(rsa->p, &p, &p_len); | ||
| 276 | + spcf_bn2bin(rsa->q, &q, &q_len); | ||
| 277 | + spcf_bn2bin_ex(rsa->dmp1, &dp, &p_len); | ||
| 278 | + spcf_bn2bin_ex(rsa->iqmp, &c, &p_len); | ||
| 279 | + spcf_bn2bin_ex(rsa->dmq1, &dq, &q_len); | ||
| 280 | /* inputs: rsa->p rsa->q I rsa->dmp1 rsa->dmq1 rsa->iqmp */ | ||
| 281 | - if (bn2crparam(rsa->p, &kop.crk_param[0])) | ||
| 282 | - goto err; | ||
| 283 | - if (bn2crparam(rsa->q, &kop.crk_param[1])) | ||
| 284 | - goto err; | ||
| 285 | - if (bn2crparam(I, &kop.crk_param[2])) | ||
| 286 | - goto err; | ||
| 287 | - if (bn2crparam(rsa->dmp1, &kop.crk_param[3])) | ||
| 288 | - goto err; | ||
| 289 | - if (bn2crparam(rsa->dmq1, &kop.crk_param[4])) | ||
| 290 | - goto err; | ||
| 291 | - if (bn2crparam(rsa->iqmp, &kop.crk_param[5])) | ||
| 292 | - goto err; | ||
| 293 | + kop.crk_param[0].crp_p = p; | ||
| 294 | + kop.crk_param[0].crp_nbits = p_len * 8; | ||
| 295 | + kop.crk_param[1].crp_p = q; | ||
| 296 | + kop.crk_param[1].crp_nbits = q_len * 8; | ||
| 297 | + kop.crk_param[2].crp_p = f; | ||
| 298 | + kop.crk_param[2].crp_nbits = f_len * 8; | ||
| 299 | + kop.crk_param[3].crp_p = dp; | ||
| 300 | + kop.crk_param[3].crp_nbits = p_len * 8; | ||
| 301 | + /* dq must of length q, rest all of length p */ | ||
| 302 | + kop.crk_param[4].crp_p = dq; | ||
| 303 | + kop.crk_param[4].crp_nbits = q_len * 8; | ||
| 304 | + kop.crk_param[5].crp_p = c; | ||
| 305 | + kop.crk_param[5].crp_nbits = p_len * 8; | ||
| 306 | kop.crk_iparams = 6; | ||
| 307 | |||
| 308 | if (cryptodev_asym(&kop, BN_num_bytes(rsa->n), r0, 0, NULL)) { | ||
| 309 | @@ -1438,93 +1554,120 @@ static RSA_METHOD cryptodev_rsa = { | ||
| 310 | NULL /* rsa_verify */ | ||
| 311 | }; | ||
| 312 | |||
| 313 | -static int | ||
| 314 | -cryptodev_dsa_bn_mod_exp(DSA *dsa, BIGNUM *r, BIGNUM *a, const BIGNUM *p, | ||
| 315 | - const BIGNUM *m, BN_CTX *ctx, BN_MONT_CTX *m_ctx) | ||
| 316 | -{ | ||
| 317 | - return (cryptodev_bn_mod_exp(r, a, p, m, ctx, m_ctx)); | ||
| 318 | -} | ||
| 319 | - | ||
| 320 | -static int | ||
| 321 | -cryptodev_dsa_dsa_mod_exp(DSA *dsa, BIGNUM *t1, BIGNUM *g, | ||
| 322 | - BIGNUM *u1, BIGNUM *pub_key, BIGNUM *u2, BIGNUM *p, | ||
| 323 | - BN_CTX *ctx, BN_MONT_CTX *mont) | ||
| 324 | +static DSA_SIG *cryptodev_dsa_do_sign(const unsigned char *dgst, int dlen, | ||
| 325 | + DSA *dsa) | ||
| 326 | { | ||
| 327 | - BIGNUM t2; | ||
| 328 | - int ret = 0; | ||
| 329 | - | ||
| 330 | - BN_init(&t2); | ||
| 331 | - | ||
| 332 | - /* v = ( g^u1 * y^u2 mod p ) mod q */ | ||
| 333 | - /* let t1 = g ^ u1 mod p */ | ||
| 334 | - ret = 0; | ||
| 335 | + struct crypt_kop kop; | ||
| 336 | + BIGNUM *c = NULL, *d = NULL; | ||
| 337 | + DSA_SIG *dsaret = NULL; | ||
| 338 | + int q_len = 0, r_len = 0, g_len = 0; | ||
| 339 | + int priv_key_len = 0, ret; | ||
| 340 | + unsigned char *q = NULL, *r = NULL, *g = NULL, *priv_key = NULL, *f = | ||
| 341 | + NULL; | ||
| 342 | |||
| 343 | - if (!dsa->meth->bn_mod_exp(dsa, t1, dsa->g, u1, dsa->p, ctx, mont)) | ||
| 344 | + memset(&kop, 0, sizeof kop); | ||
| 345 | + if ((c = BN_new()) == NULL) { | ||
| 346 | + DSAerr(DSA_F_DSA_DO_SIGN, ERR_R_MALLOC_FAILURE); | ||
| 347 | goto err; | ||
| 348 | + } | ||
| 349 | |||
| 350 | - /* let t2 = y ^ u2 mod p */ | ||
| 351 | - if (!dsa->meth->bn_mod_exp(dsa, &t2, dsa->pub_key, u2, dsa->p, ctx, mont)) | ||
| 352 | + if ((d = BN_new()) == NULL) { | ||
| 353 | + BN_free(c); | ||
| 354 | + DSAerr(DSA_F_DSA_DO_SIGN, ERR_R_MALLOC_FAILURE); | ||
| 355 | goto err; | ||
| 356 | - /* let u1 = t1 * t2 mod p */ | ||
| 357 | - if (!BN_mod_mul(u1, t1, &t2, dsa->p, ctx)) | ||
| 358 | + } | ||
| 359 | + | ||
| 360 | + if (spcf_bn2bin(dsa->p, &q, &q_len)) { | ||
| 361 | + DSAerr(DSA_F_DSA_DO_SIGN, DSA_R_DATA_TOO_LARGE_FOR_KEY_SIZE); | ||
| 362 | goto err; | ||
| 363 | + } | ||
| 364 | |||
| 365 | - BN_copy(t1, u1); | ||
| 366 | + /* Get order of the field of private keys into plain buffer */ | ||
| 367 | + if (spcf_bn2bin(dsa->q, &r, &r_len)) { | ||
| 368 | + DSAerr(DSA_F_DSA_DO_SIGN, ERR_R_MALLOC_FAILURE); | ||
| 369 | + goto err; | ||
| 370 | + } | ||
| 371 | |||
| 372 | - ret = 1; | ||
| 373 | - err: | ||
| 374 | - BN_free(&t2); | ||
| 375 | - return (ret); | ||
| 376 | -} | ||
| 377 | + /* sanity test */ | ||
| 378 | + if (dlen > r_len) { | ||
| 379 | + DSAerr(DSA_F_DSA_DO_SIGN, DSA_R_DATA_TOO_LARGE_FOR_KEY_SIZE); | ||
| 380 | + goto err; | ||
| 381 | + } | ||
| 382 | |||
| 383 | -static DSA_SIG *cryptodev_dsa_do_sign(const unsigned char *dgst, int dlen, | ||
| 384 | - DSA *dsa) | ||
| 385 | -{ | ||
| 386 | - struct crypt_kop kop; | ||
| 387 | - BIGNUM *r = NULL, *s = NULL; | ||
| 388 | - DSA_SIG *dsaret = NULL; | ||
| 389 | + g_len = q_len; | ||
| 390 | + /** | ||
| 391 | + * Get generator into a plain buffer. If length is less than | ||
| 392 | + * q_len then add leading padding bytes. | ||
| 393 | + */ | ||
| 394 | + if (spcf_bn2bin_ex(dsa->g, &g, &g_len)) { | ||
| 395 | + DSAerr(DSA_F_DSA_DO_SIGN, ERR_R_MALLOC_FAILURE); | ||
| 396 | + goto err; | ||
| 397 | + } | ||
| 398 | |||
| 399 | - if ((r = BN_new()) == NULL) | ||
| 400 | + priv_key_len = r_len; | ||
| 401 | + /** | ||
| 402 | + * Get private key into a plain buffer. If length is less than | ||
| 403 | + * r_len then add leading padding bytes. | ||
| 404 | + */ | ||
| 405 | + if (spcf_bn2bin_ex(dsa->priv_key, &priv_key, &priv_key_len)) { | ||
| 406 | + DSAerr(DSA_F_DSA_DO_SIGN, ERR_R_MALLOC_FAILURE); | ||
| 407 | goto err; | ||
| 408 | - if ((s = BN_new()) == NULL) { | ||
| 409 | - BN_free(r); | ||
| 410 | + } | ||
| 411 | + | ||
| 412 | + /* Allocate memory to store hash. */ | ||
| 413 | + f = OPENSSL_malloc(r_len); | ||
| 414 | + if (!f) { | ||
| 415 | + DSAerr(DSA_F_DSA_DO_SIGN, ERR_R_MALLOC_FAILURE); | ||
| 416 | goto err; | ||
| 417 | } | ||
| 418 | |||
| 419 | - memset(&kop, 0, sizeof kop); | ||
| 420 | + /* Add padding, since SEC expects hash to of size r_len */ | ||
| 421 | + if (dlen < r_len) | ||
| 422 | + memset(f, 0, r_len - dlen); | ||
| 423 | + | ||
| 424 | + /* Skip leading bytes if dgst_len < r_len */ | ||
| 425 | + memcpy(f + r_len - dlen, dgst, dlen); | ||
| 426 | + | ||
| 427 | kop.crk_op = CRK_DSA_SIGN; | ||
| 428 | |||
| 429 | /* inputs: dgst dsa->p dsa->q dsa->g dsa->priv_key */ | ||
| 430 | - kop.crk_param[0].crp_p = (caddr_t) dgst; | ||
| 431 | - kop.crk_param[0].crp_nbits = dlen * 8; | ||
| 432 | - if (bn2crparam(dsa->p, &kop.crk_param[1])) | ||
| 433 | - goto err; | ||
| 434 | - if (bn2crparam(dsa->q, &kop.crk_param[2])) | ||
| 435 | - goto err; | ||
| 436 | - if (bn2crparam(dsa->g, &kop.crk_param[3])) | ||
| 437 | + kop.crk_param[0].crp_p = (void *)f; | ||
| 438 | + kop.crk_param[0].crp_nbits = r_len * 8; | ||
| 439 | + kop.crk_param[1].crp_p = (void *)q; | ||
| 440 | + kop.crk_param[1].crp_nbits = q_len * 8; | ||
| 441 | + kop.crk_param[2].crp_p = (void *)r; | ||
| 442 | + kop.crk_param[2].crp_nbits = r_len * 8; | ||
| 443 | + kop.crk_param[3].crp_p = (void *)g; | ||
| 444 | + kop.crk_param[3].crp_nbits = g_len * 8; | ||
| 445 | + kop.crk_param[4].crp_p = (void *)priv_key; | ||
| 446 | + kop.crk_param[4].crp_nbits = priv_key_len * 8; | ||
| 447 | + kop.crk_iparams = 5; | ||
| 448 | + | ||
| 449 | + ret = cryptodev_asym(&kop, r_len, c, r_len, d); | ||
| 450 | + | ||
| 451 | + if (ret) { | ||
| 452 | + DSAerr(DSA_F_DSA_DO_SIGN, DSA_R_DECODE_ERROR); | ||
| 453 | goto err; | ||
| 454 | - if (bn2crparam(dsa->priv_key, &kop.crk_param[4])) | ||
| 455 | + } | ||
| 456 | + | ||
| 457 | + dsaret = DSA_SIG_new(); | ||
| 458 | + if (dsaret == NULL) | ||
| 459 | goto err; | ||
| 460 | - kop.crk_iparams = 5; | ||
| 461 | + dsaret->r = c; | ||
| 462 | + dsaret->s = d; | ||
| 463 | |||
| 464 | - if (cryptodev_asym(&kop, BN_num_bytes(dsa->q), r, | ||
| 465 | - BN_num_bytes(dsa->q), s) == 0) { | ||
| 466 | - dsaret = DSA_SIG_new(); | ||
| 467 | - if (dsaret == NULL) | ||
| 468 | - goto err; | ||
| 469 | - dsaret->r = r; | ||
| 470 | - dsaret->s = s; | ||
| 471 | - r = s = NULL; | ||
| 472 | - } else { | ||
| 473 | + zapparams(&kop); | ||
| 474 | + return (dsaret); | ||
| 475 | + err: | ||
| 476 | + { | ||
| 477 | const DSA_METHOD *meth = DSA_OpenSSL(); | ||
| 478 | + if (c) | ||
| 479 | + BN_free(c); | ||
| 480 | + if (d) | ||
| 481 | + BN_free(d); | ||
| 482 | dsaret = (meth->dsa_do_sign) (dgst, dlen, dsa); | ||
| 483 | + return (dsaret); | ||
| 484 | } | ||
| 485 | - err: | ||
| 486 | - BN_free(r); | ||
| 487 | - BN_free(s); | ||
| 488 | - kop.crk_param[0].crp_p = NULL; | ||
| 489 | - zapparams(&kop); | ||
| 490 | - return (dsaret); | ||
| 491 | } | ||
| 492 | |||
| 493 | static int | ||
| 494 | @@ -1532,43 +1675,175 @@ cryptodev_dsa_verify(const unsigned char *dgst, int dlen, | ||
| 495 | DSA_SIG *sig, DSA *dsa) | ||
| 496 | { | ||
| 497 | struct crypt_kop kop; | ||
| 498 | - int dsaret = 1; | ||
| 499 | + int dsaret = 1, q_len = 0, r_len = 0, g_len = 0; | ||
| 500 | + int w_len = 0, c_len = 0, d_len = 0, ret = -1; | ||
| 501 | + unsigned char *q = NULL, *r = NULL, *w = NULL, *g = NULL; | ||
| 502 | + unsigned char *c = NULL, *d = NULL, *f = NULL; | ||
| 503 | |||
| 504 | memset(&kop, 0, sizeof kop); | ||
| 505 | kop.crk_op = CRK_DSA_VERIFY; | ||
| 506 | |||
| 507 | - /* inputs: dgst dsa->p dsa->q dsa->g dsa->pub_key sig->r sig->s */ | ||
| 508 | - kop.crk_param[0].crp_p = (caddr_t) dgst; | ||
| 509 | - kop.crk_param[0].crp_nbits = dlen * 8; | ||
| 510 | - if (bn2crparam(dsa->p, &kop.crk_param[1])) | ||
| 511 | + if (spcf_bn2bin(dsa->p, &q, &q_len)) { | ||
| 512 | + DSAerr(DSA_F_DSA_DO_VERIFY, ERR_R_MALLOC_FAILURE); | ||
| 513 | + return ret; | ||
| 514 | + } | ||
| 515 | + | ||
| 516 | + /* Get Order of field of private keys */ | ||
| 517 | + if (spcf_bn2bin(dsa->q, &r, &r_len)) { | ||
| 518 | + DSAerr(DSA_F_DSA_DO_VERIFY, ERR_R_MALLOC_FAILURE); | ||
| 519 | + goto err; | ||
| 520 | + } | ||
| 521 | + | ||
| 522 | + g_len = q_len; | ||
| 523 | + /** | ||
| 524 | + * Get generator into a plain buffer. If length is less than | ||
| 525 | + * q_len then add leading padding bytes. | ||
| 526 | + */ | ||
| 527 | + if (spcf_bn2bin_ex(dsa->g, &g, &g_len)) { | ||
| 528 | + DSAerr(DSA_F_DSA_DO_VERIFY, ERR_R_MALLOC_FAILURE); | ||
| 529 | goto err; | ||
| 530 | - if (bn2crparam(dsa->q, &kop.crk_param[2])) | ||
| 531 | + } | ||
| 532 | + w_len = q_len; | ||
| 533 | + /** | ||
| 534 | + * Get public key into a plain buffer. If length is less than | ||
| 535 | + * q_len then add leading padding bytes. | ||
| 536 | + */ | ||
| 537 | + if (spcf_bn2bin_ex(dsa->pub_key, &w, &w_len)) { | ||
| 538 | + DSAerr(DSA_F_DSA_DO_VERIFY, ERR_R_MALLOC_FAILURE); | ||
| 539 | goto err; | ||
| 540 | - if (bn2crparam(dsa->g, &kop.crk_param[3])) | ||
| 541 | + } | ||
| 542 | + /** | ||
| 543 | + * Get the 1st part of signature into a flat buffer with | ||
| 544 | + * appropriate padding | ||
| 545 | + */ | ||
| 546 | + c_len = r_len; | ||
| 547 | + | ||
| 548 | + if (spcf_bn2bin_ex(sig->r, &c, &c_len)) { | ||
| 549 | + ECDSAerr(ECDSA_F_ECDSA_DO_VERIFY, ERR_R_MALLOC_FAILURE); | ||
| 550 | goto err; | ||
| 551 | - if (bn2crparam(dsa->pub_key, &kop.crk_param[4])) | ||
| 552 | + } | ||
| 553 | + | ||
| 554 | + /** | ||
| 555 | + * Get the 2nd part of signature into a flat buffer with | ||
| 556 | + * appropriate padding | ||
| 557 | + */ | ||
| 558 | + d_len = r_len; | ||
| 559 | + | ||
| 560 | + if (spcf_bn2bin_ex(sig->s, &d, &d_len)) { | ||
| 561 | + ECDSAerr(ECDSA_F_ECDSA_DO_VERIFY, ERR_R_MALLOC_FAILURE); | ||
| 562 | goto err; | ||
| 563 | - if (bn2crparam(sig->r, &kop.crk_param[5])) | ||
| 564 | + } | ||
| 565 | + | ||
| 566 | + /* Sanity test */ | ||
| 567 | + if (dlen > r_len) { | ||
| 568 | + ECDSAerr(ECDSA_F_ECDSA_DO_VERIFY, ERR_R_MALLOC_FAILURE); | ||
| 569 | goto err; | ||
| 570 | - if (bn2crparam(sig->s, &kop.crk_param[6])) | ||
| 571 | + } | ||
| 572 | + | ||
| 573 | + /* Allocate memory to store hash. */ | ||
| 574 | + f = OPENSSL_malloc(r_len); | ||
| 575 | + if (!f) { | ||
| 576 | + DSAerr(ECDSA_F_ECDSA_DO_VERIFY, ERR_R_MALLOC_FAILURE); | ||
| 577 | goto err; | ||
| 578 | + } | ||
| 579 | + | ||
| 580 | + /* Add padding, since SEC expects hash to of size r_len */ | ||
| 581 | + if (dlen < r_len) | ||
| 582 | + memset(f, 0, r_len - dlen); | ||
| 583 | + | ||
| 584 | + /* Skip leading bytes if dgst_len < r_len */ | ||
| 585 | + memcpy(f + r_len - dlen, dgst, dlen); | ||
| 586 | + | ||
| 587 | + /* inputs: dgst dsa->p dsa->q dsa->g dsa->pub_key sig->r sig->s */ | ||
| 588 | + kop.crk_param[0].crp_p = (void *)f; | ||
| 589 | + kop.crk_param[0].crp_nbits = r_len * 8; | ||
| 590 | + kop.crk_param[1].crp_p = q; | ||
| 591 | + kop.crk_param[1].crp_nbits = q_len * 8; | ||
| 592 | + kop.crk_param[2].crp_p = r; | ||
| 593 | + kop.crk_param[2].crp_nbits = r_len * 8; | ||
| 594 | + kop.crk_param[3].crp_p = g; | ||
| 595 | + kop.crk_param[3].crp_nbits = g_len * 8; | ||
| 596 | + kop.crk_param[4].crp_p = w; | ||
| 597 | + kop.crk_param[4].crp_nbits = w_len * 8; | ||
| 598 | + kop.crk_param[5].crp_p = c; | ||
| 599 | + kop.crk_param[5].crp_nbits = c_len * 8; | ||
| 600 | + kop.crk_param[6].crp_p = d; | ||
| 601 | + kop.crk_param[6].crp_nbits = d_len * 8; | ||
| 602 | kop.crk_iparams = 7; | ||
| 603 | |||
| 604 | - if (cryptodev_asym(&kop, 0, NULL, 0, NULL) == 0) { | ||
| 605 | - /* | ||
| 606 | - * OCF success value is 0, if not zero, change dsaret to fail | ||
| 607 | - */ | ||
| 608 | - if (0 != kop.crk_status) | ||
| 609 | - dsaret = 0; | ||
| 610 | - } else { | ||
| 611 | - const DSA_METHOD *meth = DSA_OpenSSL(); | ||
| 612 | + if ((cryptodev_asym(&kop, 0, NULL, 0, NULL))) { | ||
| 613 | + ECDSAerr(ECDSA_F_ECDSA_DO_VERIFY, DSA_R_DECODE_ERROR); | ||
| 614 | + goto err; | ||
| 615 | + } | ||
| 616 | |||
| 617 | - dsaret = (meth->dsa_do_verify) (dgst, dlen, sig, dsa); | ||
| 618 | + /* | ||
| 619 | + * OCF success value is 0, if not zero, change dsaret to fail | ||
| 620 | + */ | ||
| 621 | + if (0 != kop.crk_status) { | ||
| 622 | + ECDSAerr(ECDSA_F_ECDSA_DO_VERIFY, DSA_R_DECODE_ERROR); | ||
| 623 | + goto err; | ||
| 624 | } | ||
| 625 | - err: | ||
| 626 | - kop.crk_param[0].crp_p = NULL; | ||
| 627 | + | ||
| 628 | zapparams(&kop); | ||
| 629 | return (dsaret); | ||
| 630 | + err: | ||
| 631 | + { | ||
| 632 | + const DSA_METHOD *meth = DSA_OpenSSL(); | ||
| 633 | + dsaret = (meth->dsa_do_verify) (dgst, dlen, sig, dsa); | ||
| 634 | + return dsaret; | ||
| 635 | + } | ||
| 636 | +} | ||
| 637 | + | ||
| 638 | +/* Cryptodev DSA Key Gen routine */ | ||
| 639 | +static int cryptodev_dsa_keygen(DSA *dsa) | ||
| 640 | +{ | ||
| 641 | + struct crypt_kop kop; | ||
| 642 | + int ret = 1, g_len; | ||
| 643 | + unsigned char *g = NULL; | ||
| 644 | + | ||
| 645 | + if (dsa->priv_key == NULL) { | ||
| 646 | + if ((dsa->priv_key = BN_new()) == NULL) | ||
| 647 | + goto sw_try; | ||
| 648 | + } | ||
| 649 | + | ||
| 650 | + if (dsa->pub_key == NULL) { | ||
| 651 | + if ((dsa->pub_key = BN_new()) == NULL) | ||
| 652 | + goto sw_try; | ||
| 653 | + } | ||
| 654 | + | ||
| 655 | + g_len = BN_num_bytes(dsa->p); | ||
| 656 | + /** | ||
| 657 | + * Get generator into a plain buffer. If length is less than | ||
| 658 | + * p_len then add leading padding bytes. | ||
| 659 | + */ | ||
| 660 | + if (spcf_bn2bin_ex(dsa->g, &g, &g_len)) { | ||
| 661 | + DSAerr(DSA_F_DSA_GENERATE_KEY, ERR_R_MALLOC_FAILURE); | ||
| 662 | + goto sw_try; | ||
| 663 | + } | ||
| 664 | + | ||
| 665 | + memset(&kop, 0, sizeof kop); | ||
| 666 | + | ||
| 667 | + kop.crk_op = CRK_DSA_GENERATE_KEY; | ||
| 668 | + if (bn2crparam(dsa->p, &kop.crk_param[0])) | ||
| 669 | + goto sw_try; | ||
| 670 | + if (bn2crparam(dsa->q, &kop.crk_param[1])) | ||
| 671 | + goto sw_try; | ||
| 672 | + kop.crk_param[2].crp_p = g; | ||
| 673 | + kop.crk_param[2].crp_nbits = g_len * 8; | ||
| 674 | + kop.crk_iparams = 3; | ||
| 675 | + | ||
| 676 | + /* pub_key is or prime length while priv key is of length of order */ | ||
| 677 | + if (cryptodev_asym(&kop, BN_num_bytes(dsa->p), dsa->pub_key, | ||
| 678 | + BN_num_bytes(dsa->q), dsa->priv_key)) | ||
| 679 | + goto sw_try; | ||
| 680 | + | ||
| 681 | + return ret; | ||
| 682 | + sw_try: | ||
| 683 | + { | ||
| 684 | + const DSA_METHOD *meth = DSA_OpenSSL(); | ||
| 685 | + ret = (meth->dsa_keygen) (dsa); | ||
| 686 | + } | ||
| 687 | + return ret; | ||
| 688 | } | ||
| 689 | |||
| 690 | static DSA_METHOD cryptodev_dsa = { | ||
| 691 | @@ -1584,12 +1859,558 @@ static DSA_METHOD cryptodev_dsa = { | ||
| 692 | NULL /* app_data */ | ||
| 693 | }; | ||
| 694 | |||
| 695 | -static int | ||
| 696 | -cryptodev_mod_exp_dh(const DH *dh, BIGNUM *r, const BIGNUM *a, | ||
| 697 | - const BIGNUM *p, const BIGNUM *m, BN_CTX *ctx, | ||
| 698 | - BN_MONT_CTX *m_ctx) | ||
| 699 | +static ECDSA_METHOD cryptodev_ecdsa = { | ||
| 700 | + "cryptodev ECDSA method", | ||
| 701 | + NULL, | ||
| 702 | + NULL, /* ecdsa_sign_setup */ | ||
| 703 | + NULL, | ||
| 704 | + NULL, | ||
| 705 | + 0, /* flags */ | ||
| 706 | + NULL /* app_data */ | ||
| 707 | +}; | ||
| 708 | + | ||
| 709 | +typedef enum ec_curve_s { | ||
| 710 | + EC_PRIME, | ||
| 711 | + EC_BINARY | ||
| 712 | +} ec_curve_t; | ||
| 713 | + | ||
| 714 | +/* ENGINE handler for ECDSA Sign */ | ||
| 715 | +static ECDSA_SIG *cryptodev_ecdsa_do_sign(const unsigned char *dgst, | ||
| 716 | + int dgst_len, const BIGNUM *in_kinv, | ||
| 717 | + const BIGNUM *in_r, EC_KEY *eckey) | ||
| 718 | { | ||
| 719 | - return (cryptodev_bn_mod_exp(r, a, p, m, ctx, m_ctx)); | ||
| 720 | + BIGNUM *m = NULL, *p = NULL, *a = NULL; | ||
| 721 | + BIGNUM *b = NULL, *x = NULL, *y = NULL; | ||
| 722 | + BN_CTX *ctx = NULL; | ||
| 723 | + ECDSA_SIG *ret = NULL; | ||
| 724 | + ECDSA_DATA *ecdsa = NULL; | ||
| 725 | + unsigned char *q = NULL, *r = NULL, *ab = NULL, *g_xy = NULL; | ||
| 726 | + unsigned char *s = NULL, *c = NULL, *d = NULL, *f = NULL, *tmp_dgst = | ||
| 727 | + NULL; | ||
| 728 | + int i = 0, q_len = 0, priv_key_len = 0, r_len = 0; | ||
| 729 | + int g_len = 0, d_len = 0, ab_len = 0; | ||
| 730 | + const BIGNUM *order = NULL, *priv_key = NULL; | ||
| 731 | + const EC_GROUP *group = NULL; | ||
| 732 | + struct crypt_kop kop; | ||
| 733 | + ec_curve_t ec_crv = EC_PRIME; | ||
| 734 | + | ||
| 735 | + memset(&kop, 0, sizeof(kop)); | ||
| 736 | + ecdsa = ecdsa_check(eckey); | ||
| 737 | + if (!ecdsa) { | ||
| 738 | + ECDSAerr(ECDSA_F_ECDSA_DO_SIGN, ERR_R_PASSED_NULL_PARAMETER); | ||
| 739 | + return NULL; | ||
| 740 | + } | ||
| 741 | + | ||
| 742 | + group = EC_KEY_get0_group(eckey); | ||
| 743 | + priv_key = EC_KEY_get0_private_key(eckey); | ||
| 744 | + | ||
| 745 | + if (!group || !priv_key) { | ||
| 746 | + ECDSAerr(ECDSA_F_ECDSA_DO_SIGN, ERR_R_PASSED_NULL_PARAMETER); | ||
| 747 | + return NULL; | ||
| 748 | + } | ||
| 749 | + | ||
| 750 | + if ((ctx = BN_CTX_new()) == NULL || (m = BN_new()) == NULL || | ||
| 751 | + (a = BN_new()) == NULL || (b = BN_new()) == NULL || | ||
| 752 | + (p = BN_new()) == NULL || (x = BN_new()) == NULL || | ||
| 753 | + (y = BN_new()) == NULL) { | ||
| 754 | + ECDSAerr(ECDSA_F_ECDSA_DO_SIGN, ERR_R_MALLOC_FAILURE); | ||
| 755 | + goto err; | ||
| 756 | + } | ||
| 757 | + | ||
| 758 | + order = &group->order; | ||
| 759 | + if (!order || BN_is_zero(order)) { | ||
| 760 | + ECDSAerr(ECDSA_F_ECDSA_DO_SIGN, ECDSA_R_MISSING_PARAMETERS); | ||
| 761 | + goto err; | ||
| 762 | + } | ||
| 763 | + | ||
| 764 | + i = BN_num_bits(order); | ||
| 765 | + /* | ||
| 766 | + * Need to truncate digest if it is too long: first truncate whole bytes | ||
| 767 | + */ | ||
| 768 | + if (8 * dgst_len > i) | ||
| 769 | + dgst_len = (i + 7) / 8; | ||
| 770 | + | ||
| 771 | + if (!BN_bin2bn(dgst, dgst_len, m)) { | ||
| 772 | + ECDSAerr(ECDSA_F_ECDSA_DO_SIGN, ERR_R_BN_LIB); | ||
| 773 | + goto err; | ||
| 774 | + } | ||
| 775 | + | ||
| 776 | + /* If still too long truncate remaining bits with a shift */ | ||
| 777 | + if ((8 * dgst_len > i) && !BN_rshift(m, m, 8 - (i & 0x7))) { | ||
| 778 | + ECDSAerr(ECDSA_F_ECDSA_DO_SIGN, ERR_R_BN_LIB); | ||
| 779 | + goto err; | ||
| 780 | + } | ||
| 781 | + | ||
| 782 | + /* copy the truncated bits into plain buffer */ | ||
| 783 | + if (spcf_bn2bin(m, &tmp_dgst, &dgst_len)) { | ||
| 784 | + fprintf(stderr, "%s:%d: OPENSSL_malloc failec\n", __FUNCTION__, | ||
| 785 | + __LINE__); | ||
| 786 | + goto err; | ||
| 787 | + } | ||
| 788 | + | ||
| 789 | + ret = ECDSA_SIG_new(); | ||
| 790 | + if (!ret) { | ||
| 791 | + ECDSAerr(ECDSA_F_ECDSA_DO_SIGN, ERR_R_BN_LIB); | ||
| 792 | + goto err; | ||
| 793 | + } | ||
| 794 | + | ||
| 795 | + /* check if this is prime or binary EC request */ | ||
| 796 | + if (EC_METHOD_get_field_type(EC_GROUP_method_of(group)) == | ||
| 797 | + NID_X9_62_prime_field) { | ||
| 798 | + ec_crv = EC_PRIME; | ||
| 799 | + /* get the generator point pair */ | ||
| 800 | + if (!EC_POINT_get_affine_coordinates_GFp | ||
| 801 | + (group, EC_GROUP_get0_generator(group), x, y, ctx)) { | ||
| 802 | + ECDSAerr(ECDSA_F_ECDSA_DO_SIGN, ERR_R_EC_LIB); | ||
| 803 | + goto err; | ||
| 804 | + } | ||
| 805 | + | ||
| 806 | + /* get the ECC curve parameters */ | ||
| 807 | + if (!EC_GROUP_get_curve_GFp(group, p, a, b, ctx)) { | ||
| 808 | + ECDSAerr(ECDSA_F_ECDSA_DO_SIGN, ERR_R_EC_LIB); | ||
| 809 | + goto err; | ||
| 810 | + } | ||
| 811 | + } else if (EC_METHOD_get_field_type(EC_GROUP_method_of(group)) == | ||
| 812 | + NID_X9_62_characteristic_two_field) { | ||
| 813 | + ec_crv = EC_BINARY; | ||
| 814 | + /* get the ECC curve parameters */ | ||
| 815 | + if (!EC_GROUP_get_curve_GF2m(group, p, a, b, ctx)) { | ||
| 816 | + ECDSAerr(ECDSA_F_ECDSA_DO_SIGN, ERR_R_EC_LIB); | ||
| 817 | + goto err; | ||
| 818 | + } | ||
| 819 | + | ||
| 820 | + /* get the generator point pair */ | ||
| 821 | + if (!EC_POINT_get_affine_coordinates_GF2m(group, | ||
| 822 | + EC_GROUP_get0_generator | ||
| 823 | + (group), x, y, ctx)) { | ||
| 824 | + ECDSAerr(ECDSA_F_ECDSA_DO_SIGN, ERR_R_EC_LIB); | ||
| 825 | + goto err; | ||
| 826 | + } | ||
| 827 | + } else { | ||
| 828 | + ECDSAerr(ECDSA_F_ECDSA_DO_SIGN, ERR_R_EC_LIB); | ||
| 829 | + goto err; | ||
| 830 | + } | ||
| 831 | + | ||
| 832 | + if (spcf_bn2bin(order, &r, &r_len)) { | ||
| 833 | + ECDSAerr(ECDSA_F_ECDSA_DO_SIGN, ERR_R_MALLOC_FAILURE); | ||
| 834 | + goto err; | ||
| 835 | + } | ||
| 836 | + | ||
| 837 | + if (spcf_bn2bin(p, &q, &q_len)) { | ||
| 838 | + ECDSAerr(ECDSA_F_ECDSA_DO_SIGN, ERR_R_MALLOC_FAILURE); | ||
| 839 | + goto err; | ||
| 840 | + } | ||
| 841 | + | ||
| 842 | + priv_key_len = r_len; | ||
| 843 | + | ||
| 844 | + /** | ||
| 845 | + * If BN_num_bytes of priv_key returns less then r_len then | ||
| 846 | + * add padding bytes before the key | ||
| 847 | + */ | ||
| 848 | + if (spcf_bn2bin_ex(priv_key, &s, &priv_key_len)) { | ||
| 849 | + ECDSAerr(ECDSA_F_ECDSA_DO_SIGN, ERR_R_MALLOC_FAILURE); | ||
| 850 | + goto err; | ||
| 851 | + } | ||
| 852 | + | ||
| 853 | + /* Generation of ECC curve parameters */ | ||
| 854 | + ab_len = 2 * q_len; | ||
| 855 | + ab = eng_copy_curve_points(a, b, ab_len, q_len); | ||
| 856 | + if (!ab) { | ||
| 857 | + ECDSAerr(ECDSA_F_ECDSA_DO_SIGN, ERR_R_MALLOC_FAILURE); | ||
| 858 | + goto err; | ||
| 859 | + } | ||
| 860 | + | ||
| 861 | + if (ec_crv == EC_BINARY) { | ||
| 862 | + if (eng_ec_get_cparam | ||
| 863 | + (EC_GROUP_get_curve_name(group), ab + q_len, q_len)) { | ||
| 864 | + unsigned char *c_temp = NULL; | ||
| 865 | + int c_temp_len = q_len; | ||
| 866 | + if (eng_ec_compute_cparam(b, p, &c_temp, &c_temp_len)) | ||
| 867 | + memcpy(ab + q_len, c_temp, q_len); | ||
| 868 | + else | ||
| 869 | + goto err; | ||
| 870 | + } | ||
| 871 | + kop.curve_type = ECC_BINARY; | ||
| 872 | + } | ||
| 873 | + | ||
| 874 | + /* Calculation of Generator point */ | ||
| 875 | + g_len = 2 * q_len; | ||
| 876 | + g_xy = eng_copy_curve_points(x, y, g_len, q_len); | ||
| 877 | + if (!g_xy) { | ||
| 878 | + ECDSAerr(ECDSA_F_ECDSA_DO_SIGN, ERR_R_MALLOC_FAILURE); | ||
| 879 | + goto err; | ||
| 880 | + } | ||
| 881 | + | ||
| 882 | + /* Memory allocation for first part of digital signature */ | ||
| 883 | + c = malloc(r_len); | ||
| 884 | + if (!c) { | ||
| 885 | + ECDSAerr(ECDSA_F_ECDSA_DO_SIGN, ERR_R_MALLOC_FAILURE); | ||
| 886 | + goto err; | ||
| 887 | + } | ||
| 888 | + | ||
| 889 | + d_len = r_len; | ||
| 890 | + | ||
| 891 | + /* Memory allocation for second part of digital signature */ | ||
| 892 | + d = malloc(d_len); | ||
| 893 | + if (!d) { | ||
| 894 | + ECDSAerr(ECDSA_F_ECDSA_DO_SIGN, ERR_R_MALLOC_FAILURE); | ||
| 895 | + goto err; | ||
| 896 | + } | ||
| 897 | + | ||
| 898 | + /* memory for message representative */ | ||
| 899 | + f = malloc(r_len); | ||
| 900 | + if (!f) { | ||
| 901 | + ECDSAerr(ECDSA_F_ECDSA_DO_SIGN, ERR_R_MALLOC_FAILURE); | ||
| 902 | + goto err; | ||
| 903 | + } | ||
| 904 | + | ||
| 905 | + /* Add padding, since SEC expects hash to of size r_len */ | ||
| 906 | + memset(f, 0, r_len - dgst_len); | ||
| 907 | + | ||
| 908 | + /* Skip leading bytes if dgst_len < r_len */ | ||
| 909 | + memcpy(f + r_len - dgst_len, tmp_dgst, dgst_len); | ||
| 910 | + | ||
| 911 | + dgst_len += r_len - dgst_len; | ||
| 912 | + kop.crk_op = CRK_DSA_SIGN; | ||
| 913 | + /* inputs: dgst dsa->p dsa->q dsa->g dsa->priv_key */ | ||
| 914 | + kop.crk_param[0].crp_p = f; | ||
| 915 | + kop.crk_param[0].crp_nbits = dgst_len * 8; | ||
| 916 | + kop.crk_param[1].crp_p = q; | ||
| 917 | + kop.crk_param[1].crp_nbits = q_len * 8; | ||
| 918 | + kop.crk_param[2].crp_p = r; | ||
| 919 | + kop.crk_param[2].crp_nbits = r_len * 8; | ||
| 920 | + kop.crk_param[3].crp_p = g_xy; | ||
| 921 | + kop.crk_param[3].crp_nbits = g_len * 8; | ||
| 922 | + kop.crk_param[4].crp_p = s; | ||
| 923 | + kop.crk_param[4].crp_nbits = priv_key_len * 8; | ||
| 924 | + kop.crk_param[5].crp_p = ab; | ||
| 925 | + kop.crk_param[5].crp_nbits = ab_len * 8; | ||
| 926 | + kop.crk_iparams = 6; | ||
| 927 | + kop.crk_param[6].crp_p = c; | ||
| 928 | + kop.crk_param[6].crp_nbits = d_len * 8; | ||
| 929 | + kop.crk_param[7].crp_p = d; | ||
| 930 | + kop.crk_param[7].crp_nbits = d_len * 8; | ||
| 931 | + kop.crk_oparams = 2; | ||
| 932 | + | ||
| 933 | + if (cryptodev_asym(&kop, 0, NULL, 0, NULL) == 0) { | ||
| 934 | + /* Check if ret->r and s needs to allocated */ | ||
| 935 | + crparam2bn(&kop.crk_param[6], ret->r); | ||
| 936 | + crparam2bn(&kop.crk_param[7], ret->s); | ||
| 937 | + } else { | ||
| 938 | + const ECDSA_METHOD *meth = ECDSA_OpenSSL(); | ||
| 939 | + ret = (meth->ecdsa_do_sign) (dgst, dgst_len, in_kinv, in_r, eckey); | ||
| 940 | + } | ||
| 941 | + kop.crk_param[0].crp_p = NULL; | ||
| 942 | + zapparams(&kop); | ||
| 943 | + err: | ||
| 944 | + if (!ret) { | ||
| 945 | + ECDSA_SIG_free(ret); | ||
| 946 | + ret = NULL; | ||
| 947 | + } | ||
| 948 | + return ret; | ||
| 949 | +} | ||
| 950 | + | ||
| 951 | +static int cryptodev_ecdsa_verify(const unsigned char *dgst, int dgst_len, | ||
| 952 | + ECDSA_SIG *sig, EC_KEY *eckey) | ||
| 953 | +{ | ||
| 954 | + BIGNUM *m = NULL, *p = NULL, *a = NULL, *b = NULL; | ||
| 955 | + BIGNUM *x = NULL, *y = NULL, *w_x = NULL, *w_y = NULL; | ||
| 956 | + BN_CTX *ctx = NULL; | ||
| 957 | + ECDSA_DATA *ecdsa = NULL; | ||
| 958 | + unsigned char *q = NULL, *r = NULL, *ab = NULL, *g_xy = NULL, *w_xy = | ||
| 959 | + NULL; | ||
| 960 | + unsigned char *c = NULL, *d = NULL, *f = NULL, *tmp_dgst = NULL; | ||
| 961 | + int i = 0, q_len = 0, pub_key_len = 0, r_len = 0, c_len = 0, g_len = 0; | ||
| 962 | + int d_len = 0, ab_len = 0, ret = -1; | ||
| 963 | + const EC_POINT *pub_key = NULL; | ||
| 964 | + const BIGNUM *order = NULL; | ||
| 965 | + const EC_GROUP *group = NULL; | ||
| 966 | + ec_curve_t ec_crv = EC_PRIME; | ||
| 967 | + struct crypt_kop kop; | ||
| 968 | + | ||
| 969 | + memset(&kop, 0, sizeof kop); | ||
| 970 | + ecdsa = ecdsa_check(eckey); | ||
| 971 | + if (!ecdsa) { | ||
| 972 | + ECDSAerr(ECDSA_F_ECDSA_DO_VERIFY, ERR_R_PASSED_NULL_PARAMETER); | ||
| 973 | + return ret; | ||
| 974 | + } | ||
| 975 | + | ||
| 976 | + group = EC_KEY_get0_group(eckey); | ||
| 977 | + pub_key = EC_KEY_get0_public_key(eckey); | ||
| 978 | + | ||
| 979 | + if (!group || !pub_key) { | ||
| 980 | + ECDSAerr(ECDSA_F_ECDSA_DO_VERIFY, ERR_R_PASSED_NULL_PARAMETER); | ||
| 981 | + return ret; | ||
| 982 | + } | ||
| 983 | + | ||
| 984 | + if ((ctx = BN_CTX_new()) == NULL || (m = BN_new()) == NULL || | ||
| 985 | + (a = BN_new()) == NULL || (b = BN_new()) == NULL || | ||
| 986 | + (p = BN_new()) == NULL || (x = BN_new()) == NULL || | ||
| 987 | + (y = BN_new()) == NULL || (w_x = BN_new()) == NULL || | ||
| 988 | + (w_y = BN_new()) == NULL) { | ||
| 989 | + ECDSAerr(ECDSA_F_ECDSA_DO_VERIFY, ERR_R_MALLOC_FAILURE); | ||
| 990 | + goto err; | ||
| 991 | + } | ||
| 992 | + | ||
| 993 | + order = &group->order; | ||
| 994 | + if (!order || BN_is_zero(order)) { | ||
| 995 | + ECDSAerr(ECDSA_F_ECDSA_DO_VERIFY, ECDSA_R_MISSING_PARAMETERS); | ||
| 996 | + goto err; | ||
| 997 | + } | ||
| 998 | + | ||
| 999 | + i = BN_num_bits(order); | ||
| 1000 | + /* | ||
| 1001 | + * Need to truncate digest if it is too long: first truncate whole * | ||
| 1002 | + * bytes | ||
| 1003 | + */ | ||
| 1004 | + if (8 * dgst_len > i) | ||
| 1005 | + dgst_len = (i + 7) / 8; | ||
| 1006 | + | ||
| 1007 | + if (!BN_bin2bn(dgst, dgst_len, m)) { | ||
| 1008 | + ECDSAerr(ECDSA_F_ECDSA_DO_VERIFY, ERR_R_BN_LIB); | ||
| 1009 | + goto err; | ||
| 1010 | + } | ||
| 1011 | + | ||
| 1012 | + /* If still too long truncate remaining bits with a shift */ | ||
| 1013 | + if ((8 * dgst_len > i) && !BN_rshift(m, m, 8 - (i & 0x7))) { | ||
| 1014 | + ECDSAerr(ECDSA_F_ECDSA_DO_VERIFY, ERR_R_BN_LIB); | ||
| 1015 | + goto err; | ||
| 1016 | + } | ||
| 1017 | + /* copy the truncated bits into plain buffer */ | ||
| 1018 | + if (spcf_bn2bin(m, &tmp_dgst, &dgst_len)) { | ||
| 1019 | + ECDSAerr(ECDSA_F_ECDSA_DO_VERIFY, ERR_R_MALLOC_FAILURE); | ||
| 1020 | + goto err; | ||
| 1021 | + } | ||
| 1022 | + | ||
| 1023 | + /* check if this is prime or binary EC request */ | ||
| 1024 | + if (EC_METHOD_get_field_type(EC_GROUP_method_of(group)) == | ||
| 1025 | + NID_X9_62_prime_field) { | ||
| 1026 | + ec_crv = EC_PRIME; | ||
| 1027 | + | ||
| 1028 | + /* get the generator point pair */ | ||
| 1029 | + if (!EC_POINT_get_affine_coordinates_GFp(group, | ||
| 1030 | + EC_GROUP_get0_generator | ||
| 1031 | + (group), x, y, ctx)) { | ||
| 1032 | + ECDSAerr(ECDSA_F_ECDSA_DO_VERIFY, ERR_R_EC_LIB); | ||
| 1033 | + goto err; | ||
| 1034 | + } | ||
| 1035 | + | ||
| 1036 | + /* get the public key pair for prime curve */ | ||
| 1037 | + if (!EC_POINT_get_affine_coordinates_GFp(group, | ||
| 1038 | + pub_key, w_x, w_y, ctx)) { | ||
| 1039 | + ECDSAerr(ECDSA_F_ECDSA_DO_VERIFY, ERR_R_EC_LIB); | ||
| 1040 | + goto err; | ||
| 1041 | + } | ||
| 1042 | + | ||
| 1043 | + /* get the ECC curve parameters */ | ||
| 1044 | + if (!EC_GROUP_get_curve_GFp(group, p, a, b, ctx)) { | ||
| 1045 | + ECDSAerr(ECDSA_F_ECDSA_DO_VERIFY, ERR_R_EC_LIB); | ||
| 1046 | + goto err; | ||
| 1047 | + } | ||
| 1048 | + } else if (EC_METHOD_get_field_type(EC_GROUP_method_of(group)) == | ||
| 1049 | + NID_X9_62_characteristic_two_field) { | ||
| 1050 | + ec_crv = EC_BINARY; | ||
| 1051 | + /* get the ECC curve parameters */ | ||
| 1052 | + if (!EC_GROUP_get_curve_GF2m(group, p, a, b, ctx)) { | ||
| 1053 | + ECDSAerr(ECDSA_F_ECDSA_DO_VERIFY, ERR_R_EC_LIB); | ||
| 1054 | + goto err; | ||
| 1055 | + } | ||
| 1056 | + | ||
| 1057 | + /* get the generator point pair */ | ||
| 1058 | + if (!EC_POINT_get_affine_coordinates_GF2m(group, | ||
| 1059 | + EC_GROUP_get0_generator | ||
| 1060 | + (group), x, y, ctx)) { | ||
| 1061 | + ECDSAerr(ECDSA_F_ECDSA_DO_VERIFY, ERR_R_EC_LIB); | ||
| 1062 | + goto err; | ||
| 1063 | + } | ||
| 1064 | + | ||
| 1065 | + /* get the public key pair for binary curve */ | ||
| 1066 | + if (!EC_POINT_get_affine_coordinates_GF2m(group, | ||
| 1067 | + pub_key, w_x, w_y, ctx)) { | ||
| 1068 | + ECDSAerr(ECDSA_F_ECDSA_DO_VERIFY, ERR_R_EC_LIB); | ||
| 1069 | + goto err; | ||
| 1070 | + } | ||
| 1071 | + } else { | ||
| 1072 | + ECDSAerr(ECDSA_F_ECDSA_DO_VERIFY, ERR_R_EC_LIB); | ||
| 1073 | + goto err; | ||
| 1074 | + } | ||
| 1075 | + | ||
| 1076 | + /* Get the order of the subgroup of private keys */ | ||
| 1077 | + if (spcf_bn2bin((BIGNUM *)order, &r, &r_len)) { | ||
| 1078 | + ECDSAerr(ECDSA_F_ECDSA_DO_VERIFY, ERR_R_MALLOC_FAILURE); | ||
| 1079 | + goto err; | ||
| 1080 | + } | ||
| 1081 | + | ||
| 1082 | + /* Get the irreducible polynomial that creates the field */ | ||
| 1083 | + if (spcf_bn2bin(p, &q, &q_len)) { | ||
| 1084 | + ECDSAerr(ECDSA_F_ECDSA_DO_VERIFY, ERR_R_MALLOC_FAILURE); | ||
| 1085 | + goto err; | ||
| 1086 | + } | ||
| 1087 | + | ||
| 1088 | + /* Get the public key into a flat buffer with appropriate padding */ | ||
| 1089 | + pub_key_len = 2 * q_len; | ||
| 1090 | + | ||
| 1091 | + w_xy = eng_copy_curve_points(w_x, w_y, pub_key_len, q_len); | ||
| 1092 | + if (!w_xy) { | ||
| 1093 | + ECDSAerr(ECDSA_F_ECDSA_DO_VERIFY, ERR_R_MALLOC_FAILURE); | ||
| 1094 | + goto err; | ||
| 1095 | + } | ||
| 1096 | + | ||
| 1097 | + /* Generation of ECC curve parameters */ | ||
| 1098 | + ab_len = 2 * q_len; | ||
| 1099 | + | ||
| 1100 | + ab = eng_copy_curve_points(a, b, ab_len, q_len); | ||
| 1101 | + if (!ab) { | ||
| 1102 | + ECDSAerr(ECDSA_F_ECDSA_DO_VERIFY, ERR_R_MALLOC_FAILURE); | ||
| 1103 | + goto err; | ||
| 1104 | + } | ||
| 1105 | + | ||
| 1106 | + if (ec_crv == EC_BINARY) { | ||
| 1107 | + /* copy b' i.e c(b), instead of only b */ | ||
| 1108 | + if (eng_ec_get_cparam | ||
| 1109 | + (EC_GROUP_get_curve_name(group), ab + q_len, q_len)) { | ||
| 1110 | + unsigned char *c_temp = NULL; | ||
| 1111 | + int c_temp_len = q_len; | ||
| 1112 | + if (eng_ec_compute_cparam(b, p, &c_temp, &c_temp_len)) | ||
| 1113 | + memcpy(ab + q_len, c_temp, q_len); | ||
| 1114 | + else | ||
| 1115 | + goto err; | ||
| 1116 | + } | ||
| 1117 | + kop.curve_type = ECC_BINARY; | ||
| 1118 | + } | ||
| 1119 | + | ||
| 1120 | + /* Calculation of Generator point */ | ||
| 1121 | + g_len = 2 * q_len; | ||
| 1122 | + | ||
| 1123 | + g_xy = eng_copy_curve_points(x, y, g_len, q_len); | ||
| 1124 | + if (!g_xy) { | ||
| 1125 | + ECDSAerr(ECDSA_F_ECDSA_DO_VERIFY, ERR_R_MALLOC_FAILURE); | ||
| 1126 | + goto err; | ||
| 1127 | + } | ||
| 1128 | + | ||
| 1129 | + /** | ||
| 1130 | + * Get the 1st part of signature into a flat buffer with | ||
| 1131 | + * appropriate padding | ||
| 1132 | + */ | ||
| 1133 | + if (BN_num_bytes(sig->r) < r_len) | ||
| 1134 | + c_len = r_len; | ||
| 1135 | + | ||
| 1136 | + if (spcf_bn2bin_ex(sig->r, &c, &c_len)) { | ||
| 1137 | + ECDSAerr(ECDSA_F_ECDSA_DO_VERIFY, ERR_R_MALLOC_FAILURE); | ||
| 1138 | + goto err; | ||
| 1139 | + } | ||
| 1140 | + | ||
| 1141 | + /** | ||
| 1142 | + * Get the 2nd part of signature into a flat buffer with | ||
| 1143 | + * appropriate padding | ||
| 1144 | + */ | ||
| 1145 | + if (BN_num_bytes(sig->s) < r_len) | ||
| 1146 | + d_len = r_len; | ||
| 1147 | + | ||
| 1148 | + if (spcf_bn2bin_ex(sig->s, &d, &d_len)) { | ||
| 1149 | + ECDSAerr(ECDSA_F_ECDSA_DO_VERIFY, ERR_R_MALLOC_FAILURE); | ||
| 1150 | + goto err; | ||
| 1151 | + } | ||
| 1152 | + | ||
| 1153 | + /* memory for message representative */ | ||
| 1154 | + f = malloc(r_len); | ||
| 1155 | + if (!f) { | ||
| 1156 | + ECDSAerr(ECDSA_F_ECDSA_DO_VERIFY, ERR_R_MALLOC_FAILURE); | ||
| 1157 | + goto err; | ||
| 1158 | + } | ||
| 1159 | + | ||
| 1160 | + /* Add padding, since SEC expects hash to of size r_len */ | ||
| 1161 | + memset(f, 0, r_len - dgst_len); | ||
| 1162 | + | ||
| 1163 | + /* Skip leading bytes if dgst_len < r_len */ | ||
| 1164 | + memcpy(f + r_len - dgst_len, tmp_dgst, dgst_len); | ||
| 1165 | + dgst_len += r_len - dgst_len; | ||
| 1166 | + kop.crk_op = CRK_DSA_VERIFY; | ||
| 1167 | + /* inputs: dgst dsa->p dsa->q dsa->g dsa->priv_key */ | ||
| 1168 | + kop.crk_param[0].crp_p = f; | ||
| 1169 | + kop.crk_param[0].crp_nbits = dgst_len * 8; | ||
| 1170 | + kop.crk_param[1].crp_p = q; | ||
| 1171 | + kop.crk_param[1].crp_nbits = q_len * 8; | ||
| 1172 | + kop.crk_param[2].crp_p = r; | ||
| 1173 | + kop.crk_param[2].crp_nbits = r_len * 8; | ||
| 1174 | + kop.crk_param[3].crp_p = g_xy; | ||
| 1175 | + kop.crk_param[3].crp_nbits = g_len * 8; | ||
| 1176 | + kop.crk_param[4].crp_p = w_xy; | ||
| 1177 | + kop.crk_param[4].crp_nbits = pub_key_len * 8; | ||
| 1178 | + kop.crk_param[5].crp_p = ab; | ||
| 1179 | + kop.crk_param[5].crp_nbits = ab_len * 8; | ||
| 1180 | + kop.crk_param[6].crp_p = c; | ||
| 1181 | + kop.crk_param[6].crp_nbits = d_len * 8; | ||
| 1182 | + kop.crk_param[7].crp_p = d; | ||
| 1183 | + kop.crk_param[7].crp_nbits = d_len * 8; | ||
| 1184 | + kop.crk_iparams = 8; | ||
| 1185 | + | ||
| 1186 | + if (cryptodev_asym(&kop, 0, NULL, 0, NULL) == 0) { | ||
| 1187 | + /* | ||
| 1188 | + * OCF success value is 0, if not zero, change ret to fail | ||
| 1189 | + */ | ||
| 1190 | + if (0 == kop.crk_status) | ||
| 1191 | + ret = 1; | ||
| 1192 | + } else { | ||
| 1193 | + const ECDSA_METHOD *meth = ECDSA_OpenSSL(); | ||
| 1194 | + | ||
| 1195 | + ret = (meth->ecdsa_do_verify) (dgst, dgst_len, sig, eckey); | ||
| 1196 | + } | ||
| 1197 | + kop.crk_param[0].crp_p = NULL; | ||
| 1198 | + zapparams(&kop); | ||
| 1199 | + | ||
| 1200 | + err: | ||
| 1201 | + return ret; | ||
| 1202 | +} | ||
| 1203 | + | ||
| 1204 | +static int cryptodev_dh_keygen(DH *dh) | ||
| 1205 | +{ | ||
| 1206 | + struct crypt_kop kop; | ||
| 1207 | + int ret = 1, g_len; | ||
| 1208 | + unsigned char *g = NULL; | ||
| 1209 | + | ||
| 1210 | + if (dh->priv_key == NULL) { | ||
| 1211 | + if ((dh->priv_key = BN_new()) == NULL) | ||
| 1212 | + goto sw_try; | ||
| 1213 | + } | ||
| 1214 | + | ||
| 1215 | + if (dh->pub_key == NULL) { | ||
| 1216 | + if ((dh->pub_key = BN_new()) == NULL) | ||
| 1217 | + goto sw_try; | ||
| 1218 | + } | ||
| 1219 | + | ||
| 1220 | + g_len = BN_num_bytes(dh->p); | ||
| 1221 | + /** | ||
| 1222 | + * Get generator into a plain buffer. If length is less than | ||
| 1223 | + * q_len then add leading padding bytes. | ||
| 1224 | + */ | ||
| 1225 | + if (spcf_bn2bin_ex(dh->g, &g, &g_len)) { | ||
| 1226 | + DSAerr(DH_F_DH_GENERATE_KEY, ERR_R_MALLOC_FAILURE); | ||
| 1227 | + goto sw_try; | ||
| 1228 | + } | ||
| 1229 | + | ||
| 1230 | + memset(&kop, 0, sizeof kop); | ||
| 1231 | + kop.crk_op = CRK_DH_GENERATE_KEY; | ||
| 1232 | + if (bn2crparam(dh->p, &kop.crk_param[0])) | ||
| 1233 | + goto sw_try; | ||
| 1234 | + if (bn2crparam(dh->q, &kop.crk_param[1])) | ||
| 1235 | + goto sw_try; | ||
| 1236 | + kop.crk_param[2].crp_p = g; | ||
| 1237 | + kop.crk_param[2].crp_nbits = g_len * 8; | ||
| 1238 | + kop.crk_iparams = 3; | ||
| 1239 | + | ||
| 1240 | + /* pub_key is or prime length while priv key is of length of order */ | ||
| 1241 | + if (cryptodev_asym(&kop, BN_num_bytes(dh->p), dh->pub_key, | ||
| 1242 | + BN_num_bytes(dh->q), dh->priv_key)) | ||
| 1243 | + goto sw_try; | ||
| 1244 | + | ||
| 1245 | + return ret; | ||
| 1246 | + sw_try: | ||
| 1247 | + { | ||
| 1248 | + const DH_METHOD *meth = DH_OpenSSL(); | ||
| 1249 | + ret = (meth->generate_key) (dh); | ||
| 1250 | + } | ||
| 1251 | + return ret; | ||
| 1252 | } | ||
| 1253 | |||
| 1254 | static int | ||
| 1255 | @@ -1597,41 +2418,236 @@ cryptodev_dh_compute_key(unsigned char *key, const BIGNUM *pub_key, DH *dh) | ||
| 1256 | { | ||
| 1257 | struct crypt_kop kop; | ||
| 1258 | int dhret = 1; | ||
| 1259 | - int fd, keylen; | ||
| 1260 | + int fd, p_len; | ||
| 1261 | + BIGNUM *temp = NULL; | ||
| 1262 | + unsigned char *padded_pub_key = NULL, *p = NULL; | ||
| 1263 | + | ||
| 1264 | + if ((fd = get_asym_dev_crypto()) < 0) | ||
| 1265 | + goto sw_try; | ||
| 1266 | + | ||
| 1267 | + memset(&kop, 0, sizeof kop); | ||
| 1268 | + kop.crk_op = CRK_DH_COMPUTE_KEY; | ||
| 1269 | + /* inputs: dh->priv_key pub_key dh->p key */ | ||
| 1270 | + spcf_bn2bin(dh->p, &p, &p_len); | ||
| 1271 | + spcf_bn2bin_ex(pub_key, &padded_pub_key, &p_len); | ||
| 1272 | + if (bn2crparam(dh->priv_key, &kop.crk_param[0])) | ||
| 1273 | + goto sw_try; | ||
| 1274 | + | ||
| 1275 | + kop.crk_param[1].crp_p = padded_pub_key; | ||
| 1276 | + kop.crk_param[1].crp_nbits = p_len * 8; | ||
| 1277 | + kop.crk_param[2].crp_p = p; | ||
| 1278 | + kop.crk_param[2].crp_nbits = p_len * 8; | ||
| 1279 | + kop.crk_iparams = 3; | ||
| 1280 | + kop.crk_param[3].crp_p = (void *)key; | ||
| 1281 | + kop.crk_param[3].crp_nbits = p_len * 8; | ||
| 1282 | + kop.crk_oparams = 1; | ||
| 1283 | + dhret = p_len; | ||
| 1284 | + | ||
| 1285 | + if (ioctl(fd, CIOCKEY, &kop)) | ||
| 1286 | + goto sw_try; | ||
| 1287 | + | ||
| 1288 | + if ((temp = BN_new())) { | ||
| 1289 | + if (!BN_bin2bn(key, p_len, temp)) { | ||
| 1290 | + ECDSAerr(ECDSA_F_ECDSA_DO_SIGN, ERR_R_BN_LIB); | ||
| 1291 | + goto sw_try; | ||
| 1292 | + } | ||
| 1293 | + if (dhret > BN_num_bytes(temp)) | ||
| 1294 | + dhret = BN_bn2bin(temp, key); | ||
| 1295 | + BN_free(temp); | ||
| 1296 | + } | ||
| 1297 | |||
| 1298 | - if ((fd = get_asym_dev_crypto()) < 0) { | ||
| 1299 | + kop.crk_param[3].crp_p = NULL; | ||
| 1300 | + zapparams(&kop); | ||
| 1301 | + return (dhret); | ||
| 1302 | + sw_try: | ||
| 1303 | + { | ||
| 1304 | const DH_METHOD *meth = DH_OpenSSL(); | ||
| 1305 | |||
| 1306 | - return ((meth->compute_key) (key, pub_key, dh)); | ||
| 1307 | + dhret = (meth->compute_key) (key, pub_key, dh); | ||
| 1308 | } | ||
| 1309 | + return (dhret); | ||
| 1310 | +} | ||
| 1311 | |||
| 1312 | - keylen = BN_num_bits(dh->p); | ||
| 1313 | +int cryptodev_ecdh_compute_key(void *out, size_t outlen, | ||
| 1314 | + const EC_POINT *pub_key, EC_KEY *ecdh, | ||
| 1315 | + void *(*KDF) (const void *in, size_t inlen, | ||
| 1316 | + void *out, size_t *outlen)) | ||
| 1317 | +{ | ||
| 1318 | + ec_curve_t ec_crv = EC_PRIME; | ||
| 1319 | + unsigned char *q = NULL, *w_xy = NULL, *ab = NULL, *s = NULL, *r = NULL; | ||
| 1320 | + BIGNUM *w_x = NULL, *w_y = NULL; | ||
| 1321 | + int q_len = 0, ab_len = 0, pub_key_len = 0, r_len = 0, priv_key_len = 0; | ||
| 1322 | + BIGNUM *p = NULL, *a = NULL, *b = NULL; | ||
| 1323 | + BN_CTX *ctx; | ||
| 1324 | + EC_POINT *tmp = NULL; | ||
| 1325 | + BIGNUM *x = NULL, *y = NULL; | ||
| 1326 | + const BIGNUM *priv_key; | ||
| 1327 | + const EC_GROUP *group = NULL; | ||
| 1328 | + int ret = -1; | ||
| 1329 | + size_t buflen, len; | ||
| 1330 | + struct crypt_kop kop; | ||
| 1331 | |||
| 1332 | memset(&kop, 0, sizeof kop); | ||
| 1333 | - kop.crk_op = CRK_DH_COMPUTE_KEY; | ||
| 1334 | |||
| 1335 | - /* inputs: dh->priv_key pub_key dh->p key */ | ||
| 1336 | - if (bn2crparam(dh->priv_key, &kop.crk_param[0])) | ||
| 1337 | + if ((ctx = BN_CTX_new()) == NULL) | ||
| 1338 | goto err; | ||
| 1339 | - if (bn2crparam(pub_key, &kop.crk_param[1])) | ||
| 1340 | + BN_CTX_start(ctx); | ||
| 1341 | + x = BN_CTX_get(ctx); | ||
| 1342 | + y = BN_CTX_get(ctx); | ||
| 1343 | + p = BN_CTX_get(ctx); | ||
| 1344 | + a = BN_CTX_get(ctx); | ||
| 1345 | + b = BN_CTX_get(ctx); | ||
| 1346 | + w_x = BN_CTX_get(ctx); | ||
| 1347 | + w_y = BN_CTX_get(ctx); | ||
| 1348 | + | ||
| 1349 | + if (!x || !y || !p || !a || !b || !w_x || !w_y) { | ||
| 1350 | + ECDHerr(ECDH_F_ECDH_COMPUTE_KEY, ERR_R_MALLOC_FAILURE); | ||
| 1351 | goto err; | ||
| 1352 | - if (bn2crparam(dh->p, &kop.crk_param[2])) | ||
| 1353 | + } | ||
| 1354 | + | ||
| 1355 | + priv_key = EC_KEY_get0_private_key(ecdh); | ||
| 1356 | + if (priv_key == NULL) { | ||
| 1357 | + ECDHerr(ECDH_F_ECDH_COMPUTE_KEY, ECDH_R_NO_PRIVATE_VALUE); | ||
| 1358 | goto err; | ||
| 1359 | - kop.crk_iparams = 3; | ||
| 1360 | + } | ||
| 1361 | |||
| 1362 | - kop.crk_param[3].crp_p = (caddr_t) key; | ||
| 1363 | - kop.crk_param[3].crp_nbits = keylen * 8; | ||
| 1364 | - kop.crk_oparams = 1; | ||
| 1365 | + group = EC_KEY_get0_group(ecdh); | ||
| 1366 | + if ((tmp = EC_POINT_new(group)) == NULL) { | ||
| 1367 | + ECDHerr(ECDH_F_ECDH_COMPUTE_KEY, ERR_R_MALLOC_FAILURE); | ||
| 1368 | + goto err; | ||
| 1369 | + } | ||
| 1370 | |||
| 1371 | - if (ioctl(fd, CIOCKEY, &kop) == -1) { | ||
| 1372 | - const DH_METHOD *meth = DH_OpenSSL(); | ||
| 1373 | + if (EC_METHOD_get_field_type(EC_GROUP_method_of(group)) == | ||
| 1374 | + NID_X9_62_prime_field) { | ||
| 1375 | + ec_crv = EC_PRIME; | ||
| 1376 | |||
| 1377 | - dhret = (meth->compute_key) (key, pub_key, dh); | ||
| 1378 | + if (!EC_POINT_get_affine_coordinates_GFp(group, | ||
| 1379 | + EC_GROUP_get0_generator | ||
| 1380 | + (group), x, y, ctx)) { | ||
| 1381 | + ECDHerr(ECDH_F_ECDH_COMPUTE_KEY, ECDH_R_POINT_ARITHMETIC_FAILURE); | ||
| 1382 | + goto err; | ||
| 1383 | + } | ||
| 1384 | + | ||
| 1385 | + /* get the ECC curve parameters */ | ||
| 1386 | + if (!EC_GROUP_get_curve_GFp(group, p, a, b, ctx)) { | ||
| 1387 | + ECDHerr(ECDH_F_ECDH_COMPUTE_KEY, ERR_R_BN_LIB); | ||
| 1388 | + goto err; | ||
| 1389 | + } | ||
| 1390 | + | ||
| 1391 | + /* get the public key pair for prime curve */ | ||
| 1392 | + if (!EC_POINT_get_affine_coordinates_GFp | ||
| 1393 | + (group, pub_key, w_x, w_y, ctx)) { | ||
| 1394 | + ECDHerr(ECDH_F_ECDH_COMPUTE_KEY, ERR_R_BN_LIB); | ||
| 1395 | + goto err; | ||
| 1396 | + } | ||
| 1397 | + } else { | ||
| 1398 | + ec_crv = EC_BINARY; | ||
| 1399 | + | ||
| 1400 | + if (!EC_POINT_get_affine_coordinates_GF2m(group, | ||
| 1401 | + EC_GROUP_get0_generator | ||
| 1402 | + (group), x, y, ctx)) { | ||
| 1403 | + ECDHerr(ECDH_F_ECDH_COMPUTE_KEY, ECDH_R_POINT_ARITHMETIC_FAILURE); | ||
| 1404 | + goto err; | ||
| 1405 | + } | ||
| 1406 | + | ||
| 1407 | + /* get the ECC curve parameters */ | ||
| 1408 | + if (!EC_GROUP_get_curve_GF2m(group, p, a, b, ctx)) { | ||
| 1409 | + ECDHerr(ECDH_F_ECDH_COMPUTE_KEY, ERR_R_BN_LIB); | ||
| 1410 | + goto err; | ||
| 1411 | + } | ||
| 1412 | + | ||
| 1413 | + /* get the public key pair for binary curve */ | ||
| 1414 | + if (!EC_POINT_get_affine_coordinates_GF2m(group, | ||
| 1415 | + pub_key, w_x, w_y, ctx)) { | ||
| 1416 | + ECDSAerr(ECDSA_F_ECDSA_DO_SIGN, ERR_R_EC_LIB); | ||
| 1417 | + goto err; | ||
| 1418 | + } | ||
| 1419 | + } | ||
| 1420 | + | ||
| 1421 | + /* irreducible polynomial that creates the field */ | ||
| 1422 | + if (spcf_bn2bin((BIGNUM *)&group->order, &r, &r_len)) { | ||
| 1423 | + ECDSAerr(ECDSA_F_ECDSA_DO_SIGN, ERR_R_MALLOC_FAILURE); | ||
| 1424 | + goto err; | ||
| 1425 | + } | ||
| 1426 | + | ||
| 1427 | + /* Get the irreducible polynomial that creates the field */ | ||
| 1428 | + if (spcf_bn2bin(p, &q, &q_len)) { | ||
| 1429 | + ECDHerr(ECDH_F_ECDH_COMPUTE_KEY, ERR_R_BN_LIB); | ||
| 1430 | + goto err; | ||
| 1431 | + } | ||
| 1432 | + | ||
| 1433 | + /* Get the public key into a flat buffer with appropriate padding */ | ||
| 1434 | + pub_key_len = 2 * q_len; | ||
| 1435 | + w_xy = eng_copy_curve_points(w_x, w_y, pub_key_len, q_len); | ||
| 1436 | + if (!w_xy) { | ||
| 1437 | + ECDSAerr(ECDSA_F_ECDSA_DO_SIGN, ERR_R_MALLOC_FAILURE); | ||
| 1438 | + goto err; | ||
| 1439 | + } | ||
| 1440 | + | ||
| 1441 | + /* Generation of ECC curve parameters */ | ||
| 1442 | + ab_len = 2 * q_len; | ||
| 1443 | + ab = eng_copy_curve_points(a, b, ab_len, q_len); | ||
| 1444 | + if (!ab) { | ||
| 1445 | + ECDHerr(ECDH_F_ECDH_COMPUTE_KEY, ERR_R_BN_LIB); | ||
| 1446 | + goto err; | ||
| 1447 | + } | ||
| 1448 | + | ||
| 1449 | + if (ec_crv == EC_BINARY) { | ||
| 1450 | + /* copy b' i.e c(b), instead of only b */ | ||
| 1451 | + if (eng_ec_get_cparam | ||
| 1452 | + (EC_GROUP_get_curve_name(group), ab + q_len, q_len)) { | ||
| 1453 | + unsigned char *c_temp = NULL; | ||
| 1454 | + int c_temp_len = q_len; | ||
| 1455 | + if (eng_ec_compute_cparam(b, p, &c_temp, &c_temp_len)) | ||
| 1456 | + memcpy(ab + q_len, c_temp, q_len); | ||
| 1457 | + else | ||
| 1458 | + goto err; | ||
| 1459 | + } | ||
| 1460 | + kop.curve_type = ECC_BINARY; | ||
| 1461 | + } else | ||
| 1462 | + kop.curve_type = ECC_PRIME; | ||
| 1463 | + | ||
| 1464 | + priv_key_len = r_len; | ||
| 1465 | + | ||
| 1466 | + /* | ||
| 1467 | + * If BN_num_bytes of priv_key returns less then r_len then | ||
| 1468 | + * add padding bytes before the key | ||
| 1469 | + */ | ||
| 1470 | + if (spcf_bn2bin_ex((BIGNUM *)priv_key, &s, &priv_key_len)) { | ||
| 1471 | + ECDSAerr(ECDSA_F_ECDSA_DO_SIGN, ERR_R_MALLOC_FAILURE); | ||
| 1472 | + goto err; | ||
| 1473 | + } | ||
| 1474 | + | ||
| 1475 | + buflen = (EC_GROUP_get_degree(group) + 7) / 8; | ||
| 1476 | + len = BN_num_bytes(x); | ||
| 1477 | + if (len > buflen || q_len < buflen) { | ||
| 1478 | + ECDHerr(ECDH_F_ECDH_COMPUTE_KEY, ERR_R_INTERNAL_ERROR); | ||
| 1479 | + goto err; | ||
| 1480 | } | ||
| 1481 | + | ||
| 1482 | + kop.crk_op = CRK_DH_COMPUTE_KEY; | ||
| 1483 | + kop.crk_param[0].crp_p = (void *)s; | ||
| 1484 | + kop.crk_param[0].crp_nbits = priv_key_len * 8; | ||
| 1485 | + kop.crk_param[1].crp_p = (void *)w_xy; | ||
| 1486 | + kop.crk_param[1].crp_nbits = pub_key_len * 8; | ||
| 1487 | + kop.crk_param[2].crp_p = (void *)q; | ||
| 1488 | + kop.crk_param[2].crp_nbits = q_len * 8; | ||
| 1489 | + kop.crk_param[3].crp_p = (void *)ab; | ||
| 1490 | + kop.crk_param[3].crp_nbits = ab_len * 8; | ||
| 1491 | + kop.crk_iparams = 4; | ||
| 1492 | + kop.crk_param[4].crp_p = (void *)out; | ||
| 1493 | + kop.crk_param[4].crp_nbits = q_len * 8; | ||
| 1494 | + kop.crk_oparams = 1; | ||
| 1495 | + ret = q_len; | ||
| 1496 | + if (cryptodev_asym(&kop, 0, NULL, 0, NULL)) { | ||
| 1497 | + const ECDH_METHOD *meth = ECDH_OpenSSL(); | ||
| 1498 | + ret = (meth->compute_key) (out, outlen, pub_key, ecdh, KDF); | ||
| 1499 | + } else | ||
| 1500 | + ret = q_len; | ||
| 1501 | err: | ||
| 1502 | - kop.crk_param[3].crp_p = NULL; | ||
| 1503 | + kop.crk_param[4].crp_p = NULL; | ||
| 1504 | zapparams(&kop); | ||
| 1505 | - return (dhret); | ||
| 1506 | + return ret; | ||
| 1507 | } | ||
| 1508 | |||
| 1509 | static DH_METHOD cryptodev_dh = { | ||
| 1510 | @@ -1645,6 +2661,14 @@ static DH_METHOD cryptodev_dh = { | ||
| 1511 | NULL /* app_data */ | ||
| 1512 | }; | ||
| 1513 | |||
| 1514 | +static ECDH_METHOD cryptodev_ecdh = { | ||
| 1515 | + "cryptodev ECDH method", | ||
| 1516 | + NULL, /* cryptodev_ecdh_compute_key */ | ||
| 1517 | + NULL, | ||
| 1518 | + 0, /* flags */ | ||
| 1519 | + NULL /* app_data */ | ||
| 1520 | +}; | ||
| 1521 | + | ||
| 1522 | /* | ||
| 1523 | * ctrl right now is just a wrapper that doesn't do much | ||
| 1524 | * but I expect we'll want some options soon. | ||
| 1525 | @@ -1724,24 +2748,39 @@ void ENGINE_load_cryptodev(void) | ||
| 1526 | memcpy(&cryptodev_dsa, meth, sizeof(DSA_METHOD)); | ||
| 1527 | if (cryptodev_asymfeat & CRF_DSA_SIGN) | ||
| 1528 | cryptodev_dsa.dsa_do_sign = cryptodev_dsa_do_sign; | ||
| 1529 | - if (cryptodev_asymfeat & CRF_MOD_EXP) { | ||
| 1530 | - cryptodev_dsa.bn_mod_exp = cryptodev_dsa_bn_mod_exp; | ||
| 1531 | - cryptodev_dsa.dsa_mod_exp = cryptodev_dsa_dsa_mod_exp; | ||
| 1532 | - } | ||
| 1533 | if (cryptodev_asymfeat & CRF_DSA_VERIFY) | ||
| 1534 | cryptodev_dsa.dsa_do_verify = cryptodev_dsa_verify; | ||
| 1535 | + if (cryptodev_asymfeat & CRF_DSA_GENERATE_KEY) | ||
| 1536 | + cryptodev_dsa.dsa_keygen = cryptodev_dsa_keygen; | ||
| 1537 | } | ||
| 1538 | |||
| 1539 | if (ENGINE_set_DH(engine, &cryptodev_dh)) { | ||
| 1540 | const DH_METHOD *dh_meth = DH_OpenSSL(); | ||
| 1541 | + memcpy(&cryptodev_dh, dh_meth, sizeof(DH_METHOD)); | ||
| 1542 | + if (cryptodev_asymfeat & CRF_DH_COMPUTE_KEY) { | ||
| 1543 | + cryptodev_dh.compute_key = cryptodev_dh_compute_key; | ||
| 1544 | + } | ||
| 1545 | + if (cryptodev_asymfeat & CRF_DH_GENERATE_KEY) { | ||
| 1546 | + cryptodev_dh.generate_key = cryptodev_dh_keygen; | ||
| 1547 | + } | ||
| 1548 | + } | ||
| 1549 | |||
| 1550 | - cryptodev_dh.generate_key = dh_meth->generate_key; | ||
| 1551 | - cryptodev_dh.compute_key = dh_meth->compute_key; | ||
| 1552 | - cryptodev_dh.bn_mod_exp = dh_meth->bn_mod_exp; | ||
| 1553 | - if (cryptodev_asymfeat & CRF_MOD_EXP) { | ||
| 1554 | - cryptodev_dh.bn_mod_exp = cryptodev_mod_exp_dh; | ||
| 1555 | - if (cryptodev_asymfeat & CRF_DH_COMPUTE_KEY) | ||
| 1556 | - cryptodev_dh.compute_key = cryptodev_dh_compute_key; | ||
| 1557 | + if (ENGINE_set_ECDSA(engine, &cryptodev_ecdsa)) { | ||
| 1558 | + const ECDSA_METHOD *meth = ECDSA_OpenSSL(); | ||
| 1559 | + memcpy(&cryptodev_ecdsa, meth, sizeof(ECDSA_METHOD)); | ||
| 1560 | + if (cryptodev_asymfeat & CRF_DSA_SIGN) { | ||
| 1561 | + cryptodev_ecdsa.ecdsa_do_sign = cryptodev_ecdsa_do_sign; | ||
| 1562 | + } | ||
| 1563 | + if (cryptodev_asymfeat & CRF_DSA_VERIFY) { | ||
| 1564 | + cryptodev_ecdsa.ecdsa_do_verify = cryptodev_ecdsa_verify; | ||
| 1565 | + } | ||
| 1566 | + } | ||
| 1567 | + | ||
| 1568 | + if (ENGINE_set_ECDH(engine, &cryptodev_ecdh)) { | ||
| 1569 | + const ECDH_METHOD *ecdh_meth = ECDH_OpenSSL(); | ||
| 1570 | + memcpy(&cryptodev_ecdh, ecdh_meth, sizeof(ECDH_METHOD)); | ||
| 1571 | + if (cryptodev_asymfeat & CRF_DH_COMPUTE_KEY) { | ||
| 1572 | + cryptodev_ecdh.compute_key = cryptodev_ecdh_compute_key; | ||
| 1573 | } | ||
| 1574 | } | ||
| 1575 | |||
| 1576 | -- | ||
| 1577 | 2.7.0 | ||
| 1578 | |||
diff --git a/recipes-connectivity/openssl/openssl-qoriq/qoriq/0006-Added-hwrng-dev-file-as-source-of-RNG.patch b/recipes-connectivity/openssl/openssl-qoriq/qoriq/0006-Added-hwrng-dev-file-as-source-of-RNG.patch new file mode 100644 index 000000000..61469dcf3 --- /dev/null +++ b/recipes-connectivity/openssl/openssl-qoriq/qoriq/0006-Added-hwrng-dev-file-as-source-of-RNG.patch | |||
| @@ -0,0 +1,28 @@ | |||
| 1 | From c3b1f595607fe4e431dab12b7d8ceda6742547d5 Mon Sep 17 00:00:00 2001 | ||
| 2 | From: Yashpal Dutta <yashpal.dutta@freescale.com> | ||
| 3 | Date: Tue, 11 Mar 2014 06:42:59 +0545 | ||
| 4 | Subject: [PATCH 06/48] Added hwrng dev file as source of RNG | ||
| 5 | |||
| 6 | Upstream-status: Pending | ||
| 7 | |||
| 8 | Signed-off-by: Yashpal Dutta <yashpal.dutta@freescale.com> | ||
| 9 | --- | ||
| 10 | e_os.h | 2 +- | ||
| 11 | 1 file changed, 1 insertion(+), 1 deletion(-) | ||
| 12 | |||
| 13 | diff --git a/e_os.h b/e_os.h | ||
| 14 | index 1fa36c1..6c0917b 100644 | ||
| 15 | --- a/e_os.h | ||
| 16 | +++ b/e_os.h | ||
| 17 | @@ -82,7 +82,7 @@ extern "C" { | ||
| 18 | * set this to a comma-separated list of 'random' device files to try out. My | ||
| 19 | * default, we will try to read at least one of these files | ||
| 20 | */ | ||
| 21 | -# define DEVRANDOM "/dev/urandom","/dev/random","/dev/srandom" | ||
| 22 | +# define DEVRANDOM "/dev/hwrng","/dev/urandom","/dev/random","/dev/srandom" | ||
| 23 | # endif | ||
| 24 | # ifndef DEVRANDOM_EGD | ||
| 25 | /* | ||
| 26 | -- | ||
| 27 | 2.7.0 | ||
| 28 | |||
diff --git a/recipes-connectivity/openssl/openssl-qoriq/qoriq/0006-Fixed-private-key-support-for-DH.patch b/recipes-connectivity/openssl/openssl-qoriq/qoriq/0006-Fixed-private-key-support-for-DH.patch deleted file mode 100644 index 01c268b6f..000000000 --- a/recipes-connectivity/openssl/openssl-qoriq/qoriq/0006-Fixed-private-key-support-for-DH.patch +++ /dev/null | |||
| @@ -1,33 +0,0 @@ | |||
| 1 | From 39a9e609290a8a1163a721915bcde0c7cf8f92f7 Mon Sep 17 00:00:00 2001 | ||
| 2 | From: Yashpal Dutta <yashpal.dutta@freescale.com> | ||
| 3 | Date: Tue, 11 Mar 2014 05:57:47 +0545 | ||
| 4 | Subject: [PATCH 06/26] Fixed private key support for DH | ||
| 5 | |||
| 6 | Upstream-status: Pending | ||
| 7 | |||
| 8 | Signed-off-by: Yashpal Dutta <yashpal.dutta@freescale.com> | ||
| 9 | --- | ||
| 10 | crypto/dh/dh_ameth.c | 7 +++++++ | ||
| 11 | 1 file changed, 7 insertions(+) | ||
| 12 | |||
| 13 | diff --git a/crypto/dh/dh_ameth.c b/crypto/dh/dh_ameth.c | ||
| 14 | index 02ec2d4..ed32004 100644 | ||
| 15 | --- a/crypto/dh/dh_ameth.c | ||
| 16 | +++ b/crypto/dh/dh_ameth.c | ||
| 17 | @@ -422,6 +422,13 @@ static int dh_copy_parameters(EVP_PKEY *to, const EVP_PKEY *from) | ||
| 18 | if (to->pkey.dh->g != NULL) | ||
| 19 | BN_free(to->pkey.dh->g); | ||
| 20 | to->pkey.dh->g=a; | ||
| 21 | + if ((a=BN_dup(from->pkey.dh->q)) != NULL) { | ||
| 22 | + if (to->pkey.dh->q != NULL) | ||
| 23 | + BN_free(to->pkey.dh->q); | ||
| 24 | + to->pkey.dh->q=a; | ||
| 25 | + } | ||
| 26 | + | ||
| 27 | + to->pkey.dh->length = from->pkey.dh->length; | ||
| 28 | |||
| 29 | return 1; | ||
| 30 | } | ||
| 31 | -- | ||
| 32 | 2.3.5 | ||
| 33 | |||
diff --git a/recipes-connectivity/openssl/openssl-qoriq/qoriq/0007-Asynchronous-interface-added-for-PKC-cryptodev-inter.patch b/recipes-connectivity/openssl/openssl-qoriq/qoriq/0007-Asynchronous-interface-added-for-PKC-cryptodev-inter.patch new file mode 100644 index 000000000..192cd1842 --- /dev/null +++ b/recipes-connectivity/openssl/openssl-qoriq/qoriq/0007-Asynchronous-interface-added-for-PKC-cryptodev-inter.patch | |||
| @@ -0,0 +1,2050 @@ | |||
| 1 | From 45cfc01ade9eeb43fdb5950d3db152cae1b41059 Mon Sep 17 00:00:00 2001 | ||
| 2 | From: Yashpal Dutta <yashpal.dutta@freescale.com> | ||
| 3 | Date: Tue, 11 Mar 2014 07:14:30 +0545 | ||
| 4 | Subject: [PATCH 07/48] Asynchronous interface added for PKC cryptodev | ||
| 5 | interface | ||
| 6 | |||
| 7 | Upstream-status: Pending | ||
| 8 | |||
| 9 | Change-Id: Ia8974f793dc18a959ed6798dcdd7d3fad81cb7da | ||
| 10 | Signed-off-by: Yashpal Dutta <yashpal.dutta@freescale.com> | ||
| 11 | --- | ||
| 12 | crypto/crypto.h | 16 + | ||
| 13 | crypto/dh/dh.h | 3 + | ||
| 14 | crypto/dsa/dsa.h | 5 + | ||
| 15 | crypto/ecdh/ech_locl.h | 3 + | ||
| 16 | crypto/ecdsa/ecs_locl.h | 5 + | ||
| 17 | crypto/engine/eng_cryptodev.c | 1598 +++++++++++++++++++++++++++++++++++++---- | ||
| 18 | crypto/engine/eng_int.h | 23 + | ||
| 19 | crypto/engine/eng_lib.c | 46 ++ | ||
| 20 | crypto/engine/engine.h | 24 + | ||
| 21 | crypto/rsa/rsa.h | 23 + | ||
| 22 | 10 files changed, 1605 insertions(+), 141 deletions(-) | ||
| 23 | |||
| 24 | diff --git a/crypto/crypto.h b/crypto/crypto.h | ||
| 25 | index 6c644ce..2b4ec59 100644 | ||
| 26 | --- a/crypto/crypto.h | ||
| 27 | +++ b/crypto/crypto.h | ||
| 28 | @@ -655,6 +655,22 @@ void ERR_load_CRYPTO_strings(void); | ||
| 29 | # define CRYPTO_R_FIPS_MODE_NOT_SUPPORTED 101 | ||
| 30 | # define CRYPTO_R_NO_DYNLOCK_CREATE_CALLBACK 100 | ||
| 31 | |||
| 32 | +/* Additions for Asynchronous PKC Infrastructure */ | ||
| 33 | +struct pkc_cookie_s { | ||
| 34 | + void *cookie; /* To be filled by openssl library primitive method function caller */ | ||
| 35 | + void *eng_cookie; /* To be filled by Engine */ | ||
| 36 | + /* | ||
| 37 | + * Callback handler to be provided by caller. Ensure to pass a | ||
| 38 | + * handler which takes the crypto operation to completion. | ||
| 39 | + * cookie: Container cookie from library | ||
| 40 | + * status: Status of the crypto Job completion. | ||
| 41 | + * 0: Job handled without any issue | ||
| 42 | + * -EINVAL: Parameters Invalid | ||
| 43 | + */ | ||
| 44 | + void (*pkc_callback)(struct pkc_cookie_s *cookie, int status); | ||
| 45 | + void *eng_handle; | ||
| 46 | +}; | ||
| 47 | + | ||
| 48 | #ifdef __cplusplus | ||
| 49 | } | ||
| 50 | #endif | ||
| 51 | diff --git a/crypto/dh/dh.h b/crypto/dh/dh.h | ||
| 52 | index a5bd901..31dd762 100644 | ||
| 53 | --- a/crypto/dh/dh.h | ||
| 54 | +++ b/crypto/dh/dh.h | ||
| 55 | @@ -123,6 +123,9 @@ struct dh_method { | ||
| 56 | int (*bn_mod_exp) (const DH *dh, BIGNUM *r, const BIGNUM *a, | ||
| 57 | const BIGNUM *p, const BIGNUM *m, BN_CTX *ctx, | ||
| 58 | BN_MONT_CTX *m_ctx); | ||
| 59 | + int (*compute_key_async)(unsigned char *key,const BIGNUM *pub_key,DH *dh, | ||
| 60 | + struct pkc_cookie_s *cookie); | ||
| 61 | + int (*generate_key_async)(DH *dh, struct pkc_cookie_s *cookie); | ||
| 62 | int (*init) (DH *dh); | ||
| 63 | int (*finish) (DH *dh); | ||
| 64 | int flags; | ||
| 65 | diff --git a/crypto/dsa/dsa.h b/crypto/dsa/dsa.h | ||
| 66 | index 545358f..8584731 100644 | ||
| 67 | --- a/crypto/dsa/dsa.h | ||
| 68 | +++ b/crypto/dsa/dsa.h | ||
| 69 | @@ -139,6 +139,10 @@ struct dsa_method { | ||
| 70 | /* Can be null */ | ||
| 71 | int (*bn_mod_exp) (DSA *dsa, BIGNUM *r, BIGNUM *a, const BIGNUM *p, | ||
| 72 | const BIGNUM *m, BN_CTX *ctx, BN_MONT_CTX *m_ctx); | ||
| 73 | + int (*dsa_do_sign_async)(const unsigned char *dgst, int dlen, DSA *dsa, | ||
| 74 | + DSA_SIG *sig, struct pkc_cookie_s *cookie); | ||
| 75 | + int (*dsa_do_verify_async)(const unsigned char *dgst, int dgst_len, | ||
| 76 | + DSA_SIG *sig, DSA *dsa, struct pkc_cookie_s *cookie); | ||
| 77 | int (*init) (DSA *dsa); | ||
| 78 | int (*finish) (DSA *dsa); | ||
| 79 | int flags; | ||
| 80 | @@ -150,6 +154,7 @@ struct dsa_method { | ||
| 81 | BN_GENCB *cb); | ||
| 82 | /* If this is non-NULL, it is used to generate DSA keys */ | ||
| 83 | int (*dsa_keygen) (DSA *dsa); | ||
| 84 | + int (*dsa_keygen_async)(DSA *dsa, struct pkc_cookie_s *cookie); | ||
| 85 | }; | ||
| 86 | |||
| 87 | struct dsa_st { | ||
| 88 | diff --git a/crypto/ecdh/ech_locl.h b/crypto/ecdh/ech_locl.h | ||
| 89 | index 4e66024..502507b 100644 | ||
| 90 | --- a/crypto/ecdh/ech_locl.h | ||
| 91 | +++ b/crypto/ecdh/ech_locl.h | ||
| 92 | @@ -68,6 +68,9 @@ struct ecdh_method { | ||
| 93 | EC_KEY *ecdh, void *(*KDF) (const void *in, | ||
| 94 | size_t inlen, void *out, | ||
| 95 | size_t *outlen)); | ||
| 96 | + int (*compute_key_async)(void *key, size_t outlen, const EC_POINT *pub_key, EC_KEY *ecdh, | ||
| 97 | + void *(*KDF)(const void *in, size_t inlen, void *out, size_t *outlen), | ||
| 98 | + struct pkc_cookie_s *cookie); | ||
| 99 | # if 0 | ||
| 100 | int (*init) (EC_KEY *eckey); | ||
| 101 | int (*finish) (EC_KEY *eckey); | ||
| 102 | diff --git a/crypto/ecdsa/ecs_locl.h b/crypto/ecdsa/ecs_locl.h | ||
| 103 | index d3a5efc..9b28c04 100644 | ||
| 104 | --- a/crypto/ecdsa/ecs_locl.h | ||
| 105 | +++ b/crypto/ecdsa/ecs_locl.h | ||
| 106 | @@ -74,6 +74,11 @@ struct ecdsa_method { | ||
| 107 | BIGNUM **r); | ||
| 108 | int (*ecdsa_do_verify) (const unsigned char *dgst, int dgst_len, | ||
| 109 | const ECDSA_SIG *sig, EC_KEY *eckey); | ||
| 110 | + int (*ecdsa_do_sign_async)(const unsigned char *dgst, int dgst_len, | ||
| 111 | + const BIGNUM *inv, const BIGNUM *rp, EC_KEY *eckey, | ||
| 112 | + ECDSA_SIG *sig, struct pkc_cookie_s *cookie); | ||
| 113 | + int (*ecdsa_do_verify_async)(const unsigned char *dgst, int dgst_len, | ||
| 114 | + const ECDSA_SIG *sig, EC_KEY *eckey, struct pkc_cookie_s *cookie); | ||
| 115 | # if 0 | ||
| 116 | int (*init) (EC_KEY *eckey); | ||
| 117 | int (*finish) (EC_KEY *eckey); | ||
| 118 | diff --git a/crypto/engine/eng_cryptodev.c b/crypto/engine/eng_cryptodev.c | ||
| 119 | index 0b41bb2..8303630 100644 | ||
| 120 | --- a/crypto/engine/eng_cryptodev.c | ||
| 121 | +++ b/crypto/engine/eng_cryptodev.c | ||
| 122 | @@ -1367,6 +1367,60 @@ static void zapparams(struct crypt_kop *kop) | ||
| 123 | } | ||
| 124 | } | ||
| 125 | |||
| 126 | +/* | ||
| 127 | + * Any PKC request has at max 2 output parameters and they are stored here to | ||
| 128 | + * be used while copying in the check availability | ||
| 129 | + */ | ||
| 130 | +struct cryptodev_cookie_s { | ||
| 131 | + BIGNUM *r; | ||
| 132 | + struct crparam r_param; | ||
| 133 | + BIGNUM *s; | ||
| 134 | + struct crparam s_param; | ||
| 135 | + struct crypt_kop *kop; | ||
| 136 | +}; | ||
| 137 | + | ||
| 138 | +static int | ||
| 139 | +cryptodev_asym_async(struct crypt_kop *kop, int rlen, BIGNUM *r, int slen, | ||
| 140 | + BIGNUM *s) | ||
| 141 | +{ | ||
| 142 | + int fd; | ||
| 143 | + struct pkc_cookie_s *cookie = kop->cookie; | ||
| 144 | + struct cryptodev_cookie_s *eng_cookie; | ||
| 145 | + | ||
| 146 | + fd = *(int *)cookie->eng_handle; | ||
| 147 | + | ||
| 148 | + eng_cookie = malloc(sizeof(struct cryptodev_cookie_s)); | ||
| 149 | + | ||
| 150 | + if (eng_cookie) { | ||
| 151 | + memset(eng_cookie, 0, sizeof(struct cryptodev_cookie_s)); | ||
| 152 | + if (r) { | ||
| 153 | + kop->crk_param[kop->crk_iparams].crp_p = | ||
| 154 | + calloc(rlen, sizeof(char)); | ||
| 155 | + if (!kop->crk_param[kop->crk_iparams].crp_p) | ||
| 156 | + return -ENOMEM; | ||
| 157 | + kop->crk_param[kop->crk_iparams].crp_nbits = rlen * 8; | ||
| 158 | + kop->crk_oparams++; | ||
| 159 | + eng_cookie->r = r; | ||
| 160 | + eng_cookie->r_param = kop->crk_param[kop->crk_iparams]; | ||
| 161 | + } | ||
| 162 | + if (s) { | ||
| 163 | + kop->crk_param[kop->crk_iparams + 1].crp_p = | ||
| 164 | + calloc(slen, sizeof(char)); | ||
| 165 | + if (!kop->crk_param[kop->crk_iparams + 1].crp_p) | ||
| 166 | + return -ENOMEM; | ||
| 167 | + kop->crk_param[kop->crk_iparams + 1].crp_nbits = slen * 8; | ||
| 168 | + kop->crk_oparams++; | ||
| 169 | + eng_cookie->s = s; | ||
| 170 | + eng_cookie->s_param = kop->crk_param[kop->crk_iparams + 1]; | ||
| 171 | + } | ||
| 172 | + } else | ||
| 173 | + return -ENOMEM; | ||
| 174 | + | ||
| 175 | + eng_cookie->kop = kop; | ||
| 176 | + cookie->eng_cookie = eng_cookie; | ||
| 177 | + return ioctl(fd, CIOCASYMASYNCRYPT, kop); | ||
| 178 | +} | ||
| 179 | + | ||
| 180 | static int | ||
| 181 | cryptodev_asym(struct crypt_kop *kop, int rlen, BIGNUM *r, int slen, | ||
| 182 | BIGNUM *s) | ||
| 183 | @@ -1425,6 +1479,44 @@ void *cryptodev_init_instance(void) | ||
| 184 | return fd; | ||
| 185 | } | ||
| 186 | |||
| 187 | +# include <poll.h> | ||
| 188 | + | ||
| 189 | +/* Return 0 on success and 1 on failure */ | ||
| 190 | +int cryptodev_check_availability(void *eng_handle) | ||
| 191 | +{ | ||
| 192 | + int fd = *(int *)eng_handle; | ||
| 193 | + struct pkc_cookie_list_s cookie_list; | ||
| 194 | + struct pkc_cookie_s *cookie; | ||
| 195 | + int i; | ||
| 196 | + | ||
| 197 | + /* FETCH COOKIE returns number of cookies extracted */ | ||
| 198 | + if (ioctl(fd, CIOCASYMFETCHCOOKIE, &cookie_list) <= 0) | ||
| 199 | + return 1; | ||
| 200 | + | ||
| 201 | + for (i = 0; i < cookie_list.cookie_available; i++) { | ||
| 202 | + cookie = cookie_list.cookie[i]; | ||
| 203 | + if (cookie) { | ||
| 204 | + struct cryptodev_cookie_s *eng_cookie = cookie->eng_cookie; | ||
| 205 | + if (eng_cookie) { | ||
| 206 | + struct crypt_kop *kop = eng_cookie->kop; | ||
| 207 | + | ||
| 208 | + if (eng_cookie->r) | ||
| 209 | + crparam2bn(&eng_cookie->r_param, eng_cookie->r); | ||
| 210 | + if (eng_cookie->s) | ||
| 211 | + crparam2bn(&eng_cookie->s_param, eng_cookie->s); | ||
| 212 | + if (kop->crk_op == CRK_DH_COMPUTE_KEY) | ||
| 213 | + kop->crk_oparams = 0; | ||
| 214 | + | ||
| 215 | + zapparams(eng_cookie->kop); | ||
| 216 | + free(eng_cookie->kop); | ||
| 217 | + free(eng_cookie); | ||
| 218 | + } | ||
| 219 | + cookie->pkc_callback(cookie, cookie_list.status[i]); | ||
| 220 | + } | ||
| 221 | + } | ||
| 222 | + return 0; | ||
| 223 | +} | ||
| 224 | + | ||
| 225 | static int | ||
| 226 | cryptodev_bn_mod_exp(BIGNUM *r, const BIGNUM *a, const BIGNUM *p, | ||
| 227 | const BIGNUM *m, BN_CTX *ctx, BN_MONT_CTX *in_mont) | ||
| 228 | @@ -1472,6 +1564,66 @@ cryptodev_bn_mod_exp(BIGNUM *r, const BIGNUM *a, const BIGNUM *p, | ||
| 229 | } | ||
| 230 | |||
| 231 | static int | ||
| 232 | +cryptodev_bn_mod_exp_async(BIGNUM *r, const BIGNUM *a, const BIGNUM *p, | ||
| 233 | + const BIGNUM *m, BN_CTX *ctx, BN_MONT_CTX *in_mont, | ||
| 234 | + struct pkc_cookie_s *cookie) | ||
| 235 | +{ | ||
| 236 | + struct crypt_kop *kop = malloc(sizeof(struct crypt_kop)); | ||
| 237 | + int ret = 1; | ||
| 238 | + | ||
| 239 | + /* | ||
| 240 | + * Currently, we know we can do mod exp iff we can do any asymmetric | ||
| 241 | + * operations at all. | ||
| 242 | + */ | ||
| 243 | + if (cryptodev_asymfeat == 0 || !kop) { | ||
| 244 | + ret = BN_mod_exp(r, a, p, m, ctx); | ||
| 245 | + return (ret); | ||
| 246 | + } | ||
| 247 | + | ||
| 248 | + kop->crk_oparams = 0; | ||
| 249 | + kop->crk_status = 0; | ||
| 250 | + kop->crk_op = CRK_MOD_EXP; | ||
| 251 | + kop->cookie = cookie; | ||
| 252 | + /* inputs: a^p % m */ | ||
| 253 | + if (bn2crparam(a, &kop->crk_param[0])) | ||
| 254 | + goto err; | ||
| 255 | + if (bn2crparam(p, &kop->crk_param[1])) | ||
| 256 | + goto err; | ||
| 257 | + if (bn2crparam(m, &kop->crk_param[2])) | ||
| 258 | + goto err; | ||
| 259 | + | ||
| 260 | + kop->crk_iparams = 3; | ||
| 261 | + if (cryptodev_asym_async(kop, BN_num_bytes(m), r, 0, NULL)) | ||
| 262 | + goto err; | ||
| 263 | + | ||
| 264 | + return ret; | ||
| 265 | + err: | ||
| 266 | + { | ||
| 267 | + const RSA_METHOD *meth = RSA_PKCS1_SSLeay(); | ||
| 268 | + | ||
| 269 | + if (kop) | ||
| 270 | + free(kop); | ||
| 271 | + ret = meth->bn_mod_exp(r, a, p, m, ctx, in_mont); | ||
| 272 | + if (ret) | ||
| 273 | + /* Call the completion handler immediately */ | ||
| 274 | + cookie->pkc_callback(cookie, 0); | ||
| 275 | + } | ||
| 276 | + return ret; | ||
| 277 | +} | ||
| 278 | + | ||
| 279 | +static int | ||
| 280 | +cryptodev_rsa_nocrt_mod_exp_async(BIGNUM *r0, const BIGNUM *I, | ||
| 281 | + RSA *rsa, BN_CTX *ctx, | ||
| 282 | + struct pkc_cookie_s *cookie) | ||
| 283 | +{ | ||
| 284 | + int r; | ||
| 285 | + ctx = BN_CTX_new(); | ||
| 286 | + r = cryptodev_bn_mod_exp_async(r0, I, rsa->d, rsa->n, ctx, NULL, cookie); | ||
| 287 | + BN_CTX_free(ctx); | ||
| 288 | + return r; | ||
| 289 | +} | ||
| 290 | + | ||
| 291 | +static int | ||
| 292 | cryptodev_rsa_nocrt_mod_exp(BIGNUM *r0, const BIGNUM *I, RSA *rsa, | ||
| 293 | BN_CTX *ctx) | ||
| 294 | { | ||
| 295 | @@ -1538,6 +1690,63 @@ cryptodev_rsa_mod_exp(BIGNUM *r0, const BIGNUM *I, RSA *rsa, BN_CTX *ctx) | ||
| 296 | return (ret); | ||
| 297 | } | ||
| 298 | |||
| 299 | +static int | ||
| 300 | +cryptodev_rsa_mod_exp_async(BIGNUM *r0, const BIGNUM *I, RSA *rsa, | ||
| 301 | + BN_CTX *ctx, struct pkc_cookie_s *cookie) | ||
| 302 | +{ | ||
| 303 | + struct crypt_kop *kop = malloc(sizeof(struct crypt_kop)); | ||
| 304 | + int ret = 1, f_len, p_len, q_len; | ||
| 305 | + unsigned char *f = NULL, *p = NULL, *q = NULL, *dp = NULL, *dq = | ||
| 306 | + NULL, *c = NULL; | ||
| 307 | + | ||
| 308 | + if (!rsa->p || !rsa->q || !rsa->dmp1 || !rsa->dmq1 || !rsa->iqmp || !kop) { | ||
| 309 | + return (0); | ||
| 310 | + } | ||
| 311 | + | ||
| 312 | + kop->crk_oparams = 0; | ||
| 313 | + kop->crk_status = 0; | ||
| 314 | + kop->crk_op = CRK_MOD_EXP_CRT; | ||
| 315 | + f_len = BN_num_bytes(rsa->n); | ||
| 316 | + spcf_bn2bin_ex(I, &f, &f_len); | ||
| 317 | + spcf_bn2bin(rsa->p, &p, &p_len); | ||
| 318 | + spcf_bn2bin(rsa->q, &q, &q_len); | ||
| 319 | + spcf_bn2bin_ex(rsa->dmp1, &dp, &p_len); | ||
| 320 | + spcf_bn2bin_ex(rsa->iqmp, &c, &p_len); | ||
| 321 | + spcf_bn2bin_ex(rsa->dmq1, &dq, &q_len); | ||
| 322 | + /* inputs: rsa->p rsa->q I rsa->dmp1 rsa->dmq1 rsa->iqmp */ | ||
| 323 | + kop->crk_param[0].crp_p = p; | ||
| 324 | + kop->crk_param[0].crp_nbits = p_len * 8; | ||
| 325 | + kop->crk_param[1].crp_p = q; | ||
| 326 | + kop->crk_param[1].crp_nbits = q_len * 8; | ||
| 327 | + kop->crk_param[2].crp_p = f; | ||
| 328 | + kop->crk_param[2].crp_nbits = f_len * 8; | ||
| 329 | + kop->crk_param[3].crp_p = dp; | ||
| 330 | + kop->crk_param[3].crp_nbits = p_len * 8; | ||
| 331 | + /* dq must of length q, rest all of length p */ | ||
| 332 | + kop->crk_param[4].crp_p = dq; | ||
| 333 | + kop->crk_param[4].crp_nbits = q_len * 8; | ||
| 334 | + kop->crk_param[5].crp_p = c; | ||
| 335 | + kop->crk_param[5].crp_nbits = p_len * 8; | ||
| 336 | + kop->crk_iparams = 6; | ||
| 337 | + kop->cookie = cookie; | ||
| 338 | + if (cryptodev_asym_async(kop, BN_num_bytes(rsa->n), r0, 0, NULL)) | ||
| 339 | + goto err; | ||
| 340 | + | ||
| 341 | + return ret; | ||
| 342 | + err: | ||
| 343 | + { | ||
| 344 | + const RSA_METHOD *meth = RSA_PKCS1_SSLeay(); | ||
| 345 | + | ||
| 346 | + if (kop) | ||
| 347 | + free(kop); | ||
| 348 | + ret = (*meth->rsa_mod_exp) (r0, I, rsa, ctx); | ||
| 349 | + if (ret) | ||
| 350 | + /* Call user completion handler immediately */ | ||
| 351 | + cookie->pkc_callback(cookie, 0); | ||
| 352 | + } | ||
| 353 | + return (ret); | ||
| 354 | +} | ||
| 355 | + | ||
| 356 | static RSA_METHOD cryptodev_rsa = { | ||
| 357 | "cryptodev RSA method", | ||
| 358 | NULL, /* rsa_pub_enc */ | ||
| 359 | @@ -1546,6 +1755,12 @@ static RSA_METHOD cryptodev_rsa = { | ||
| 360 | NULL, /* rsa_priv_dec */ | ||
| 361 | NULL, | ||
| 362 | NULL, | ||
| 363 | + NULL, /* rsa_pub_enc */ | ||
| 364 | + NULL, /* rsa_pub_dec */ | ||
| 365 | + NULL, /* rsa_priv_enc */ | ||
| 366 | + NULL, /* rsa_priv_dec */ | ||
| 367 | + NULL, | ||
| 368 | + NULL, | ||
| 369 | NULL, /* init */ | ||
| 370 | NULL, /* finish */ | ||
| 371 | 0, /* flags */ | ||
| 372 | @@ -1846,128 +2061,428 @@ static int cryptodev_dsa_keygen(DSA *dsa) | ||
| 373 | return ret; | ||
| 374 | } | ||
| 375 | |||
| 376 | -static DSA_METHOD cryptodev_dsa = { | ||
| 377 | - "cryptodev DSA method", | ||
| 378 | - NULL, | ||
| 379 | - NULL, /* dsa_sign_setup */ | ||
| 380 | - NULL, | ||
| 381 | - NULL, /* dsa_mod_exp */ | ||
| 382 | - NULL, | ||
| 383 | - NULL, /* init */ | ||
| 384 | - NULL, /* finish */ | ||
| 385 | - 0, /* flags */ | ||
| 386 | - NULL /* app_data */ | ||
| 387 | -}; | ||
| 388 | +/* Cryptodev DSA Key Gen routine */ | ||
| 389 | +static int cryptodev_dsa_keygen_async(DSA *dsa, struct pkc_cookie_s *cookie) | ||
| 390 | +{ | ||
| 391 | + struct crypt_kop *kop = malloc(sizeof(struct crypt_kop)); | ||
| 392 | + int ret = 1, g_len; | ||
| 393 | + unsigned char *g = NULL; | ||
| 394 | |||
| 395 | -static ECDSA_METHOD cryptodev_ecdsa = { | ||
| 396 | - "cryptodev ECDSA method", | ||
| 397 | - NULL, | ||
| 398 | - NULL, /* ecdsa_sign_setup */ | ||
| 399 | - NULL, | ||
| 400 | - NULL, | ||
| 401 | - 0, /* flags */ | ||
| 402 | - NULL /* app_data */ | ||
| 403 | -}; | ||
| 404 | + if (!kop) | ||
| 405 | + goto sw_try; | ||
| 406 | |||
| 407 | -typedef enum ec_curve_s { | ||
| 408 | - EC_PRIME, | ||
| 409 | - EC_BINARY | ||
| 410 | -} ec_curve_t; | ||
| 411 | + if (dsa->priv_key == NULL) { | ||
| 412 | + if ((dsa->priv_key = BN_new()) == NULL) | ||
| 413 | + goto sw_try; | ||
| 414 | + } | ||
| 415 | |||
| 416 | -/* ENGINE handler for ECDSA Sign */ | ||
| 417 | -static ECDSA_SIG *cryptodev_ecdsa_do_sign(const unsigned char *dgst, | ||
| 418 | - int dgst_len, const BIGNUM *in_kinv, | ||
| 419 | - const BIGNUM *in_r, EC_KEY *eckey) | ||
| 420 | -{ | ||
| 421 | - BIGNUM *m = NULL, *p = NULL, *a = NULL; | ||
| 422 | - BIGNUM *b = NULL, *x = NULL, *y = NULL; | ||
| 423 | - BN_CTX *ctx = NULL; | ||
| 424 | - ECDSA_SIG *ret = NULL; | ||
| 425 | - ECDSA_DATA *ecdsa = NULL; | ||
| 426 | - unsigned char *q = NULL, *r = NULL, *ab = NULL, *g_xy = NULL; | ||
| 427 | - unsigned char *s = NULL, *c = NULL, *d = NULL, *f = NULL, *tmp_dgst = | ||
| 428 | - NULL; | ||
| 429 | - int i = 0, q_len = 0, priv_key_len = 0, r_len = 0; | ||
| 430 | - int g_len = 0, d_len = 0, ab_len = 0; | ||
| 431 | - const BIGNUM *order = NULL, *priv_key = NULL; | ||
| 432 | - const EC_GROUP *group = NULL; | ||
| 433 | - struct crypt_kop kop; | ||
| 434 | - ec_curve_t ec_crv = EC_PRIME; | ||
| 435 | + if (dsa->pub_key == NULL) { | ||
| 436 | + if ((dsa->pub_key = BN_new()) == NULL) | ||
| 437 | + goto sw_try; | ||
| 438 | + } | ||
| 439 | |||
| 440 | - memset(&kop, 0, sizeof(kop)); | ||
| 441 | - ecdsa = ecdsa_check(eckey); | ||
| 442 | - if (!ecdsa) { | ||
| 443 | - ECDSAerr(ECDSA_F_ECDSA_DO_SIGN, ERR_R_PASSED_NULL_PARAMETER); | ||
| 444 | - return NULL; | ||
| 445 | + g_len = BN_num_bytes(dsa->p); | ||
| 446 | + /** | ||
| 447 | + * Get generator into a plain buffer. If length is less than | ||
| 448 | + * q_len then add leading padding bytes. | ||
| 449 | + */ | ||
| 450 | + if (spcf_bn2bin_ex(dsa->g, &g, &g_len)) { | ||
| 451 | + DSAerr(DSA_F_DSA_GENERATE_KEY, ERR_R_MALLOC_FAILURE); | ||
| 452 | + goto sw_try; | ||
| 453 | } | ||
| 454 | |||
| 455 | - group = EC_KEY_get0_group(eckey); | ||
| 456 | - priv_key = EC_KEY_get0_private_key(eckey); | ||
| 457 | + memset(kop, 0, sizeof(struct crypt_kop)); | ||
| 458 | + kop->crk_op = CRK_DSA_GENERATE_KEY; | ||
| 459 | + if (bn2crparam(dsa->p, &kop->crk_param[0])) | ||
| 460 | + goto sw_try; | ||
| 461 | + if (bn2crparam(dsa->q, &kop->crk_param[1])) | ||
| 462 | + goto sw_try; | ||
| 463 | + kop->crk_param[2].crp_p = g; | ||
| 464 | + kop->crk_param[2].crp_nbits = g_len * 8; | ||
| 465 | + kop->crk_iparams = 3; | ||
| 466 | + kop->cookie = cookie; | ||
| 467 | |||
| 468 | - if (!group || !priv_key) { | ||
| 469 | - ECDSAerr(ECDSA_F_ECDSA_DO_SIGN, ERR_R_PASSED_NULL_PARAMETER); | ||
| 470 | - return NULL; | ||
| 471 | + /* pub_key is or prime length while priv key is of length of order */ | ||
| 472 | + if (cryptodev_asym_async(kop, BN_num_bytes(dsa->p), dsa->pub_key, | ||
| 473 | + BN_num_bytes(dsa->q), dsa->priv_key)) | ||
| 474 | + goto sw_try; | ||
| 475 | + | ||
| 476 | + return ret; | ||
| 477 | + sw_try: | ||
| 478 | + { | ||
| 479 | + const DSA_METHOD *meth = DSA_OpenSSL(); | ||
| 480 | + | ||
| 481 | + if (kop) | ||
| 482 | + free(kop); | ||
| 483 | + ret = (meth->dsa_keygen) (dsa); | ||
| 484 | + cookie->pkc_callback(cookie, 0); | ||
| 485 | } | ||
| 486 | + return ret; | ||
| 487 | +} | ||
| 488 | |||
| 489 | - if ((ctx = BN_CTX_new()) == NULL || (m = BN_new()) == NULL || | ||
| 490 | - (a = BN_new()) == NULL || (b = BN_new()) == NULL || | ||
| 491 | - (p = BN_new()) == NULL || (x = BN_new()) == NULL || | ||
| 492 | - (y = BN_new()) == NULL) { | ||
| 493 | - ECDSAerr(ECDSA_F_ECDSA_DO_SIGN, ERR_R_MALLOC_FAILURE); | ||
| 494 | +static int | ||
| 495 | +cryptodev_dsa_do_sign_async(const unsigned char *dgst, int dlen, DSA *dsa, | ||
| 496 | + DSA_SIG *sig, struct pkc_cookie_s *cookie) | ||
| 497 | +{ | ||
| 498 | + struct crypt_kop *kop = malloc(sizeof(struct crypt_kop)); | ||
| 499 | + DSA_SIG *dsaret = NULL; | ||
| 500 | + int q_len = 0, r_len = 0, g_len = 0; | ||
| 501 | + int priv_key_len = 0, ret = 1; | ||
| 502 | + unsigned char *q = NULL, *r = NULL, *g = NULL, *priv_key = NULL, *f = | ||
| 503 | + NULL; | ||
| 504 | + if (((sig->r = BN_new()) == NULL) || !kop) { | ||
| 505 | + DSAerr(DSA_F_DSA_DO_SIGN, ERR_R_MALLOC_FAILURE); | ||
| 506 | goto err; | ||
| 507 | } | ||
| 508 | |||
| 509 | - order = &group->order; | ||
| 510 | - if (!order || BN_is_zero(order)) { | ||
| 511 | - ECDSAerr(ECDSA_F_ECDSA_DO_SIGN, ECDSA_R_MISSING_PARAMETERS); | ||
| 512 | + if ((sig->s = BN_new()) == NULL) { | ||
| 513 | + BN_free(sig->r); | ||
| 514 | + DSAerr(DSA_F_DSA_DO_SIGN, ERR_R_MALLOC_FAILURE); | ||
| 515 | goto err; | ||
| 516 | } | ||
| 517 | |||
| 518 | - i = BN_num_bits(order); | ||
| 519 | - /* | ||
| 520 | - * Need to truncate digest if it is too long: first truncate whole bytes | ||
| 521 | - */ | ||
| 522 | - if (8 * dgst_len > i) | ||
| 523 | - dgst_len = (i + 7) / 8; | ||
| 524 | - | ||
| 525 | - if (!BN_bin2bn(dgst, dgst_len, m)) { | ||
| 526 | - ECDSAerr(ECDSA_F_ECDSA_DO_SIGN, ERR_R_BN_LIB); | ||
| 527 | + if (spcf_bn2bin(dsa->p, &q, &q_len)) { | ||
| 528 | + DSAerr(DSA_F_DSA_DO_SIGN, DSA_R_DATA_TOO_LARGE_FOR_KEY_SIZE); | ||
| 529 | goto err; | ||
| 530 | } | ||
| 531 | |||
| 532 | - /* If still too long truncate remaining bits with a shift */ | ||
| 533 | - if ((8 * dgst_len > i) && !BN_rshift(m, m, 8 - (i & 0x7))) { | ||
| 534 | - ECDSAerr(ECDSA_F_ECDSA_DO_SIGN, ERR_R_BN_LIB); | ||
| 535 | + /* Get order of the field of private keys into plain buffer */ | ||
| 536 | + if (spcf_bn2bin(dsa->q, &r, &r_len)) { | ||
| 537 | + DSAerr(DSA_F_DSA_DO_SIGN, ERR_R_MALLOC_FAILURE); | ||
| 538 | goto err; | ||
| 539 | } | ||
| 540 | |||
| 541 | - /* copy the truncated bits into plain buffer */ | ||
| 542 | - if (spcf_bn2bin(m, &tmp_dgst, &dgst_len)) { | ||
| 543 | - fprintf(stderr, "%s:%d: OPENSSL_malloc failec\n", __FUNCTION__, | ||
| 544 | - __LINE__); | ||
| 545 | + /* sanity test */ | ||
| 546 | + if (dlen > r_len) { | ||
| 547 | + DSAerr(DSA_F_DSA_DO_SIGN, DSA_R_DATA_TOO_LARGE_FOR_KEY_SIZE); | ||
| 548 | goto err; | ||
| 549 | } | ||
| 550 | |||
| 551 | - ret = ECDSA_SIG_new(); | ||
| 552 | - if (!ret) { | ||
| 553 | - ECDSAerr(ECDSA_F_ECDSA_DO_SIGN, ERR_R_BN_LIB); | ||
| 554 | + g_len = q_len; | ||
| 555 | + /** | ||
| 556 | + * Get generator into a plain buffer. If length is less than | ||
| 557 | + * q_len then add leading padding bytes. | ||
| 558 | + */ | ||
| 559 | + if (spcf_bn2bin_ex(dsa->g, &g, &g_len)) { | ||
| 560 | + DSAerr(DSA_F_DSA_DO_SIGN, ERR_R_MALLOC_FAILURE); | ||
| 561 | goto err; | ||
| 562 | } | ||
| 563 | |||
| 564 | - /* check if this is prime or binary EC request */ | ||
| 565 | - if (EC_METHOD_get_field_type(EC_GROUP_method_of(group)) == | ||
| 566 | - NID_X9_62_prime_field) { | ||
| 567 | - ec_crv = EC_PRIME; | ||
| 568 | - /* get the generator point pair */ | ||
| 569 | - if (!EC_POINT_get_affine_coordinates_GFp | ||
| 570 | - (group, EC_GROUP_get0_generator(group), x, y, ctx)) { | ||
| 571 | - ECDSAerr(ECDSA_F_ECDSA_DO_SIGN, ERR_R_EC_LIB); | ||
| 572 | - goto err; | ||
| 573 | - } | ||
| 574 | + priv_key_len = r_len; | ||
| 575 | + /** | ||
| 576 | + * Get private key into a plain buffer. If length is less than | ||
| 577 | + * r_len then add leading padding bytes. | ||
| 578 | + */ | ||
| 579 | + if (spcf_bn2bin_ex(dsa->priv_key, &priv_key, &priv_key_len)) { | ||
| 580 | + DSAerr(DSA_F_DSA_DO_SIGN, ERR_R_MALLOC_FAILURE); | ||
| 581 | + goto err; | ||
| 582 | + } | ||
| 583 | |||
| 584 | - /* get the ECC curve parameters */ | ||
| 585 | - if (!EC_GROUP_get_curve_GFp(group, p, a, b, ctx)) { | ||
| 586 | - ECDSAerr(ECDSA_F_ECDSA_DO_SIGN, ERR_R_EC_LIB); | ||
| 587 | + /* Allocate memory to store hash. */ | ||
| 588 | + f = OPENSSL_malloc(r_len); | ||
| 589 | + if (!f) { | ||
| 590 | + DSAerr(DSA_F_DSA_DO_SIGN, ERR_R_MALLOC_FAILURE); | ||
| 591 | + goto err; | ||
| 592 | + } | ||
| 593 | + | ||
| 594 | + /* Add padding, since SEC expects hash to of size r_len */ | ||
| 595 | + if (dlen < r_len) | ||
| 596 | + memset(f, 0, r_len - dlen); | ||
| 597 | + | ||
| 598 | + /* Skip leading bytes if dgst_len < r_len */ | ||
| 599 | + memcpy(f + r_len - dlen, dgst, dlen); | ||
| 600 | + | ||
| 601 | + dlen = r_len; | ||
| 602 | + | ||
| 603 | + memset(kop, 0, sizeof(struct crypt_kop)); | ||
| 604 | + kop->crk_op = CRK_DSA_SIGN; | ||
| 605 | + | ||
| 606 | + /* inputs: dgst dsa->p dsa->q dsa->g dsa->priv_key */ | ||
| 607 | + kop->crk_param[0].crp_p = (void *)f; | ||
| 608 | + kop->crk_param[0].crp_nbits = dlen * 8; | ||
| 609 | + kop->crk_param[1].crp_p = (void *)q; | ||
| 610 | + kop->crk_param[1].crp_nbits = q_len * 8; | ||
| 611 | + kop->crk_param[2].crp_p = (void *)r; | ||
| 612 | + kop->crk_param[2].crp_nbits = r_len * 8; | ||
| 613 | + kop->crk_param[3].crp_p = (void *)g; | ||
| 614 | + kop->crk_param[3].crp_nbits = g_len * 8; | ||
| 615 | + kop->crk_param[4].crp_p = (void *)priv_key; | ||
| 616 | + kop->crk_param[4].crp_nbits = priv_key_len * 8; | ||
| 617 | + kop->crk_iparams = 5; | ||
| 618 | + kop->cookie = cookie; | ||
| 619 | + | ||
| 620 | + if (cryptodev_asym_async(kop, r_len, sig->r, r_len, sig->s)) | ||
| 621 | + goto err; | ||
| 622 | + | ||
| 623 | + return ret; | ||
| 624 | + err: | ||
| 625 | + { | ||
| 626 | + const DSA_METHOD *meth = DSA_OpenSSL(); | ||
| 627 | + | ||
| 628 | + if (kop) | ||
| 629 | + free(kop); | ||
| 630 | + BN_free(sig->r); | ||
| 631 | + BN_free(sig->s); | ||
| 632 | + dsaret = (meth->dsa_do_sign) (dgst, dlen, dsa); | ||
| 633 | + sig->r = dsaret->r; | ||
| 634 | + sig->s = dsaret->s; | ||
| 635 | + /* Call user callback immediately */ | ||
| 636 | + cookie->pkc_callback(cookie, 0); | ||
| 637 | + ret = dsaret; | ||
| 638 | + } | ||
| 639 | + return ret; | ||
| 640 | +} | ||
| 641 | + | ||
| 642 | +static int | ||
| 643 | +cryptodev_dsa_verify_async(const unsigned char *dgst, int dlen, | ||
| 644 | + DSA_SIG *sig, DSA *dsa, | ||
| 645 | + struct pkc_cookie_s *cookie) | ||
| 646 | +{ | ||
| 647 | + struct crypt_kop *kop = malloc(sizeof(struct crypt_kop)); | ||
| 648 | + int q_len = 0, r_len = 0, g_len = 0; | ||
| 649 | + int w_len = 0, c_len = 0, d_len = 0, ret = 1; | ||
| 650 | + unsigned char *q = NULL, *r = NULL, *w = NULL, *g = NULL; | ||
| 651 | + unsigned char *c = NULL, *d = NULL, *f = NULL; | ||
| 652 | + | ||
| 653 | + if (!kop) | ||
| 654 | + goto err; | ||
| 655 | + | ||
| 656 | + if (spcf_bn2bin(dsa->p, &q, &q_len)) { | ||
| 657 | + DSAerr(DSA_F_DSA_DO_VERIFY, ERR_R_MALLOC_FAILURE); | ||
| 658 | + return ret; | ||
| 659 | + } | ||
| 660 | + | ||
| 661 | + /* Get Order of field of private keys */ | ||
| 662 | + if (spcf_bn2bin(dsa->q, &r, &r_len)) { | ||
| 663 | + DSAerr(DSA_F_DSA_DO_VERIFY, ERR_R_MALLOC_FAILURE); | ||
| 664 | + goto err; | ||
| 665 | + } | ||
| 666 | + | ||
| 667 | + g_len = q_len; | ||
| 668 | + /** | ||
| 669 | + * Get generator into a plain buffer. If length is less than | ||
| 670 | + * q_len then add leading padding bytes. | ||
| 671 | + */ | ||
| 672 | + if (spcf_bn2bin_ex(dsa->g, &g, &g_len)) { | ||
| 673 | + DSAerr(DSA_F_DSA_DO_VERIFY, ERR_R_MALLOC_FAILURE); | ||
| 674 | + goto err; | ||
| 675 | + } | ||
| 676 | + w_len = q_len; | ||
| 677 | + /** | ||
| 678 | + * Get public key into a plain buffer. If length is less than | ||
| 679 | + * q_len then add leading padding bytes. | ||
| 680 | + */ | ||
| 681 | + if (spcf_bn2bin_ex(dsa->pub_key, &w, &w_len)) { | ||
| 682 | + DSAerr(DSA_F_DSA_DO_VERIFY, ERR_R_MALLOC_FAILURE); | ||
| 683 | + goto err; | ||
| 684 | + } | ||
| 685 | + /** | ||
| 686 | + * Get the 1st part of signature into a flat buffer with | ||
| 687 | + * appropriate padding | ||
| 688 | + */ | ||
| 689 | + c_len = r_len; | ||
| 690 | + | ||
| 691 | + if (spcf_bn2bin_ex(sig->r, &c, &c_len)) { | ||
| 692 | + ECDSAerr(ECDSA_F_ECDSA_DO_VERIFY, ERR_R_MALLOC_FAILURE); | ||
| 693 | + goto err; | ||
| 694 | + } | ||
| 695 | + | ||
| 696 | + /** | ||
| 697 | + * Get the 2nd part of signature into a flat buffer with | ||
| 698 | + * appropriate padding | ||
| 699 | + */ | ||
| 700 | + d_len = r_len; | ||
| 701 | + | ||
| 702 | + if (spcf_bn2bin_ex(sig->s, &d, &d_len)) { | ||
| 703 | + ECDSAerr(ECDSA_F_ECDSA_DO_VERIFY, ERR_R_MALLOC_FAILURE); | ||
| 704 | + goto err; | ||
| 705 | + } | ||
| 706 | + | ||
| 707 | + /* Sanity test */ | ||
| 708 | + if (dlen > r_len) { | ||
| 709 | + ECDSAerr(ECDSA_F_ECDSA_DO_VERIFY, ERR_R_MALLOC_FAILURE); | ||
| 710 | + goto err; | ||
| 711 | + } | ||
| 712 | + | ||
| 713 | + /* Allocate memory to store hash. */ | ||
| 714 | + f = OPENSSL_malloc(r_len); | ||
| 715 | + if (!f) { | ||
| 716 | + DSAerr(ECDSA_F_ECDSA_DO_VERIFY, ERR_R_MALLOC_FAILURE); | ||
| 717 | + goto err; | ||
| 718 | + } | ||
| 719 | + | ||
| 720 | + /* Add padding, since SEC expects hash to of size r_len */ | ||
| 721 | + if (dlen < r_len) | ||
| 722 | + memset(f, 0, r_len - dlen); | ||
| 723 | + | ||
| 724 | + /* Skip leading bytes if dgst_len < r_len */ | ||
| 725 | + memcpy(f + r_len - dlen, dgst, dlen); | ||
| 726 | + | ||
| 727 | + dlen = r_len; | ||
| 728 | + memset(kop, 0, sizeof(struct crypt_kop)); | ||
| 729 | + | ||
| 730 | + /* inputs: dgst dsa->p dsa->q dsa->g dsa->pub_key sig->r sig->s */ | ||
| 731 | + kop->crk_param[0].crp_p = (void *)f; | ||
| 732 | + kop->crk_param[0].crp_nbits = dlen * 8; | ||
| 733 | + kop->crk_param[1].crp_p = q; | ||
| 734 | + kop->crk_param[1].crp_nbits = q_len * 8; | ||
| 735 | + kop->crk_param[2].crp_p = r; | ||
| 736 | + kop->crk_param[2].crp_nbits = r_len * 8; | ||
| 737 | + kop->crk_param[3].crp_p = g; | ||
| 738 | + kop->crk_param[3].crp_nbits = g_len * 8; | ||
| 739 | + kop->crk_param[4].crp_p = w; | ||
| 740 | + kop->crk_param[4].crp_nbits = w_len * 8; | ||
| 741 | + kop->crk_param[5].crp_p = c; | ||
| 742 | + kop->crk_param[5].crp_nbits = c_len * 8; | ||
| 743 | + kop->crk_param[6].crp_p = d; | ||
| 744 | + kop->crk_param[6].crp_nbits = d_len * 8; | ||
| 745 | + kop->crk_iparams = 7; | ||
| 746 | + kop->crk_op = CRK_DSA_VERIFY; | ||
| 747 | + kop->cookie = cookie; | ||
| 748 | + if (cryptodev_asym_async(kop, 0, NULL, 0, NULL)) | ||
| 749 | + goto err; | ||
| 750 | + | ||
| 751 | + return ret; | ||
| 752 | + err: | ||
| 753 | + { | ||
| 754 | + const DSA_METHOD *meth = DSA_OpenSSL(); | ||
| 755 | + | ||
| 756 | + if (kop) | ||
| 757 | + free(kop); | ||
| 758 | + | ||
| 759 | + ret = (meth->dsa_do_verify) (dgst, dlen, sig, dsa); | ||
| 760 | + cookie->pkc_callback(cookie, 0); | ||
| 761 | + } | ||
| 762 | + return ret; | ||
| 763 | +} | ||
| 764 | + | ||
| 765 | +static DSA_METHOD cryptodev_dsa = { | ||
| 766 | + "cryptodev DSA method", | ||
| 767 | + NULL, | ||
| 768 | + NULL, /* dsa_sign_setup */ | ||
| 769 | + NULL, | ||
| 770 | + NULL, /* dsa_mod_exp */ | ||
| 771 | + NULL, | ||
| 772 | + NULL, | ||
| 773 | + NULL, | ||
| 774 | + NULL, | ||
| 775 | + NULL, /* init */ | ||
| 776 | + NULL, /* finish */ | ||
| 777 | + 0, /* flags */ | ||
| 778 | + NULL /* app_data */ | ||
| 779 | +}; | ||
| 780 | + | ||
| 781 | +static ECDSA_METHOD cryptodev_ecdsa = { | ||
| 782 | + "cryptodev ECDSA method", | ||
| 783 | + NULL, | ||
| 784 | + NULL, /* ecdsa_sign_setup */ | ||
| 785 | + NULL, | ||
| 786 | + NULL, | ||
| 787 | + NULL, | ||
| 788 | + NULL, | ||
| 789 | + 0, /* flags */ | ||
| 790 | + NULL /* app_data */ | ||
| 791 | +}; | ||
| 792 | + | ||
| 793 | +typedef enum ec_curve_s { | ||
| 794 | + EC_PRIME, | ||
| 795 | + EC_BINARY | ||
| 796 | +} ec_curve_t; | ||
| 797 | + | ||
| 798 | +/* ENGINE handler for ECDSA Sign */ | ||
| 799 | +static ECDSA_SIG *cryptodev_ecdsa_do_sign(const unsigned char *dgst, | ||
| 800 | + int dgst_len, const BIGNUM *in_kinv, | ||
| 801 | + const BIGNUM *in_r, EC_KEY *eckey) | ||
| 802 | +{ | ||
| 803 | + BIGNUM *m = NULL, *p = NULL, *a = NULL; | ||
| 804 | + BIGNUM *b = NULL, *x = NULL, *y = NULL; | ||
| 805 | + BN_CTX *ctx = NULL; | ||
| 806 | + ECDSA_SIG *ret = NULL; | ||
| 807 | + ECDSA_DATA *ecdsa = NULL; | ||
| 808 | + unsigned char *q = NULL, *r = NULL, *ab = NULL, *g_xy = NULL; | ||
| 809 | + unsigned char *s = NULL, *c = NULL, *d = NULL, *f = NULL, *tmp_dgst = | ||
| 810 | + NULL; | ||
| 811 | + int i = 0, q_len = 0, priv_key_len = 0, r_len = 0; | ||
| 812 | + int g_len = 0, d_len = 0, ab_len = 0; | ||
| 813 | + const BIGNUM *order = NULL, *priv_key = NULL; | ||
| 814 | + const EC_GROUP *group = NULL; | ||
| 815 | + struct crypt_kop kop; | ||
| 816 | + ec_curve_t ec_crv = EC_PRIME; | ||
| 817 | + | ||
| 818 | + memset(&kop, 0, sizeof(kop)); | ||
| 819 | + ecdsa = ecdsa_check(eckey); | ||
| 820 | + if (!ecdsa) { | ||
| 821 | + ECDSAerr(ECDSA_F_ECDSA_DO_SIGN, ERR_R_PASSED_NULL_PARAMETER); | ||
| 822 | + return NULL; | ||
| 823 | + } | ||
| 824 | + | ||
| 825 | + group = EC_KEY_get0_group(eckey); | ||
| 826 | + priv_key = EC_KEY_get0_private_key(eckey); | ||
| 827 | + | ||
| 828 | + if (!group || !priv_key) { | ||
| 829 | + ECDSAerr(ECDSA_F_ECDSA_DO_SIGN, ERR_R_PASSED_NULL_PARAMETER); | ||
| 830 | + return NULL; | ||
| 831 | + } | ||
| 832 | + | ||
| 833 | + if ((ctx = BN_CTX_new()) == NULL || (m = BN_new()) == NULL || | ||
| 834 | + (a = BN_new()) == NULL || (b = BN_new()) == NULL || | ||
| 835 | + (p = BN_new()) == NULL || (x = BN_new()) == NULL || | ||
| 836 | + (y = BN_new()) == NULL) { | ||
| 837 | + ECDSAerr(ECDSA_F_ECDSA_DO_SIGN, ERR_R_MALLOC_FAILURE); | ||
| 838 | + goto err; | ||
| 839 | + } | ||
| 840 | + | ||
| 841 | + order = &group->order; | ||
| 842 | + if (!order || BN_is_zero(order)) { | ||
| 843 | + ECDSAerr(ECDSA_F_ECDSA_DO_SIGN, ECDSA_R_MISSING_PARAMETERS); | ||
| 844 | + goto err; | ||
| 845 | + } | ||
| 846 | + | ||
| 847 | + i = BN_num_bits(order); | ||
| 848 | + /* | ||
| 849 | + * Need to truncate digest if it is too long: first truncate whole bytes | ||
| 850 | + */ | ||
| 851 | + if (8 * dgst_len > i) | ||
| 852 | + dgst_len = (i + 7) / 8; | ||
| 853 | + | ||
| 854 | + if (!BN_bin2bn(dgst, dgst_len, m)) { | ||
| 855 | + ECDSAerr(ECDSA_F_ECDSA_DO_SIGN, ERR_R_BN_LIB); | ||
| 856 | + goto err; | ||
| 857 | + } | ||
| 858 | + | ||
| 859 | + /* If still too long truncate remaining bits with a shift */ | ||
| 860 | + if ((8 * dgst_len > i) && !BN_rshift(m, m, 8 - (i & 0x7))) { | ||
| 861 | + ECDSAerr(ECDSA_F_ECDSA_DO_SIGN, ERR_R_BN_LIB); | ||
| 862 | + goto err; | ||
| 863 | + } | ||
| 864 | + | ||
| 865 | + /* copy the truncated bits into plain buffer */ | ||
| 866 | + if (spcf_bn2bin(m, &tmp_dgst, &dgst_len)) { | ||
| 867 | + fprintf(stderr, "%s:%d: OPENSSL_malloc failec\n", __FUNCTION__, | ||
| 868 | + __LINE__); | ||
| 869 | + goto err; | ||
| 870 | + } | ||
| 871 | + | ||
| 872 | + ret = ECDSA_SIG_new(); | ||
| 873 | + if (!ret) { | ||
| 874 | + ECDSAerr(ECDSA_F_ECDSA_DO_SIGN, ERR_R_BN_LIB); | ||
| 875 | + goto err; | ||
| 876 | + } | ||
| 877 | + | ||
| 878 | + /* check if this is prime or binary EC request */ | ||
| 879 | + if (EC_METHOD_get_field_type(EC_GROUP_method_of(group)) == | ||
| 880 | + NID_X9_62_prime_field) { | ||
| 881 | + ec_crv = EC_PRIME; | ||
| 882 | + /* get the generator point pair */ | ||
| 883 | + if (!EC_POINT_get_affine_coordinates_GFp | ||
| 884 | + (group, EC_GROUP_get0_generator(group), x, y, ctx)) { | ||
| 885 | + ECDSAerr(ECDSA_F_ECDSA_DO_SIGN, ERR_R_EC_LIB); | ||
| 886 | + goto err; | ||
| 887 | + } | ||
| 888 | + | ||
| 889 | + /* get the ECC curve parameters */ | ||
| 890 | + if (!EC_GROUP_get_curve_GFp(group, p, a, b, ctx)) { | ||
| 891 | + ECDSAerr(ECDSA_F_ECDSA_DO_SIGN, ERR_R_EC_LIB); | ||
| 892 | goto err; | ||
| 893 | } | ||
| 894 | } else if (EC_METHOD_get_field_type(EC_GROUP_method_of(group)) == | ||
| 895 | @@ -2312,54 +2827,588 @@ static int cryptodev_ecdsa_verify(const unsigned char *dgst, int dgst_len, | ||
| 896 | goto err; | ||
| 897 | } | ||
| 898 | |||
| 899 | - /* memory for message representative */ | ||
| 900 | - f = malloc(r_len); | ||
| 901 | - if (!f) { | ||
| 902 | - ECDSAerr(ECDSA_F_ECDSA_DO_VERIFY, ERR_R_MALLOC_FAILURE); | ||
| 903 | - goto err; | ||
| 904 | + /* memory for message representative */ | ||
| 905 | + f = malloc(r_len); | ||
| 906 | + if (!f) { | ||
| 907 | + ECDSAerr(ECDSA_F_ECDSA_DO_VERIFY, ERR_R_MALLOC_FAILURE); | ||
| 908 | + goto err; | ||
| 909 | + } | ||
| 910 | + | ||
| 911 | + /* Add padding, since SEC expects hash to of size r_len */ | ||
| 912 | + memset(f, 0, r_len - dgst_len); | ||
| 913 | + | ||
| 914 | + /* Skip leading bytes if dgst_len < r_len */ | ||
| 915 | + memcpy(f + r_len - dgst_len, tmp_dgst, dgst_len); | ||
| 916 | + dgst_len += r_len - dgst_len; | ||
| 917 | + kop.crk_op = CRK_DSA_VERIFY; | ||
| 918 | + /* inputs: dgst dsa->p dsa->q dsa->g dsa->priv_key */ | ||
| 919 | + kop.crk_param[0].crp_p = f; | ||
| 920 | + kop.crk_param[0].crp_nbits = dgst_len * 8; | ||
| 921 | + kop.crk_param[1].crp_p = q; | ||
| 922 | + kop.crk_param[1].crp_nbits = q_len * 8; | ||
| 923 | + kop.crk_param[2].crp_p = r; | ||
| 924 | + kop.crk_param[2].crp_nbits = r_len * 8; | ||
| 925 | + kop.crk_param[3].crp_p = g_xy; | ||
| 926 | + kop.crk_param[3].crp_nbits = g_len * 8; | ||
| 927 | + kop.crk_param[4].crp_p = w_xy; | ||
| 928 | + kop.crk_param[4].crp_nbits = pub_key_len * 8; | ||
| 929 | + kop.crk_param[5].crp_p = ab; | ||
| 930 | + kop.crk_param[5].crp_nbits = ab_len * 8; | ||
| 931 | + kop.crk_param[6].crp_p = c; | ||
| 932 | + kop.crk_param[6].crp_nbits = d_len * 8; | ||
| 933 | + kop.crk_param[7].crp_p = d; | ||
| 934 | + kop.crk_param[7].crp_nbits = d_len * 8; | ||
| 935 | + kop.crk_iparams = 8; | ||
| 936 | + | ||
| 937 | + if (cryptodev_asym(&kop, 0, NULL, 0, NULL) == 0) { | ||
| 938 | + /* | ||
| 939 | + * OCF success value is 0, if not zero, change ret to fail | ||
| 940 | + */ | ||
| 941 | + if (0 == kop.crk_status) | ||
| 942 | + ret = 1; | ||
| 943 | + } else { | ||
| 944 | + const ECDSA_METHOD *meth = ECDSA_OpenSSL(); | ||
| 945 | + | ||
| 946 | + ret = (meth->ecdsa_do_verify) (dgst, dgst_len, sig, eckey); | ||
| 947 | + } | ||
| 948 | + kop.crk_param[0].crp_p = NULL; | ||
| 949 | + zapparams(&kop); | ||
| 950 | + | ||
| 951 | + err: | ||
| 952 | + return ret; | ||
| 953 | +} | ||
| 954 | + | ||
| 955 | +static int cryptodev_ecdsa_do_sign_async(const unsigned char *dgst, | ||
| 956 | + int dgst_len, const BIGNUM *in_kinv, | ||
| 957 | + const BIGNUM *in_r, EC_KEY *eckey, | ||
| 958 | + ECDSA_SIG *sig, | ||
| 959 | + struct pkc_cookie_s *cookie) | ||
| 960 | +{ | ||
| 961 | + BIGNUM *m = NULL, *p = NULL, *a = NULL; | ||
| 962 | + BIGNUM *b = NULL, *x = NULL, *y = NULL; | ||
| 963 | + BN_CTX *ctx = NULL; | ||
| 964 | + ECDSA_SIG *sig_ret = NULL; | ||
| 965 | + ECDSA_DATA *ecdsa = NULL; | ||
| 966 | + unsigned char *q = NULL, *r = NULL, *ab = NULL, *g_xy = NULL; | ||
| 967 | + unsigned char *s = NULL, *f = NULL, *tmp_dgst = NULL; | ||
| 968 | + int i = 0, q_len = 0, priv_key_len = 0, r_len = 0; | ||
| 969 | + int g_len = 0, ab_len = 0, ret = 1; | ||
| 970 | + const BIGNUM *order = NULL, *priv_key = NULL; | ||
| 971 | + const EC_GROUP *group = NULL; | ||
| 972 | + struct crypt_kop *kop = malloc(sizeof(struct crypt_kop)); | ||
| 973 | + ec_curve_t ec_crv = EC_PRIME; | ||
| 974 | + | ||
| 975 | + if (!(sig->r = BN_new()) || !kop) | ||
| 976 | + goto err; | ||
| 977 | + if ((sig->s = BN_new()) == NULL) { | ||
| 978 | + BN_free(r); | ||
| 979 | + goto err; | ||
| 980 | + } | ||
| 981 | + | ||
| 982 | + memset(kop, 0, sizeof(struct crypt_kop)); | ||
| 983 | + ecdsa = ecdsa_check(eckey); | ||
| 984 | + if (!ecdsa) { | ||
| 985 | + ECDSAerr(ECDSA_F_ECDSA_DO_SIGN, ERR_R_PASSED_NULL_PARAMETER); | ||
| 986 | + goto err; | ||
| 987 | + } | ||
| 988 | + | ||
| 989 | + group = EC_KEY_get0_group(eckey); | ||
| 990 | + priv_key = EC_KEY_get0_private_key(eckey); | ||
| 991 | + | ||
| 992 | + if (!group || !priv_key) { | ||
| 993 | + ECDSAerr(ECDSA_F_ECDSA_DO_SIGN, ERR_R_PASSED_NULL_PARAMETER); | ||
| 994 | + goto err; | ||
| 995 | + } | ||
| 996 | + | ||
| 997 | + if ((ctx = BN_CTX_new()) == NULL || (m = BN_new()) == NULL || | ||
| 998 | + (a = BN_new()) == NULL || (b = BN_new()) == NULL || | ||
| 999 | + (p = BN_new()) == NULL || (x = BN_new()) == NULL || | ||
| 1000 | + (y = BN_new()) == NULL) { | ||
| 1001 | + ECDSAerr(ECDSA_F_ECDSA_DO_SIGN, ERR_R_MALLOC_FAILURE); | ||
| 1002 | + goto err; | ||
| 1003 | + } | ||
| 1004 | + | ||
| 1005 | + order = &group->order; | ||
| 1006 | + if (!order || BN_is_zero(order)) { | ||
| 1007 | + ECDSAerr(ECDSA_F_ECDSA_DO_SIGN, ECDSA_R_MISSING_PARAMETERS); | ||
| 1008 | + goto err; | ||
| 1009 | + } | ||
| 1010 | + | ||
| 1011 | + i = BN_num_bits(order); | ||
| 1012 | + /* | ||
| 1013 | + * Need to truncate digest if it is too long: first truncate whole bytes | ||
| 1014 | + */ | ||
| 1015 | + if (8 * dgst_len > i) | ||
| 1016 | + dgst_len = (i + 7) / 8; | ||
| 1017 | + | ||
| 1018 | + if (!BN_bin2bn(dgst, dgst_len, m)) { | ||
| 1019 | + ECDSAerr(ECDSA_F_ECDSA_DO_SIGN, ERR_R_BN_LIB); | ||
| 1020 | + goto err; | ||
| 1021 | + } | ||
| 1022 | + | ||
| 1023 | + /* If still too long truncate remaining bits with a shift */ | ||
| 1024 | + if ((8 * dgst_len > i) && !BN_rshift(m, m, 8 - (i & 0x7))) { | ||
| 1025 | + ECDSAerr(ECDSA_F_ECDSA_DO_SIGN, ERR_R_BN_LIB); | ||
| 1026 | + goto err; | ||
| 1027 | + } | ||
| 1028 | + | ||
| 1029 | + /* copy the truncated bits into plain buffer */ | ||
| 1030 | + if (spcf_bn2bin(m, &tmp_dgst, &dgst_len)) { | ||
| 1031 | + fprintf(stderr, "%s:%d: OPENSSL_malloc failec\n", __FUNCTION__, | ||
| 1032 | + __LINE__); | ||
| 1033 | + goto err; | ||
| 1034 | + } | ||
| 1035 | + | ||
| 1036 | + /* check if this is prime or binary EC request */ | ||
| 1037 | + if (EC_METHOD_get_field_type(EC_GROUP_method_of(group)) | ||
| 1038 | + == NID_X9_62_prime_field) { | ||
| 1039 | + ec_crv = EC_PRIME; | ||
| 1040 | + /* get the generator point pair */ | ||
| 1041 | + if (!EC_POINT_get_affine_coordinates_GFp(group, | ||
| 1042 | + EC_GROUP_get0_generator | ||
| 1043 | + (group), x, y, ctx)) { | ||
| 1044 | + ECDSAerr(ECDSA_F_ECDSA_DO_SIGN, ERR_R_EC_LIB); | ||
| 1045 | + goto err; | ||
| 1046 | + } | ||
| 1047 | + | ||
| 1048 | + /* get the ECC curve parameters */ | ||
| 1049 | + if (!EC_GROUP_get_curve_GFp(group, p, a, b, ctx)) { | ||
| 1050 | + ECDSAerr(ECDSA_F_ECDSA_DO_SIGN, ERR_R_EC_LIB); | ||
| 1051 | + goto err; | ||
| 1052 | + } | ||
| 1053 | + } else if (EC_METHOD_get_field_type(EC_GROUP_method_of(group)) == | ||
| 1054 | + NID_X9_62_characteristic_two_field) { | ||
| 1055 | + ec_crv = EC_BINARY; | ||
| 1056 | + /* get the ECC curve parameters */ | ||
| 1057 | + if (!EC_GROUP_get_curve_GF2m(group, p, a, b, ctx)) { | ||
| 1058 | + ECDSAerr(ECDSA_F_ECDSA_DO_SIGN, ERR_R_EC_LIB); | ||
| 1059 | + goto err; | ||
| 1060 | + } | ||
| 1061 | + | ||
| 1062 | + /* get the generator point pair */ | ||
| 1063 | + if (!EC_POINT_get_affine_coordinates_GF2m(group, | ||
| 1064 | + EC_GROUP_get0_generator | ||
| 1065 | + (group), x, y, ctx)) { | ||
| 1066 | + ECDSAerr(ECDSA_F_ECDSA_DO_SIGN, ERR_R_EC_LIB); | ||
| 1067 | + goto err; | ||
| 1068 | + } | ||
| 1069 | + } else { | ||
| 1070 | + printf("Unsupported Curve\n"); | ||
| 1071 | + ECDSAerr(ECDSA_F_ECDSA_DO_SIGN, ERR_R_EC_LIB); | ||
| 1072 | + goto err; | ||
| 1073 | + } | ||
| 1074 | + | ||
| 1075 | + if (spcf_bn2bin(order, &r, &r_len)) { | ||
| 1076 | + ECDSAerr(ECDSA_F_ECDSA_DO_SIGN, ERR_R_MALLOC_FAILURE); | ||
| 1077 | + goto err; | ||
| 1078 | + } | ||
| 1079 | + | ||
| 1080 | + if (spcf_bn2bin(p, &q, &q_len)) { | ||
| 1081 | + ECDSAerr(ECDSA_F_ECDSA_DO_SIGN, ERR_R_MALLOC_FAILURE); | ||
| 1082 | + goto err; | ||
| 1083 | + } | ||
| 1084 | + | ||
| 1085 | + priv_key_len = r_len; | ||
| 1086 | + | ||
| 1087 | + /** | ||
| 1088 | + * If BN_num_bytes of priv_key returns less then r_len then | ||
| 1089 | + * add padding bytes before the key | ||
| 1090 | + */ | ||
| 1091 | + if (spcf_bn2bin_ex(priv_key, &s, &priv_key_len)) { | ||
| 1092 | + ECDSAerr(ECDSA_F_ECDSA_DO_SIGN, ERR_R_MALLOC_FAILURE); | ||
| 1093 | + goto err; | ||
| 1094 | + } | ||
| 1095 | + | ||
| 1096 | + /* Generation of ECC curve parameters */ | ||
| 1097 | + ab_len = 2 * q_len; | ||
| 1098 | + ab = eng_copy_curve_points(a, b, ab_len, q_len); | ||
| 1099 | + if (!ab) { | ||
| 1100 | + ECDSAerr(ECDSA_F_ECDSA_DO_SIGN, ERR_R_MALLOC_FAILURE); | ||
| 1101 | + goto err; | ||
| 1102 | + } | ||
| 1103 | + | ||
| 1104 | + if (ec_crv == EC_BINARY) { | ||
| 1105 | + if (eng_ec_get_cparam | ||
| 1106 | + (EC_GROUP_get_curve_name(group), ab + q_len, q_len)) { | ||
| 1107 | + unsigned char *c_temp = NULL; | ||
| 1108 | + int c_temp_len = q_len; | ||
| 1109 | + if (eng_ec_compute_cparam(b, p, &c_temp, &c_temp_len)) | ||
| 1110 | + memcpy(ab + q_len, c_temp, q_len); | ||
| 1111 | + else | ||
| 1112 | + goto err; | ||
| 1113 | + } | ||
| 1114 | + kop->curve_type = ECC_BINARY; | ||
| 1115 | + } | ||
| 1116 | + | ||
| 1117 | + /* Calculation of Generator point */ | ||
| 1118 | + g_len = 2 * q_len; | ||
| 1119 | + g_xy = eng_copy_curve_points(x, y, g_len, q_len); | ||
| 1120 | + if (!g_xy) { | ||
| 1121 | + ECDSAerr(ECDSA_F_ECDSA_DO_SIGN, ERR_R_MALLOC_FAILURE); | ||
| 1122 | + goto err; | ||
| 1123 | + } | ||
| 1124 | + | ||
| 1125 | + /* memory for message representative */ | ||
| 1126 | + f = malloc(r_len); | ||
| 1127 | + if (!f) { | ||
| 1128 | + ECDSAerr(ECDSA_F_ECDSA_DO_SIGN, ERR_R_MALLOC_FAILURE); | ||
| 1129 | + goto err; | ||
| 1130 | + } | ||
| 1131 | + | ||
| 1132 | + /* Add padding, since SEC expects hash to of size r_len */ | ||
| 1133 | + memset(f, 0, r_len - dgst_len); | ||
| 1134 | + | ||
| 1135 | + /* Skip leading bytes if dgst_len < r_len */ | ||
| 1136 | + memcpy(f + r_len - dgst_len, tmp_dgst, dgst_len); | ||
| 1137 | + | ||
| 1138 | + dgst_len += r_len - dgst_len; | ||
| 1139 | + | ||
| 1140 | + kop->crk_op = CRK_DSA_SIGN; | ||
| 1141 | + /* inputs: dgst dsa->p dsa->q dsa->g dsa->priv_key */ | ||
| 1142 | + kop->crk_param[0].crp_p = f; | ||
| 1143 | + kop->crk_param[0].crp_nbits = dgst_len * 8; | ||
| 1144 | + kop->crk_param[1].crp_p = q; | ||
| 1145 | + kop->crk_param[1].crp_nbits = q_len * 8; | ||
| 1146 | + kop->crk_param[2].crp_p = r; | ||
| 1147 | + kop->crk_param[2].crp_nbits = r_len * 8; | ||
| 1148 | + kop->crk_param[3].crp_p = g_xy; | ||
| 1149 | + kop->crk_param[3].crp_nbits = g_len * 8; | ||
| 1150 | + kop->crk_param[4].crp_p = s; | ||
| 1151 | + kop->crk_param[4].crp_nbits = priv_key_len * 8; | ||
| 1152 | + kop->crk_param[5].crp_p = ab; | ||
| 1153 | + kop->crk_param[5].crp_nbits = ab_len * 8; | ||
| 1154 | + kop->crk_iparams = 6; | ||
| 1155 | + kop->cookie = cookie; | ||
| 1156 | + | ||
| 1157 | + if (cryptodev_asym_async(kop, r_len, sig->r, r_len, sig->s)) | ||
| 1158 | + goto err; | ||
| 1159 | + | ||
| 1160 | + return ret; | ||
| 1161 | + err: | ||
| 1162 | + { | ||
| 1163 | + const ECDSA_METHOD *meth = ECDSA_OpenSSL(); | ||
| 1164 | + BN_free(sig->r); | ||
| 1165 | + BN_free(sig->s); | ||
| 1166 | + if (kop) | ||
| 1167 | + free(kop); | ||
| 1168 | + sig_ret = | ||
| 1169 | + (meth->ecdsa_do_sign) (dgst, dgst_len, in_kinv, in_r, eckey); | ||
| 1170 | + sig->r = sig_ret->r; | ||
| 1171 | + sig->s = sig_ret->s; | ||
| 1172 | + cookie->pkc_callback(cookie, 0); | ||
| 1173 | + } | ||
| 1174 | + return ret; | ||
| 1175 | +} | ||
| 1176 | + | ||
| 1177 | +static int cryptodev_ecdsa_verify_async(const unsigned char *dgst, | ||
| 1178 | + int dgst_len, const ECDSA_SIG *sig, | ||
| 1179 | + EC_KEY *eckey, | ||
| 1180 | + struct pkc_cookie_s *cookie) | ||
| 1181 | +{ | ||
| 1182 | + BIGNUM *m = NULL, *p = NULL, *a = NULL, *b = NULL; | ||
| 1183 | + BIGNUM *x = NULL, *y = NULL, *w_x = NULL, *w_y = NULL; | ||
| 1184 | + BN_CTX *ctx = NULL; | ||
| 1185 | + ECDSA_DATA *ecdsa = NULL; | ||
| 1186 | + unsigned char *q = NULL, *r = NULL, *ab = NULL, *g_xy = NULL, *w_xy = | ||
| 1187 | + NULL; | ||
| 1188 | + unsigned char *c = NULL, *d = NULL, *f = NULL, *tmp_dgst = NULL; | ||
| 1189 | + int i = 0, q_len = 0, pub_key_len = 0, r_len = 0, c_len = 0, g_len = 0; | ||
| 1190 | + int d_len = 0, ab_len = 0, ret = 1; | ||
| 1191 | + const EC_POINT *pub_key = NULL; | ||
| 1192 | + const BIGNUM *order = NULL; | ||
| 1193 | + const EC_GROUP *group = NULL; | ||
| 1194 | + ec_curve_t ec_crv = EC_PRIME; | ||
| 1195 | + struct crypt_kop *kop = malloc(sizeof(struct crypt_kop)); | ||
| 1196 | + | ||
| 1197 | + if (!kop) | ||
| 1198 | + goto err; | ||
| 1199 | + | ||
| 1200 | + memset(kop, 0, sizeof(struct crypt_kop)); | ||
| 1201 | + ecdsa = ecdsa_check(eckey); | ||
| 1202 | + if (!ecdsa) { | ||
| 1203 | + ECDSAerr(ECDSA_F_ECDSA_DO_VERIFY, ERR_R_PASSED_NULL_PARAMETER); | ||
| 1204 | + goto err; | ||
| 1205 | + } | ||
| 1206 | + | ||
| 1207 | + group = EC_KEY_get0_group(eckey); | ||
| 1208 | + pub_key = EC_KEY_get0_public_key(eckey); | ||
| 1209 | + | ||
| 1210 | + if (!group || !pub_key) { | ||
| 1211 | + ECDSAerr(ECDSA_F_ECDSA_DO_VERIFY, ERR_R_PASSED_NULL_PARAMETER); | ||
| 1212 | + goto err; | ||
| 1213 | + } | ||
| 1214 | + | ||
| 1215 | + if ((ctx = BN_CTX_new()) == NULL || (m = BN_new()) == NULL || | ||
| 1216 | + (a = BN_new()) == NULL || (b = BN_new()) == NULL || | ||
| 1217 | + (p = BN_new()) == NULL || (x = BN_new()) == NULL || | ||
| 1218 | + (y = BN_new()) == NULL || (w_x = BN_new()) == NULL || | ||
| 1219 | + (w_y = BN_new()) == NULL) { | ||
| 1220 | + ECDSAerr(ECDSA_F_ECDSA_DO_VERIFY, ERR_R_MALLOC_FAILURE); | ||
| 1221 | + goto err; | ||
| 1222 | + } | ||
| 1223 | + | ||
| 1224 | + order = &group->order; | ||
| 1225 | + if (!order || BN_is_zero(order)) { | ||
| 1226 | + ECDSAerr(ECDSA_F_ECDSA_DO_VERIFY, ECDSA_R_MISSING_PARAMETERS); | ||
| 1227 | + goto err; | ||
| 1228 | + } | ||
| 1229 | + | ||
| 1230 | + i = BN_num_bits(order); | ||
| 1231 | + /* | ||
| 1232 | + * Need to truncate digest if it is too long: first truncate whole * | ||
| 1233 | + * bytes | ||
| 1234 | + */ | ||
| 1235 | + if (8 * dgst_len > i) | ||
| 1236 | + dgst_len = (i + 7) / 8; | ||
| 1237 | + | ||
| 1238 | + if (!BN_bin2bn(dgst, dgst_len, m)) { | ||
| 1239 | + ECDSAerr(ECDSA_F_ECDSA_DO_VERIFY, ERR_R_BN_LIB); | ||
| 1240 | + goto err; | ||
| 1241 | + } | ||
| 1242 | + | ||
| 1243 | + /* If still too long truncate remaining bits with a shift */ | ||
| 1244 | + if ((8 * dgst_len > i) && !BN_rshift(m, m, 8 - (i & 0x7))) { | ||
| 1245 | + ECDSAerr(ECDSA_F_ECDSA_DO_VERIFY, ERR_R_BN_LIB); | ||
| 1246 | + goto err; | ||
| 1247 | + } | ||
| 1248 | + /* copy the truncated bits into plain buffer */ | ||
| 1249 | + if (spcf_bn2bin(m, &tmp_dgst, &dgst_len)) { | ||
| 1250 | + ECDSAerr(ECDSA_F_ECDSA_DO_VERIFY, ERR_R_MALLOC_FAILURE); | ||
| 1251 | + goto err; | ||
| 1252 | + } | ||
| 1253 | + | ||
| 1254 | + /* check if this is prime or binary EC request */ | ||
| 1255 | + if (EC_METHOD_get_field_type(EC_GROUP_method_of(group)) == | ||
| 1256 | + NID_X9_62_prime_field) { | ||
| 1257 | + ec_crv = EC_PRIME; | ||
| 1258 | + | ||
| 1259 | + /* get the generator point pair */ | ||
| 1260 | + if (!EC_POINT_get_affine_coordinates_GFp(group, | ||
| 1261 | + EC_GROUP_get0_generator | ||
| 1262 | + (group), x, y, ctx)) { | ||
| 1263 | + ECDSAerr(ECDSA_F_ECDSA_DO_VERIFY, ERR_R_EC_LIB); | ||
| 1264 | + goto err; | ||
| 1265 | + } | ||
| 1266 | + | ||
| 1267 | + /* get the public key pair for prime curve */ | ||
| 1268 | + if (!EC_POINT_get_affine_coordinates_GFp(group, | ||
| 1269 | + pub_key, w_x, w_y, ctx)) { | ||
| 1270 | + ECDSAerr(ECDSA_F_ECDSA_DO_VERIFY, ERR_R_EC_LIB); | ||
| 1271 | + goto err; | ||
| 1272 | + } | ||
| 1273 | + | ||
| 1274 | + /* get the ECC curve parameters */ | ||
| 1275 | + if (!EC_GROUP_get_curve_GFp(group, p, a, b, ctx)) { | ||
| 1276 | + ECDSAerr(ECDSA_F_ECDSA_DO_VERIFY, ERR_R_EC_LIB); | ||
| 1277 | + goto err; | ||
| 1278 | + } | ||
| 1279 | + } else if (EC_METHOD_get_field_type(EC_GROUP_method_of(group)) == | ||
| 1280 | + NID_X9_62_characteristic_two_field) { | ||
| 1281 | + ec_crv = EC_BINARY; | ||
| 1282 | + /* get the ECC curve parameters */ | ||
| 1283 | + if (!EC_GROUP_get_curve_GF2m(group, p, a, b, ctx)) { | ||
| 1284 | + ECDSAerr(ECDSA_F_ECDSA_DO_VERIFY, ERR_R_EC_LIB); | ||
| 1285 | + goto err; | ||
| 1286 | + } | ||
| 1287 | + | ||
| 1288 | + /* get the generator point pair */ | ||
| 1289 | + if (!EC_POINT_get_affine_coordinates_GF2m(group, | ||
| 1290 | + EC_GROUP_get0_generator | ||
| 1291 | + (group), x, y, ctx)) { | ||
| 1292 | + ECDSAerr(ECDSA_F_ECDSA_DO_VERIFY, ERR_R_EC_LIB); | ||
| 1293 | + goto err; | ||
| 1294 | + } | ||
| 1295 | + | ||
| 1296 | + /* get the public key pair for binary curve */ | ||
| 1297 | + if (!EC_POINT_get_affine_coordinates_GF2m(group, | ||
| 1298 | + pub_key, w_x, w_y, ctx)) { | ||
| 1299 | + ECDSAerr(ECDSA_F_ECDSA_DO_VERIFY, ERR_R_EC_LIB); | ||
| 1300 | + goto err; | ||
| 1301 | + } | ||
| 1302 | + } else { | ||
| 1303 | + printf("Unsupported Curve\n"); | ||
| 1304 | + ECDSAerr(ECDSA_F_ECDSA_DO_VERIFY, ERR_R_EC_LIB); | ||
| 1305 | + goto err; | ||
| 1306 | + } | ||
| 1307 | + | ||
| 1308 | + /* Get the order of the subgroup of private keys */ | ||
| 1309 | + if (spcf_bn2bin((BIGNUM *)order, &r, &r_len)) { | ||
| 1310 | + ECDSAerr(ECDSA_F_ECDSA_DO_VERIFY, ERR_R_MALLOC_FAILURE); | ||
| 1311 | + goto err; | ||
| 1312 | + } | ||
| 1313 | + | ||
| 1314 | + /* Get the irreducible polynomial that creates the field */ | ||
| 1315 | + if (spcf_bn2bin(p, &q, &q_len)) { | ||
| 1316 | + ECDSAerr(ECDSA_F_ECDSA_DO_VERIFY, ERR_R_MALLOC_FAILURE); | ||
| 1317 | + goto err; | ||
| 1318 | + } | ||
| 1319 | + | ||
| 1320 | + /* Get the public key into a flat buffer with appropriate padding */ | ||
| 1321 | + pub_key_len = 2 * q_len; | ||
| 1322 | + | ||
| 1323 | + w_xy = eng_copy_curve_points(w_x, w_y, pub_key_len, q_len); | ||
| 1324 | + if (!w_xy) { | ||
| 1325 | + ECDSAerr(ECDSA_F_ECDSA_DO_VERIFY, ERR_R_MALLOC_FAILURE); | ||
| 1326 | + goto err; | ||
| 1327 | + } | ||
| 1328 | + | ||
| 1329 | + /* Generation of ECC curve parameters */ | ||
| 1330 | + ab_len = 2 * q_len; | ||
| 1331 | + | ||
| 1332 | + ab = eng_copy_curve_points(a, b, ab_len, q_len); | ||
| 1333 | + if (!ab) { | ||
| 1334 | + ECDSAerr(ECDSA_F_ECDSA_DO_VERIFY, ERR_R_MALLOC_FAILURE); | ||
| 1335 | + goto err; | ||
| 1336 | + } | ||
| 1337 | + | ||
| 1338 | + if (ec_crv == EC_BINARY) { | ||
| 1339 | + /* copy b' i.e c(b), instead of only b */ | ||
| 1340 | + eng_ec_get_cparam(EC_GROUP_get_curve_name(group), ab + q_len, q_len); | ||
| 1341 | + kop->curve_type = ECC_BINARY; | ||
| 1342 | + } | ||
| 1343 | + | ||
| 1344 | + /* Calculation of Generator point */ | ||
| 1345 | + g_len = 2 * q_len; | ||
| 1346 | + | ||
| 1347 | + g_xy = eng_copy_curve_points(x, y, g_len, q_len); | ||
| 1348 | + if (!g_xy) { | ||
| 1349 | + ECDSAerr(ECDSA_F_ECDSA_DO_VERIFY, ERR_R_MALLOC_FAILURE); | ||
| 1350 | + goto err; | ||
| 1351 | + } | ||
| 1352 | + | ||
| 1353 | + /** | ||
| 1354 | + * Get the 1st part of signature into a flat buffer with | ||
| 1355 | + * appropriate padding | ||
| 1356 | + */ | ||
| 1357 | + if (BN_num_bytes(sig->r) < r_len) | ||
| 1358 | + c_len = r_len; | ||
| 1359 | + | ||
| 1360 | + if (spcf_bn2bin_ex(sig->r, &c, &c_len)) { | ||
| 1361 | + ECDSAerr(ECDSA_F_ECDSA_DO_VERIFY, ERR_R_MALLOC_FAILURE); | ||
| 1362 | + goto err; | ||
| 1363 | + } | ||
| 1364 | + | ||
| 1365 | + /** | ||
| 1366 | + * Get the 2nd part of signature into a flat buffer with | ||
| 1367 | + * appropriate padding | ||
| 1368 | + */ | ||
| 1369 | + if (BN_num_bytes(sig->s) < r_len) | ||
| 1370 | + d_len = r_len; | ||
| 1371 | + | ||
| 1372 | + if (spcf_bn2bin_ex(sig->s, &d, &d_len)) { | ||
| 1373 | + ECDSAerr(ECDSA_F_ECDSA_DO_VERIFY, ERR_R_MALLOC_FAILURE); | ||
| 1374 | + goto err; | ||
| 1375 | + } | ||
| 1376 | + | ||
| 1377 | + /* memory for message representative */ | ||
| 1378 | + f = malloc(r_len); | ||
| 1379 | + if (!f) { | ||
| 1380 | + ECDSAerr(ECDSA_F_ECDSA_DO_VERIFY, ERR_R_MALLOC_FAILURE); | ||
| 1381 | + goto err; | ||
| 1382 | + } | ||
| 1383 | + | ||
| 1384 | + /* Add padding, since SEC expects hash to of size r_len */ | ||
| 1385 | + memset(f, 0, r_len - dgst_len); | ||
| 1386 | + | ||
| 1387 | + /* Skip leading bytes if dgst_len < r_len */ | ||
| 1388 | + memcpy(f + r_len - dgst_len, tmp_dgst, dgst_len); | ||
| 1389 | + | ||
| 1390 | + dgst_len += r_len - dgst_len; | ||
| 1391 | + | ||
| 1392 | + kop->crk_op = CRK_DSA_VERIFY; | ||
| 1393 | + /* inputs: dgst dsa->p dsa->q dsa->g dsa->priv_key */ | ||
| 1394 | + kop->crk_param[0].crp_p = f; | ||
| 1395 | + kop->crk_param[0].crp_nbits = dgst_len * 8; | ||
| 1396 | + kop->crk_param[1].crp_p = q; | ||
| 1397 | + kop->crk_param[1].crp_nbits = q_len * 8; | ||
| 1398 | + kop->crk_param[2].crp_p = r; | ||
| 1399 | + kop->crk_param[2].crp_nbits = r_len * 8; | ||
| 1400 | + kop->crk_param[3].crp_p = g_xy; | ||
| 1401 | + kop->crk_param[3].crp_nbits = g_len * 8; | ||
| 1402 | + kop->crk_param[4].crp_p = w_xy; | ||
| 1403 | + kop->crk_param[4].crp_nbits = pub_key_len * 8; | ||
| 1404 | + kop->crk_param[5].crp_p = ab; | ||
| 1405 | + kop->crk_param[5].crp_nbits = ab_len * 8; | ||
| 1406 | + kop->crk_param[6].crp_p = c; | ||
| 1407 | + kop->crk_param[6].crp_nbits = d_len * 8; | ||
| 1408 | + kop->crk_param[7].crp_p = d; | ||
| 1409 | + kop->crk_param[7].crp_nbits = d_len * 8; | ||
| 1410 | + kop->crk_iparams = 8; | ||
| 1411 | + kop->cookie = cookie; | ||
| 1412 | + | ||
| 1413 | + if (cryptodev_asym_async(kop, 0, NULL, 0, NULL)) | ||
| 1414 | + goto err; | ||
| 1415 | + | ||
| 1416 | + return ret; | ||
| 1417 | + err: | ||
| 1418 | + { | ||
| 1419 | + const ECDSA_METHOD *meth = ECDSA_OpenSSL(); | ||
| 1420 | + | ||
| 1421 | + if (kop) | ||
| 1422 | + free(kop); | ||
| 1423 | + ret = (meth->ecdsa_do_verify) (dgst, dgst_len, sig, eckey); | ||
| 1424 | + cookie->pkc_callback(cookie, 0); | ||
| 1425 | + } | ||
| 1426 | + | ||
| 1427 | + return ret; | ||
| 1428 | +} | ||
| 1429 | + | ||
| 1430 | +/* Cryptodev DH Key Gen routine */ | ||
| 1431 | +static int cryptodev_dh_keygen_async(DH *dh, struct pkc_cookie_s *cookie) | ||
| 1432 | +{ | ||
| 1433 | + struct crypt_kop *kop = malloc(sizeof(struct crypt_kop)); | ||
| 1434 | + int ret = 1, g_len; | ||
| 1435 | + unsigned char *g = NULL; | ||
| 1436 | + | ||
| 1437 | + if (!kop) | ||
| 1438 | + goto sw_try; | ||
| 1439 | + | ||
| 1440 | + if (dh->priv_key == NULL) { | ||
| 1441 | + if ((dh->priv_key = BN_new()) == NULL) | ||
| 1442 | + goto sw_try; | ||
| 1443 | + } | ||
| 1444 | + | ||
| 1445 | + if (dh->pub_key == NULL) { | ||
| 1446 | + if ((dh->pub_key = BN_new()) == NULL) | ||
| 1447 | + goto sw_try; | ||
| 1448 | + } | ||
| 1449 | + | ||
| 1450 | + g_len = BN_num_bytes(dh->p); | ||
| 1451 | + /** | ||
| 1452 | + * Get generator into a plain buffer. If length is less than | ||
| 1453 | + * q_len then add leading padding bytes. | ||
| 1454 | + */ | ||
| 1455 | + if (spcf_bn2bin_ex(dh->g, &g, &g_len)) { | ||
| 1456 | + DSAerr(DH_F_DH_GENERATE_KEY, ERR_R_MALLOC_FAILURE); | ||
| 1457 | + goto sw_try; | ||
| 1458 | } | ||
| 1459 | |||
| 1460 | - /* Add padding, since SEC expects hash to of size r_len */ | ||
| 1461 | - memset(f, 0, r_len - dgst_len); | ||
| 1462 | + memset(kop, 0, sizeof(struct crypt_kop)); | ||
| 1463 | + kop->crk_op = CRK_DH_GENERATE_KEY; | ||
| 1464 | + if (bn2crparam(dh->p, &kop->crk_param[0])) | ||
| 1465 | + goto sw_try; | ||
| 1466 | + if (bn2crparam(dh->q, &kop->crk_param[1])) | ||
| 1467 | + goto sw_try; | ||
| 1468 | + kop->crk_param[2].crp_p = g; | ||
| 1469 | + kop->crk_param[2].crp_nbits = g_len * 8; | ||
| 1470 | + kop->crk_iparams = 3; | ||
| 1471 | + kop->cookie = cookie; | ||
| 1472 | |||
| 1473 | - /* Skip leading bytes if dgst_len < r_len */ | ||
| 1474 | - memcpy(f + r_len - dgst_len, tmp_dgst, dgst_len); | ||
| 1475 | - dgst_len += r_len - dgst_len; | ||
| 1476 | - kop.crk_op = CRK_DSA_VERIFY; | ||
| 1477 | - /* inputs: dgst dsa->p dsa->q dsa->g dsa->priv_key */ | ||
| 1478 | - kop.crk_param[0].crp_p = f; | ||
| 1479 | - kop.crk_param[0].crp_nbits = dgst_len * 8; | ||
| 1480 | - kop.crk_param[1].crp_p = q; | ||
| 1481 | - kop.crk_param[1].crp_nbits = q_len * 8; | ||
| 1482 | - kop.crk_param[2].crp_p = r; | ||
| 1483 | - kop.crk_param[2].crp_nbits = r_len * 8; | ||
| 1484 | - kop.crk_param[3].crp_p = g_xy; | ||
| 1485 | - kop.crk_param[3].crp_nbits = g_len * 8; | ||
| 1486 | - kop.crk_param[4].crp_p = w_xy; | ||
| 1487 | - kop.crk_param[4].crp_nbits = pub_key_len * 8; | ||
| 1488 | - kop.crk_param[5].crp_p = ab; | ||
| 1489 | - kop.crk_param[5].crp_nbits = ab_len * 8; | ||
| 1490 | - kop.crk_param[6].crp_p = c; | ||
| 1491 | - kop.crk_param[6].crp_nbits = d_len * 8; | ||
| 1492 | - kop.crk_param[7].crp_p = d; | ||
| 1493 | - kop.crk_param[7].crp_nbits = d_len * 8; | ||
| 1494 | - kop.crk_iparams = 8; | ||
| 1495 | + /* pub_key is or prime length while priv key is of length of order */ | ||
| 1496 | + if (cryptodev_asym_async(kop, BN_num_bytes(dh->p), dh->pub_key, | ||
| 1497 | + BN_num_bytes(dh->q), dh->priv_key)) | ||
| 1498 | + goto sw_try; | ||
| 1499 | |||
| 1500 | - if (cryptodev_asym(&kop, 0, NULL, 0, NULL) == 0) { | ||
| 1501 | - /* | ||
| 1502 | - * OCF success value is 0, if not zero, change ret to fail | ||
| 1503 | - */ | ||
| 1504 | - if (0 == kop.crk_status) | ||
| 1505 | - ret = 1; | ||
| 1506 | - } else { | ||
| 1507 | - const ECDSA_METHOD *meth = ECDSA_OpenSSL(); | ||
| 1508 | + return ret; | ||
| 1509 | + sw_try: | ||
| 1510 | + { | ||
| 1511 | + const DH_METHOD *meth = DH_OpenSSL(); | ||
| 1512 | |||
| 1513 | - ret = (meth->ecdsa_do_verify) (dgst, dgst_len, sig, eckey); | ||
| 1514 | + if (kop) | ||
| 1515 | + free(kop); | ||
| 1516 | + ret = (meth->generate_key) (dh); | ||
| 1517 | + cookie->pkc_callback(cookie, 0); | ||
| 1518 | } | ||
| 1519 | - kop.crk_param[0].crp_p = NULL; | ||
| 1520 | - zapparams(&kop); | ||
| 1521 | - | ||
| 1522 | - err: | ||
| 1523 | return ret; | ||
| 1524 | } | ||
| 1525 | |||
| 1526 | @@ -2468,6 +3517,54 @@ cryptodev_dh_compute_key(unsigned char *key, const BIGNUM *pub_key, DH *dh) | ||
| 1527 | return (dhret); | ||
| 1528 | } | ||
| 1529 | |||
| 1530 | +/* Return Length if successful and 0 on failure */ | ||
| 1531 | +static int | ||
| 1532 | +cryptodev_dh_compute_key_async(unsigned char *key, const BIGNUM *pub_key, | ||
| 1533 | + DH *dh, struct pkc_cookie_s *cookie) | ||
| 1534 | +{ | ||
| 1535 | + struct crypt_kop *kop = malloc(sizeof(struct crypt_kop)); | ||
| 1536 | + int ret = 1; | ||
| 1537 | + int fd, p_len; | ||
| 1538 | + unsigned char *padded_pub_key = NULL, *p = NULL; | ||
| 1539 | + | ||
| 1540 | + fd = *(int *)cookie->eng_handle; | ||
| 1541 | + | ||
| 1542 | + memset(kop, 0, sizeof(struct crypt_kop)); | ||
| 1543 | + kop->crk_op = CRK_DH_COMPUTE_KEY; | ||
| 1544 | + /* inputs: dh->priv_key pub_key dh->p key */ | ||
| 1545 | + spcf_bn2bin(dh->p, &p, &p_len); | ||
| 1546 | + spcf_bn2bin_ex(pub_key, &padded_pub_key, &p_len); | ||
| 1547 | + | ||
| 1548 | + if (bn2crparam(dh->priv_key, &kop->crk_param[0])) | ||
| 1549 | + goto err; | ||
| 1550 | + kop->crk_param[1].crp_p = padded_pub_key; | ||
| 1551 | + kop->crk_param[1].crp_nbits = p_len * 8; | ||
| 1552 | + kop->crk_param[2].crp_p = p; | ||
| 1553 | + kop->crk_param[2].crp_nbits = p_len * 8; | ||
| 1554 | + kop->crk_iparams = 3; | ||
| 1555 | + | ||
| 1556 | + kop->cookie = cookie; | ||
| 1557 | + kop->crk_param[3].crp_p = (void *)key; | ||
| 1558 | + kop->crk_param[3].crp_nbits = p_len * 8; | ||
| 1559 | + kop->crk_oparams = 1; | ||
| 1560 | + | ||
| 1561 | + if (cryptodev_asym_async(kop, 0, NULL, 0, NULL)) | ||
| 1562 | + goto err; | ||
| 1563 | + | ||
| 1564 | + return p_len; | ||
| 1565 | + err: | ||
| 1566 | + { | ||
| 1567 | + const DH_METHOD *meth = DH_OpenSSL(); | ||
| 1568 | + | ||
| 1569 | + if (kop) | ||
| 1570 | + free(kop); | ||
| 1571 | + ret = (meth->compute_key) (key, pub_key, dh); | ||
| 1572 | + /* Call user cookie handler */ | ||
| 1573 | + cookie->pkc_callback(cookie, 0); | ||
| 1574 | + } | ||
| 1575 | + return (ret); | ||
| 1576 | +} | ||
| 1577 | + | ||
| 1578 | int cryptodev_ecdh_compute_key(void *out, size_t outlen, | ||
| 1579 | const EC_POINT *pub_key, EC_KEY *ecdh, | ||
| 1580 | void *(*KDF) (const void *in, size_t inlen, | ||
| 1581 | @@ -2650,6 +3747,197 @@ int cryptodev_ecdh_compute_key(void *out, size_t outlen, | ||
| 1582 | return ret; | ||
| 1583 | } | ||
| 1584 | |||
| 1585 | +int cryptodev_ecdh_compute_key_async(void *out, size_t outlen, | ||
| 1586 | + const EC_POINT *pub_key, EC_KEY *ecdh, | ||
| 1587 | + void *(*KDF) (const void *in, | ||
| 1588 | + size_t inlen, void *out, | ||
| 1589 | + size_t *outlen), | ||
| 1590 | + struct pkc_cookie_s *cookie) | ||
| 1591 | +{ | ||
| 1592 | + ec_curve_t ec_crv = EC_PRIME; | ||
| 1593 | + unsigned char *q = NULL, *w_xy = NULL, *ab = NULL, *s = NULL, *r = NULL; | ||
| 1594 | + BIGNUM *w_x = NULL, *w_y = NULL; | ||
| 1595 | + int q_len = 0, ab_len = 0, pub_key_len = 0, r_len = 0, priv_key_len = 0; | ||
| 1596 | + BIGNUM *p = NULL, *a = NULL, *b = NULL; | ||
| 1597 | + BN_CTX *ctx; | ||
| 1598 | + EC_POINT *tmp = NULL; | ||
| 1599 | + BIGNUM *x = NULL, *y = NULL; | ||
| 1600 | + const BIGNUM *priv_key; | ||
| 1601 | + const EC_GROUP *group = NULL; | ||
| 1602 | + int ret = 1; | ||
| 1603 | + size_t buflen, len; | ||
| 1604 | + struct crypt_kop *kop = malloc(sizeof(struct crypt_kop)); | ||
| 1605 | + | ||
| 1606 | + if (!(ctx = BN_CTX_new()) || !kop) | ||
| 1607 | + goto err; | ||
| 1608 | + | ||
| 1609 | + memset(kop, 0, sizeof(struct crypt_kop)); | ||
| 1610 | + | ||
| 1611 | + BN_CTX_start(ctx); | ||
| 1612 | + x = BN_CTX_get(ctx); | ||
| 1613 | + y = BN_CTX_get(ctx); | ||
| 1614 | + p = BN_CTX_get(ctx); | ||
| 1615 | + a = BN_CTX_get(ctx); | ||
| 1616 | + b = BN_CTX_get(ctx); | ||
| 1617 | + w_x = BN_CTX_get(ctx); | ||
| 1618 | + w_y = BN_CTX_get(ctx); | ||
| 1619 | + | ||
| 1620 | + if (!x || !y || !p || !a || !b || !w_x || !w_y) { | ||
| 1621 | + ECDHerr(ECDH_F_ECDH_COMPUTE_KEY, ERR_R_MALLOC_FAILURE); | ||
| 1622 | + goto err; | ||
| 1623 | + } | ||
| 1624 | + | ||
| 1625 | + priv_key = EC_KEY_get0_private_key(ecdh); | ||
| 1626 | + if (priv_key == NULL) { | ||
| 1627 | + ECDHerr(ECDH_F_ECDH_COMPUTE_KEY, ECDH_R_NO_PRIVATE_VALUE); | ||
| 1628 | + goto err; | ||
| 1629 | + } | ||
| 1630 | + | ||
| 1631 | + group = EC_KEY_get0_group(ecdh); | ||
| 1632 | + if ((tmp = EC_POINT_new(group)) == NULL) { | ||
| 1633 | + ECDHerr(ECDH_F_ECDH_COMPUTE_KEY, ERR_R_MALLOC_FAILURE); | ||
| 1634 | + goto err; | ||
| 1635 | + } | ||
| 1636 | + | ||
| 1637 | + if (EC_METHOD_get_field_type(EC_GROUP_method_of(group)) == | ||
| 1638 | + NID_X9_62_prime_field) { | ||
| 1639 | + ec_crv = EC_PRIME; | ||
| 1640 | + | ||
| 1641 | + if (!EC_POINT_get_affine_coordinates_GFp(group, | ||
| 1642 | + EC_GROUP_get0_generator | ||
| 1643 | + (group), x, y, ctx)) { | ||
| 1644 | + ECDHerr(ECDH_F_ECDH_COMPUTE_KEY, ECDH_R_POINT_ARITHMETIC_FAILURE); | ||
| 1645 | + goto err; | ||
| 1646 | + } | ||
| 1647 | + | ||
| 1648 | + /* get the ECC curve parameters */ | ||
| 1649 | + if (!EC_GROUP_get_curve_GFp(group, p, a, b, ctx)) { | ||
| 1650 | + ECDHerr(ECDH_F_ECDH_COMPUTE_KEY, ERR_R_BN_LIB); | ||
| 1651 | + goto err; | ||
| 1652 | + } | ||
| 1653 | + | ||
| 1654 | + /* get the public key pair for prime curve */ | ||
| 1655 | + if (!EC_POINT_get_affine_coordinates_GFp | ||
| 1656 | + (group, pub_key, w_x, w_y, ctx)) { | ||
| 1657 | + ECDHerr(ECDH_F_ECDH_COMPUTE_KEY, ERR_R_BN_LIB); | ||
| 1658 | + goto err; | ||
| 1659 | + } | ||
| 1660 | + } else { | ||
| 1661 | + ec_crv = EC_BINARY; | ||
| 1662 | + | ||
| 1663 | + if (!EC_POINT_get_affine_coordinates_GF2m(group, | ||
| 1664 | + EC_GROUP_get0_generator | ||
| 1665 | + (group), x, y, ctx)) { | ||
| 1666 | + ECDHerr(ECDH_F_ECDH_COMPUTE_KEY, ECDH_R_POINT_ARITHMETIC_FAILURE); | ||
| 1667 | + goto err; | ||
| 1668 | + } | ||
| 1669 | + | ||
| 1670 | + /* get the ECC curve parameters */ | ||
| 1671 | + if (!EC_GROUP_get_curve_GF2m(group, p, a, b, ctx)) { | ||
| 1672 | + ECDHerr(ECDH_F_ECDH_COMPUTE_KEY, ERR_R_BN_LIB); | ||
| 1673 | + goto err; | ||
| 1674 | + } | ||
| 1675 | + | ||
| 1676 | + /* get the public key pair for binary curve */ | ||
| 1677 | + if (!EC_POINT_get_affine_coordinates_GF2m(group, | ||
| 1678 | + pub_key, w_x, w_y, ctx)) { | ||
| 1679 | + ECDSAerr(ECDSA_F_ECDSA_DO_SIGN, ERR_R_EC_LIB); | ||
| 1680 | + goto err; | ||
| 1681 | + } | ||
| 1682 | + } | ||
| 1683 | + | ||
| 1684 | + /* irreducible polynomial that creates the field */ | ||
| 1685 | + if (spcf_bn2bin((BIGNUM *)&group->order, &r, &r_len)) { | ||
| 1686 | + ECDSAerr(ECDSA_F_ECDSA_DO_SIGN, ERR_R_MALLOC_FAILURE); | ||
| 1687 | + goto err; | ||
| 1688 | + } | ||
| 1689 | + | ||
| 1690 | + /* Get the irreducible polynomial that creates the field */ | ||
| 1691 | + if (spcf_bn2bin(p, &q, &q_len)) { | ||
| 1692 | + ECDHerr(ECDH_F_ECDH_COMPUTE_KEY, ERR_R_BN_LIB); | ||
| 1693 | + goto err; | ||
| 1694 | + } | ||
| 1695 | + | ||
| 1696 | + /* Get the public key into a flat buffer with appropriate padding */ | ||
| 1697 | + pub_key_len = 2 * q_len; | ||
| 1698 | + w_xy = eng_copy_curve_points(w_x, w_y, pub_key_len, q_len); | ||
| 1699 | + if (!w_xy) { | ||
| 1700 | + ECDSAerr(ECDSA_F_ECDSA_DO_SIGN, ERR_R_MALLOC_FAILURE); | ||
| 1701 | + goto err; | ||
| 1702 | + } | ||
| 1703 | + | ||
| 1704 | + /* Generation of ECC curve parameters */ | ||
| 1705 | + ab_len = 2 * q_len; | ||
| 1706 | + ab = eng_copy_curve_points(a, b, ab_len, q_len); | ||
| 1707 | + if (!ab) { | ||
| 1708 | + ECDHerr(ECDH_F_ECDH_COMPUTE_KEY, ERR_R_BN_LIB); | ||
| 1709 | + goto err; | ||
| 1710 | + } | ||
| 1711 | + | ||
| 1712 | + if (ec_crv == EC_BINARY) { | ||
| 1713 | + /* copy b' i.e c(b), instead of only b */ | ||
| 1714 | + if (eng_ec_get_cparam | ||
| 1715 | + (EC_GROUP_get_curve_name(group), ab + q_len, q_len)) { | ||
| 1716 | + unsigned char *c_temp = NULL; | ||
| 1717 | + int c_temp_len = q_len; | ||
| 1718 | + if (eng_ec_compute_cparam(b, p, &c_temp, &c_temp_len)) | ||
| 1719 | + memcpy(ab + q_len, c_temp, q_len); | ||
| 1720 | + else | ||
| 1721 | + goto err; | ||
| 1722 | + } | ||
| 1723 | + kop->curve_type = ECC_BINARY; | ||
| 1724 | + } else | ||
| 1725 | + kop->curve_type = ECC_PRIME; | ||
| 1726 | + | ||
| 1727 | + priv_key_len = r_len; | ||
| 1728 | + | ||
| 1729 | + /* | ||
| 1730 | + * If BN_num_bytes of priv_key returns less then r_len then | ||
| 1731 | + * add padding bytes before the key | ||
| 1732 | + */ | ||
| 1733 | + if (spcf_bn2bin_ex((BIGNUM *)priv_key, &s, &priv_key_len)) { | ||
| 1734 | + ECDSAerr(ECDSA_F_ECDSA_DO_SIGN, ERR_R_MALLOC_FAILURE); | ||
| 1735 | + goto err; | ||
| 1736 | + } | ||
| 1737 | + | ||
| 1738 | + buflen = (EC_GROUP_get_degree(group) + 7) / 8; | ||
| 1739 | + len = BN_num_bytes(x); | ||
| 1740 | + if (len > buflen || q_len < buflen) { | ||
| 1741 | + ECDHerr(ECDH_F_ECDH_COMPUTE_KEY, ERR_R_INTERNAL_ERROR); | ||
| 1742 | + goto err; | ||
| 1743 | + } | ||
| 1744 | + | ||
| 1745 | + kop->crk_op = CRK_DH_COMPUTE_KEY; | ||
| 1746 | + kop->crk_param[0].crp_p = (void *)s; | ||
| 1747 | + kop->crk_param[0].crp_nbits = priv_key_len * 8; | ||
| 1748 | + kop->crk_param[1].crp_p = (void *)w_xy; | ||
| 1749 | + kop->crk_param[1].crp_nbits = pub_key_len * 8; | ||
| 1750 | + kop->crk_param[2].crp_p = (void *)q; | ||
| 1751 | + kop->crk_param[2].crp_nbits = q_len * 8; | ||
| 1752 | + kop->crk_param[3].crp_p = (void *)ab; | ||
| 1753 | + kop->crk_param[3].crp_nbits = ab_len * 8; | ||
| 1754 | + kop->crk_iparams = 4; | ||
| 1755 | + kop->crk_param[4].crp_p = (void *)out; | ||
| 1756 | + kop->crk_param[4].crp_nbits = q_len * 8; | ||
| 1757 | + kop->crk_oparams = 1; | ||
| 1758 | + kop->cookie = cookie; | ||
| 1759 | + if (cryptodev_asym_async(kop, 0, NULL, 0, NULL)) | ||
| 1760 | + goto err; | ||
| 1761 | + | ||
| 1762 | + return q_len; | ||
| 1763 | + err: | ||
| 1764 | + { | ||
| 1765 | + const ECDH_METHOD *meth = ECDH_OpenSSL(); | ||
| 1766 | + | ||
| 1767 | + if (kop) | ||
| 1768 | + free(kop); | ||
| 1769 | + ret = (meth->compute_key) (out, outlen, pub_key, ecdh, KDF); | ||
| 1770 | + /* Call user cookie handler */ | ||
| 1771 | + cookie->pkc_callback(cookie, 0); | ||
| 1772 | + } | ||
| 1773 | + return ret; | ||
| 1774 | +} | ||
| 1775 | + | ||
| 1776 | static DH_METHOD cryptodev_dh = { | ||
| 1777 | "cryptodev DH method", | ||
| 1778 | NULL, /* cryptodev_dh_generate_key */ | ||
| 1779 | @@ -2657,6 +3945,8 @@ static DH_METHOD cryptodev_dh = { | ||
| 1780 | NULL, | ||
| 1781 | NULL, | ||
| 1782 | NULL, | ||
| 1783 | + NULL, | ||
| 1784 | + NULL, | ||
| 1785 | 0, /* flags */ | ||
| 1786 | NULL /* app_data */ | ||
| 1787 | }; | ||
| 1788 | @@ -2665,6 +3955,7 @@ static ECDH_METHOD cryptodev_ecdh = { | ||
| 1789 | "cryptodev ECDH method", | ||
| 1790 | NULL, /* cryptodev_ecdh_compute_key */ | ||
| 1791 | NULL, | ||
| 1792 | + NULL, | ||
| 1793 | 0, /* flags */ | ||
| 1794 | NULL /* app_data */ | ||
| 1795 | }; | ||
| 1796 | @@ -2735,10 +4026,15 @@ void ENGINE_load_cryptodev(void) | ||
| 1797 | cryptodev_rsa.rsa_priv_dec = rsa_meth->rsa_priv_dec; | ||
| 1798 | if (cryptodev_asymfeat & CRF_MOD_EXP) { | ||
| 1799 | cryptodev_rsa.bn_mod_exp = cryptodev_bn_mod_exp; | ||
| 1800 | - if (cryptodev_asymfeat & CRF_MOD_EXP_CRT) | ||
| 1801 | + cryptodev_rsa.bn_mod_exp_async = cryptodev_bn_mod_exp_async; | ||
| 1802 | + if (cryptodev_asymfeat & CRF_MOD_EXP_CRT) { | ||
| 1803 | cryptodev_rsa.rsa_mod_exp = cryptodev_rsa_mod_exp; | ||
| 1804 | - else | ||
| 1805 | + cryptodev_rsa.rsa_mod_exp_async = cryptodev_rsa_mod_exp_async; | ||
| 1806 | + } else { | ||
| 1807 | cryptodev_rsa.rsa_mod_exp = cryptodev_rsa_nocrt_mod_exp; | ||
| 1808 | + cryptodev_rsa.rsa_mod_exp_async = | ||
| 1809 | + cryptodev_rsa_nocrt_mod_exp_async; | ||
| 1810 | + } | ||
| 1811 | } | ||
| 1812 | } | ||
| 1813 | |||
| 1814 | @@ -2746,12 +4042,18 @@ void ENGINE_load_cryptodev(void) | ||
| 1815 | const DSA_METHOD *meth = DSA_OpenSSL(); | ||
| 1816 | |||
| 1817 | memcpy(&cryptodev_dsa, meth, sizeof(DSA_METHOD)); | ||
| 1818 | - if (cryptodev_asymfeat & CRF_DSA_SIGN) | ||
| 1819 | + if (cryptodev_asymfeat & CRF_DSA_SIGN) { | ||
| 1820 | cryptodev_dsa.dsa_do_sign = cryptodev_dsa_do_sign; | ||
| 1821 | - if (cryptodev_asymfeat & CRF_DSA_VERIFY) | ||
| 1822 | + cryptodev_dsa.dsa_do_sign_async = cryptodev_dsa_do_sign_async; | ||
| 1823 | + } | ||
| 1824 | + if (cryptodev_asymfeat & CRF_DSA_VERIFY) { | ||
| 1825 | cryptodev_dsa.dsa_do_verify = cryptodev_dsa_verify; | ||
| 1826 | - if (cryptodev_asymfeat & CRF_DSA_GENERATE_KEY) | ||
| 1827 | + cryptodev_dsa.dsa_do_verify_async = cryptodev_dsa_verify_async; | ||
| 1828 | + } | ||
| 1829 | + if (cryptodev_asymfeat & CRF_DSA_GENERATE_KEY) { | ||
| 1830 | cryptodev_dsa.dsa_keygen = cryptodev_dsa_keygen; | ||
| 1831 | + cryptodev_dsa.dsa_keygen_async = cryptodev_dsa_keygen_async; | ||
| 1832 | + } | ||
| 1833 | } | ||
| 1834 | |||
| 1835 | if (ENGINE_set_DH(engine, &cryptodev_dh)) { | ||
| 1836 | @@ -2759,9 +4061,12 @@ void ENGINE_load_cryptodev(void) | ||
| 1837 | memcpy(&cryptodev_dh, dh_meth, sizeof(DH_METHOD)); | ||
| 1838 | if (cryptodev_asymfeat & CRF_DH_COMPUTE_KEY) { | ||
| 1839 | cryptodev_dh.compute_key = cryptodev_dh_compute_key; | ||
| 1840 | + cryptodev_dh.compute_key_async = cryptodev_dh_compute_key_async; | ||
| 1841 | } | ||
| 1842 | if (cryptodev_asymfeat & CRF_DH_GENERATE_KEY) { | ||
| 1843 | cryptodev_dh.generate_key = cryptodev_dh_keygen; | ||
| 1844 | + cryptodev_dh.generate_key_async = cryptodev_dh_keygen_async; | ||
| 1845 | + | ||
| 1846 | } | ||
| 1847 | } | ||
| 1848 | |||
| 1849 | @@ -2770,9 +4075,13 @@ void ENGINE_load_cryptodev(void) | ||
| 1850 | memcpy(&cryptodev_ecdsa, meth, sizeof(ECDSA_METHOD)); | ||
| 1851 | if (cryptodev_asymfeat & CRF_DSA_SIGN) { | ||
| 1852 | cryptodev_ecdsa.ecdsa_do_sign = cryptodev_ecdsa_do_sign; | ||
| 1853 | + cryptodev_ecdsa.ecdsa_do_sign_async = | ||
| 1854 | + cryptodev_ecdsa_do_sign_async; | ||
| 1855 | } | ||
| 1856 | if (cryptodev_asymfeat & CRF_DSA_VERIFY) { | ||
| 1857 | cryptodev_ecdsa.ecdsa_do_verify = cryptodev_ecdsa_verify; | ||
| 1858 | + cryptodev_ecdsa.ecdsa_do_verify_async = | ||
| 1859 | + cryptodev_ecdsa_verify_async; | ||
| 1860 | } | ||
| 1861 | } | ||
| 1862 | |||
| 1863 | @@ -2781,9 +4090,16 @@ void ENGINE_load_cryptodev(void) | ||
| 1864 | memcpy(&cryptodev_ecdh, ecdh_meth, sizeof(ECDH_METHOD)); | ||
| 1865 | if (cryptodev_asymfeat & CRF_DH_COMPUTE_KEY) { | ||
| 1866 | cryptodev_ecdh.compute_key = cryptodev_ecdh_compute_key; | ||
| 1867 | + cryptodev_ecdh.compute_key_async = | ||
| 1868 | + cryptodev_ecdh_compute_key_async; | ||
| 1869 | } | ||
| 1870 | } | ||
| 1871 | |||
| 1872 | + ENGINE_set_check_pkc_availability(engine, cryptodev_check_availability); | ||
| 1873 | + ENGINE_set_close_instance(engine, cryptodev_close_instance); | ||
| 1874 | + ENGINE_set_init_instance(engine, cryptodev_init_instance); | ||
| 1875 | + ENGINE_set_async_map(engine, ENGINE_ALLPKC_ASYNC); | ||
| 1876 | + | ||
| 1877 | ENGINE_add(engine); | ||
| 1878 | ENGINE_free(engine); | ||
| 1879 | ERR_clear_error(); | ||
| 1880 | diff --git a/crypto/engine/eng_int.h b/crypto/engine/eng_int.h | ||
| 1881 | index 46f163b..b698a0c 100644 | ||
| 1882 | --- a/crypto/engine/eng_int.h | ||
| 1883 | +++ b/crypto/engine/eng_int.h | ||
| 1884 | @@ -198,6 +198,29 @@ struct engine_st { | ||
| 1885 | ENGINE_LOAD_KEY_PTR load_privkey; | ||
| 1886 | ENGINE_LOAD_KEY_PTR load_pubkey; | ||
| 1887 | ENGINE_SSL_CLIENT_CERT_PTR load_ssl_client_cert; | ||
| 1888 | + /* | ||
| 1889 | + * Instantiate Engine handle to be passed in check_pkc_availability | ||
| 1890 | + * Ensure that Engine is instantiated before any pkc asynchronous call. | ||
| 1891 | + */ | ||
| 1892 | + void *(*engine_init_instance)(void); | ||
| 1893 | + /* | ||
| 1894 | + * Instantiated Engine handle will be closed with this call. | ||
| 1895 | + * Ensure that no pkc asynchronous call is made after this call | ||
| 1896 | + */ | ||
| 1897 | + void (*engine_close_instance)(void *handle); | ||
| 1898 | + /* | ||
| 1899 | + * Check availability will extract the data from kernel. | ||
| 1900 | + * eng_handle: This is the Engine handle corresponds to which | ||
| 1901 | + * the cookies needs to be polled. | ||
| 1902 | + * return 0 if cookie available else 1 | ||
| 1903 | + */ | ||
| 1904 | + int (*check_pkc_availability)(void *eng_handle); | ||
| 1905 | + /* | ||
| 1906 | + * The following map is used to check if the engine supports asynchronous implementation | ||
| 1907 | + * ENGINE_ASYNC_FLAG* for available bitmap. Any application checking for asynchronous | ||
| 1908 | + * implementation need to check this features using "int ENGINE_get_async_map(engine *)"; | ||
| 1909 | + */ | ||
| 1910 | + int async_map; | ||
| 1911 | const ENGINE_CMD_DEFN *cmd_defns; | ||
| 1912 | int flags; | ||
| 1913 | /* reference count on the structure itself */ | ||
| 1914 | diff --git a/crypto/engine/eng_lib.c b/crypto/engine/eng_lib.c | ||
| 1915 | index dc2abd2..0c57e12 100644 | ||
| 1916 | --- a/crypto/engine/eng_lib.c | ||
| 1917 | +++ b/crypto/engine/eng_lib.c | ||
| 1918 | @@ -100,7 +100,11 @@ void engine_set_all_null(ENGINE *e) | ||
| 1919 | e->ctrl = NULL; | ||
| 1920 | e->load_privkey = NULL; | ||
| 1921 | e->load_pubkey = NULL; | ||
| 1922 | + e->check_pkc_availability = NULL; | ||
| 1923 | + e->engine_init_instance = NULL; | ||
| 1924 | + e->engine_close_instance = NULL; | ||
| 1925 | e->cmd_defns = NULL; | ||
| 1926 | + e->async_map = 0; | ||
| 1927 | e->flags = 0; | ||
| 1928 | } | ||
| 1929 | |||
| 1930 | @@ -246,6 +250,48 @@ int ENGINE_set_id(ENGINE *e, const char *id) | ||
| 1931 | } | ||
| 1932 | e->id = id; | ||
| 1933 | return 1; | ||
| 1934 | + } | ||
| 1935 | + | ||
| 1936 | +void ENGINE_set_init_instance(ENGINE *e, void *(*engine_init_instance)(void)) | ||
| 1937 | + { | ||
| 1938 | + e->engine_init_instance = engine_init_instance; | ||
| 1939 | + } | ||
| 1940 | + | ||
| 1941 | +void ENGINE_set_close_instance(ENGINE *e, | ||
| 1942 | + void (*engine_close_instance)(void *)) | ||
| 1943 | + { | ||
| 1944 | + e->engine_close_instance = engine_close_instance; | ||
| 1945 | + } | ||
| 1946 | + | ||
| 1947 | +void ENGINE_set_async_map(ENGINE *e, int async_map) | ||
| 1948 | + { | ||
| 1949 | + e->async_map = async_map; | ||
| 1950 | + } | ||
| 1951 | + | ||
| 1952 | +void *ENGINE_init_instance(ENGINE *e) | ||
| 1953 | + { | ||
| 1954 | + return e->engine_init_instance(); | ||
| 1955 | + } | ||
| 1956 | + | ||
| 1957 | +void ENGINE_close_instance(ENGINE *e, void *eng_handle) | ||
| 1958 | + { | ||
| 1959 | + e->engine_close_instance(eng_handle); | ||
| 1960 | + } | ||
| 1961 | + | ||
| 1962 | +int ENGINE_get_async_map(ENGINE *e) | ||
| 1963 | + { | ||
| 1964 | + return e->async_map; | ||
| 1965 | + } | ||
| 1966 | + | ||
| 1967 | +void ENGINE_set_check_pkc_availability(ENGINE *e, | ||
| 1968 | + int (*check_pkc_availability)(void *eng_handle)) | ||
| 1969 | + { | ||
| 1970 | + e->check_pkc_availability = check_pkc_availability; | ||
| 1971 | + } | ||
| 1972 | + | ||
| 1973 | +int ENGINE_check_pkc_availability(ENGINE *e, void *eng_handle) | ||
| 1974 | + { | ||
| 1975 | + return e->check_pkc_availability(eng_handle); | ||
| 1976 | } | ||
| 1977 | |||
| 1978 | int ENGINE_set_name(ENGINE *e, const char *name) | ||
| 1979 | diff --git a/crypto/engine/engine.h b/crypto/engine/engine.h | ||
| 1980 | index 020d912..4527aa1 100644 | ||
| 1981 | --- a/crypto/engine/engine.h | ||
| 1982 | +++ b/crypto/engine/engine.h | ||
| 1983 | @@ -551,6 +551,30 @@ ENGINE *ENGINE_new(void); | ||
| 1984 | int ENGINE_free(ENGINE *e); | ||
| 1985 | int ENGINE_up_ref(ENGINE *e); | ||
| 1986 | int ENGINE_set_id(ENGINE *e, const char *id); | ||
| 1987 | +void ENGINE_set_init_instance(ENGINE *e, void *(*engine_init_instance)(void)); | ||
| 1988 | +void ENGINE_set_close_instance(ENGINE *e, | ||
| 1989 | + void (*engine_free_instance)(void *)); | ||
| 1990 | +/* | ||
| 1991 | + * Following FLAGS are bitmap store in async_map to set asynchronous interface capability | ||
| 1992 | + *of the engine | ||
| 1993 | + */ | ||
| 1994 | +#define ENGINE_RSA_ASYNC 0x0001 | ||
| 1995 | +#define ENGINE_DSA_ASYNC 0x0002 | ||
| 1996 | +#define ENGINE_DH_ASYNC 0x0004 | ||
| 1997 | +#define ENGINE_ECDSA_ASYNC 0x0008 | ||
| 1998 | +#define ENGINE_ECDH_ASYNC 0x0010 | ||
| 1999 | +#define ENGINE_ALLPKC_ASYNC 0x001F | ||
| 2000 | +/* Engine implementation will set the bitmap based on above flags using following API */ | ||
| 2001 | +void ENGINE_set_async_map(ENGINE *e, int async_map); | ||
| 2002 | + /* Application need to check the bitmap based on above flags using following API | ||
| 2003 | + * to confirm asynchronous methods supported | ||
| 2004 | + */ | ||
| 2005 | +int ENGINE_get_async_map(ENGINE *e); | ||
| 2006 | +void *ENGINE_init_instance(ENGINE *e); | ||
| 2007 | +void ENGINE_close_instance(ENGINE *e, void *eng_handle); | ||
| 2008 | +void ENGINE_set_check_pkc_availability(ENGINE *e, | ||
| 2009 | + int (*check_pkc_availability)(void *eng_handle)); | ||
| 2010 | +int ENGINE_check_pkc_availability(ENGINE *e, void *eng_handle); | ||
| 2011 | int ENGINE_set_name(ENGINE *e, const char *name); | ||
| 2012 | int ENGINE_set_RSA(ENGINE *e, const RSA_METHOD *rsa_meth); | ||
| 2013 | int ENGINE_set_DSA(ENGINE *e, const DSA_METHOD *dsa_meth); | ||
| 2014 | diff --git a/crypto/rsa/rsa.h b/crypto/rsa/rsa.h | ||
| 2015 | index d2ee374..7c539fc 100644 | ||
| 2016 | --- a/crypto/rsa/rsa.h | ||
| 2017 | +++ b/crypto/rsa/rsa.h | ||
| 2018 | @@ -97,6 +97,29 @@ struct rsa_meth_st { | ||
| 2019 | /* Can be null */ | ||
| 2020 | int (*bn_mod_exp) (BIGNUM *r, const BIGNUM *a, const BIGNUM *p, | ||
| 2021 | const BIGNUM *m, BN_CTX *ctx, BN_MONT_CTX *m_ctx); | ||
| 2022 | + /* | ||
| 2023 | + * Cookie in the following _async variant must be allocated before | ||
| 2024 | + * submission and can be freed once its corresponding callback | ||
| 2025 | + * handler is called | ||
| 2026 | + */ | ||
| 2027 | + int (*rsa_pub_enc_asyn)(int flen,const unsigned char *from, | ||
| 2028 | + unsigned char *to, RSA *rsa, int padding, | ||
| 2029 | + struct pkc_cookie_s *cookie); | ||
| 2030 | + int (*rsa_pub_dec_async)(int flen,const unsigned char *from, | ||
| 2031 | + unsigned char *to, RSA *rsa, int padding, | ||
| 2032 | + struct pkc_cookie_s *cookie); | ||
| 2033 | + int (*rsa_priv_enc_async)(int flen,const unsigned char *from, | ||
| 2034 | + unsigned char *to, RSA *rsa, int padding, | ||
| 2035 | + struct pkc_cookie_s *cookie); | ||
| 2036 | + int (*rsa_priv_dec_async)(int flen,const unsigned char *from, | ||
| 2037 | + unsigned char *to, RSA *rsa, int padding, | ||
| 2038 | + struct pkc_cookie_s *cookie); | ||
| 2039 | + int (*rsa_mod_exp_async)(BIGNUM *r0, const BIGNUM *I, RSA *rsa, | ||
| 2040 | + BN_CTX *ctx, struct pkc_cookie_s *cookie); | ||
| 2041 | + int (*bn_mod_exp_async)(BIGNUM *r, const BIGNUM *a, const BIGNUM *p, | ||
| 2042 | + const BIGNUM *m, BN_CTX *ctx, | ||
| 2043 | + BN_MONT_CTX *m_ctx, struct pkc_cookie_s *cookie); | ||
| 2044 | + | ||
| 2045 | /* called at new */ | ||
| 2046 | int (*init) (RSA *rsa); | ||
| 2047 | /* called at free */ | ||
| 2048 | -- | ||
| 2049 | 2.7.0 | ||
| 2050 | |||
diff --git a/recipes-connectivity/openssl/openssl-qoriq/qoriq/0007-Fixed-private-key-support-for-DH.patch b/recipes-connectivity/openssl/openssl-qoriq/qoriq/0007-Fixed-private-key-support-for-DH.patch deleted file mode 100644 index 12fcd7df7..000000000 --- a/recipes-connectivity/openssl/openssl-qoriq/qoriq/0007-Fixed-private-key-support-for-DH.patch +++ /dev/null | |||
| @@ -1,35 +0,0 @@ | |||
| 1 | From 8322e4157bf49d992b5b9e460f2c0785865dd1c1 Mon Sep 17 00:00:00 2001 | ||
| 2 | From: Yashpal Dutta <yashpal.dutta@freescale.com> | ||
| 3 | Date: Thu, 20 Mar 2014 19:55:51 -0500 | ||
| 4 | Subject: [PATCH 07/26] Fixed private key support for DH | ||
| 5 | |||
| 6 | Upstream-status: Pending | ||
| 7 | |||
| 8 | Required Length of the DH result is not returned in dh method in openssl | ||
| 9 | |||
| 10 | Tested-by: Yashpal Dutta <yashpal.dutta@freescale.com> | ||
| 11 | --- | ||
| 12 | crypto/dh/dh_ameth.c | 7 ------- | ||
| 13 | 1 file changed, 7 deletions(-) | ||
| 14 | |||
| 15 | diff --git a/crypto/dh/dh_ameth.c b/crypto/dh/dh_ameth.c | ||
| 16 | index ed32004..02ec2d4 100644 | ||
| 17 | --- a/crypto/dh/dh_ameth.c | ||
| 18 | +++ b/crypto/dh/dh_ameth.c | ||
| 19 | @@ -422,13 +422,6 @@ static int dh_copy_parameters(EVP_PKEY *to, const EVP_PKEY *from) | ||
| 20 | if (to->pkey.dh->g != NULL) | ||
| 21 | BN_free(to->pkey.dh->g); | ||
| 22 | to->pkey.dh->g=a; | ||
| 23 | - if ((a=BN_dup(from->pkey.dh->q)) != NULL) { | ||
| 24 | - if (to->pkey.dh->q != NULL) | ||
| 25 | - BN_free(to->pkey.dh->q); | ||
| 26 | - to->pkey.dh->q=a; | ||
| 27 | - } | ||
| 28 | - | ||
| 29 | - to->pkey.dh->length = from->pkey.dh->length; | ||
| 30 | |||
| 31 | return 1; | ||
| 32 | } | ||
| 33 | -- | ||
| 34 | 2.3.5 | ||
| 35 | |||
diff --git a/recipes-connectivity/openssl/openssl-qoriq/qoriq/0008-Add-RSA-keygen-operation-and-support-gendsa-command-.patch b/recipes-connectivity/openssl/openssl-qoriq/qoriq/0008-Add-RSA-keygen-operation-and-support-gendsa-command-.patch new file mode 100644 index 000000000..ccd24e316 --- /dev/null +++ b/recipes-connectivity/openssl/openssl-qoriq/qoriq/0008-Add-RSA-keygen-operation-and-support-gendsa-command-.patch | |||
| @@ -0,0 +1,155 @@ | |||
| 1 | From 94a3fc9f437c20726209cea19256c419837055a2 Mon Sep 17 00:00:00 2001 | ||
| 2 | From: Hou Zhiqiang <B48286@freescale.com> | ||
| 3 | Date: Wed, 2 Apr 2014 16:10:43 +0800 | ||
| 4 | Subject: [PATCH 08/48] Add RSA keygen operation and support gendsa command | ||
| 5 | with hardware engine | ||
| 6 | |||
| 7 | Upstream-status: Pending | ||
| 8 | |||
| 9 | Signed-off-by: Hou Zhiqiang <B48286@freescale.com> | ||
| 10 | Tested-by: Cristian Stoica <cristian.stoica@freescale.com> | ||
| 11 | --- | ||
| 12 | crypto/engine/eng_cryptodev.c | 120 ++++++++++++++++++++++++++++++++++++++++++ | ||
| 13 | 1 file changed, 120 insertions(+) | ||
| 14 | |||
| 15 | diff --git a/crypto/engine/eng_cryptodev.c b/crypto/engine/eng_cryptodev.c | ||
| 16 | index 8303630..44017a3 100644 | ||
| 17 | --- a/crypto/engine/eng_cryptodev.c | ||
| 18 | +++ b/crypto/engine/eng_cryptodev.c | ||
| 19 | @@ -2009,6 +2009,124 @@ cryptodev_dsa_verify(const unsigned char *dgst, int dlen, | ||
| 20 | } | ||
| 21 | } | ||
| 22 | |||
| 23 | +/* Cryptodev RSA Key Gen routine */ | ||
| 24 | +static int cryptodev_rsa_keygen(RSA *rsa, int bits, BIGNUM *e, BN_GENCB *cb) | ||
| 25 | +{ | ||
| 26 | + struct crypt_kop kop; | ||
| 27 | + int ret, fd; | ||
| 28 | + int p_len, q_len; | ||
| 29 | + int i; | ||
| 30 | + | ||
| 31 | + if ((fd = get_asym_dev_crypto()) < 0) | ||
| 32 | + return fd; | ||
| 33 | + | ||
| 34 | + if (!rsa->n && ((rsa->n = BN_new()) == NULL)) | ||
| 35 | + goto err; | ||
| 36 | + if (!rsa->d && ((rsa->d = BN_new()) == NULL)) | ||
| 37 | + goto err; | ||
| 38 | + if (!rsa->e && ((rsa->e = BN_new()) == NULL)) | ||
| 39 | + goto err; | ||
| 40 | + if (!rsa->p && ((rsa->p = BN_new()) == NULL)) | ||
| 41 | + goto err; | ||
| 42 | + if (!rsa->q && ((rsa->q = BN_new()) == NULL)) | ||
| 43 | + goto err; | ||
| 44 | + if (!rsa->dmp1 && ((rsa->dmp1 = BN_new()) == NULL)) | ||
| 45 | + goto err; | ||
| 46 | + if (!rsa->dmq1 && ((rsa->dmq1 = BN_new()) == NULL)) | ||
| 47 | + goto err; | ||
| 48 | + if (!rsa->iqmp && ((rsa->iqmp = BN_new()) == NULL)) | ||
| 49 | + goto err; | ||
| 50 | + | ||
| 51 | + BN_copy(rsa->e, e); | ||
| 52 | + | ||
| 53 | + p_len = (bits + 1) / (2 * 8); | ||
| 54 | + q_len = (bits - p_len * 8) / 8; | ||
| 55 | + memset(&kop, 0, sizeof kop); | ||
| 56 | + kop.crk_op = CRK_RSA_GENERATE_KEY; | ||
| 57 | + | ||
| 58 | + /* p length */ | ||
| 59 | + kop.crk_param[kop.crk_iparams].crp_p = calloc(p_len + 1, sizeof(char)); | ||
| 60 | + if (!kop.crk_param[kop.crk_iparams].crp_p) | ||
| 61 | + goto err; | ||
| 62 | + kop.crk_param[kop.crk_iparams].crp_nbits = p_len * 8; | ||
| 63 | + memset(kop.crk_param[kop.crk_iparams].crp_p, 0xff, p_len + 1); | ||
| 64 | + kop.crk_iparams++; | ||
| 65 | + kop.crk_oparams++; | ||
| 66 | + /* q length */ | ||
| 67 | + kop.crk_param[kop.crk_iparams].crp_p = calloc(q_len + 1, sizeof(char)); | ||
| 68 | + if (!kop.crk_param[kop.crk_iparams].crp_p) | ||
| 69 | + goto err; | ||
| 70 | + kop.crk_param[kop.crk_iparams].crp_nbits = q_len * 8; | ||
| 71 | + memset(kop.crk_param[kop.crk_iparams].crp_p, 0xff, q_len + 1); | ||
| 72 | + kop.crk_iparams++; | ||
| 73 | + kop.crk_oparams++; | ||
| 74 | + /* n length */ | ||
| 75 | + kop.crk_param[kop.crk_iparams].crp_p = | ||
| 76 | + calloc(p_len + q_len + 1, sizeof(char)); | ||
| 77 | + if (!kop.crk_param[kop.crk_iparams].crp_p) | ||
| 78 | + goto err; | ||
| 79 | + kop.crk_param[kop.crk_iparams].crp_nbits = bits; | ||
| 80 | + memset(kop.crk_param[kop.crk_iparams].crp_p, 0x00, p_len + q_len + 1); | ||
| 81 | + kop.crk_iparams++; | ||
| 82 | + kop.crk_oparams++; | ||
| 83 | + /* d length */ | ||
| 84 | + kop.crk_param[kop.crk_iparams].crp_p = | ||
| 85 | + calloc(p_len + q_len + 1, sizeof(char)); | ||
| 86 | + if (!kop.crk_param[kop.crk_iparams].crp_p) | ||
| 87 | + goto err; | ||
| 88 | + kop.crk_param[kop.crk_iparams].crp_nbits = bits; | ||
| 89 | + memset(kop.crk_param[kop.crk_iparams].crp_p, 0xff, p_len + q_len + 1); | ||
| 90 | + kop.crk_iparams++; | ||
| 91 | + kop.crk_oparams++; | ||
| 92 | + /* dp1 length */ | ||
| 93 | + kop.crk_param[kop.crk_iparams].crp_p = calloc(p_len + 1, sizeof(char)); | ||
| 94 | + if (!kop.crk_param[kop.crk_iparams].crp_p) | ||
| 95 | + goto err; | ||
| 96 | + kop.crk_param[kop.crk_iparams].crp_nbits = p_len * 8; | ||
| 97 | + memset(kop.crk_param[kop.crk_iparams].crp_p, 0xff, p_len + 1); | ||
| 98 | + kop.crk_iparams++; | ||
| 99 | + kop.crk_oparams++; | ||
| 100 | + /* dq1 length */ | ||
| 101 | + kop.crk_param[kop.crk_iparams].crp_p = calloc(q_len + 1, sizeof(char)); | ||
| 102 | + if (!kop.crk_param[kop.crk_iparams].crp_p) | ||
| 103 | + goto err; | ||
| 104 | + kop.crk_param[kop.crk_iparams].crp_nbits = q_len * 8; | ||
| 105 | + memset(kop.crk_param[kop.crk_iparams].crp_p, 0xff, q_len + 1); | ||
| 106 | + kop.crk_iparams++; | ||
| 107 | + kop.crk_oparams++; | ||
| 108 | + /* i length */ | ||
| 109 | + kop.crk_param[kop.crk_iparams].crp_p = calloc(p_len + 1, sizeof(char)); | ||
| 110 | + if (!kop.crk_param[kop.crk_iparams].crp_p) | ||
| 111 | + goto err; | ||
| 112 | + kop.crk_param[kop.crk_iparams].crp_nbits = p_len * 8; | ||
| 113 | + memset(kop.crk_param[kop.crk_iparams].crp_p, 0xff, p_len + 1); | ||
| 114 | + kop.crk_iparams++; | ||
| 115 | + kop.crk_oparams++; | ||
| 116 | + | ||
| 117 | + if (ioctl(fd, CIOCKEY, &kop) == 0) { | ||
| 118 | + BN_bin2bn(kop.crk_param[0].crp_p, p_len, rsa->p); | ||
| 119 | + BN_bin2bn(kop.crk_param[1].crp_p, q_len, rsa->q); | ||
| 120 | + BN_bin2bn(kop.crk_param[2].crp_p, bits / 8, rsa->n); | ||
| 121 | + BN_bin2bn(kop.crk_param[3].crp_p, bits / 8, rsa->d); | ||
| 122 | + BN_bin2bn(kop.crk_param[4].crp_p, p_len, rsa->dmp1); | ||
| 123 | + BN_bin2bn(kop.crk_param[5].crp_p, q_len, rsa->dmq1); | ||
| 124 | + BN_bin2bn(kop.crk_param[6].crp_p, p_len, rsa->iqmp); | ||
| 125 | + return 1; | ||
| 126 | + } | ||
| 127 | + sw_try: | ||
| 128 | + { | ||
| 129 | + const RSA_METHOD *meth = RSA_PKCS1_SSLeay(); | ||
| 130 | + ret = (meth->rsa_keygen) (rsa, bits, e, cb); | ||
| 131 | + } | ||
| 132 | + return ret; | ||
| 133 | + | ||
| 134 | + err: | ||
| 135 | + for (i = 0; i < CRK_MAXPARAM; i++) | ||
| 136 | + free(kop.crk_param[i].crp_p); | ||
| 137 | + return 0; | ||
| 138 | + | ||
| 139 | +} | ||
| 140 | + | ||
| 141 | /* Cryptodev DSA Key Gen routine */ | ||
| 142 | static int cryptodev_dsa_keygen(DSA *dsa) | ||
| 143 | { | ||
| 144 | @@ -4035,6 +4153,8 @@ void ENGINE_load_cryptodev(void) | ||
| 145 | cryptodev_rsa.rsa_mod_exp_async = | ||
| 146 | cryptodev_rsa_nocrt_mod_exp_async; | ||
| 147 | } | ||
| 148 | + if (cryptodev_asymfeat & CRF_RSA_GENERATE_KEY) | ||
| 149 | + cryptodev_rsa.rsa_keygen = cryptodev_rsa_keygen; | ||
| 150 | } | ||
| 151 | } | ||
| 152 | |||
| 153 | -- | ||
| 154 | 2.7.0 | ||
| 155 | |||
diff --git a/recipes-connectivity/openssl/openssl-qoriq/qoriq/0008-Initial-support-for-PKC-in-cryptodev-engine.patch b/recipes-connectivity/openssl/openssl-qoriq/qoriq/0008-Initial-support-for-PKC-in-cryptodev-engine.patch deleted file mode 100644 index 98272abf2..000000000 --- a/recipes-connectivity/openssl/openssl-qoriq/qoriq/0008-Initial-support-for-PKC-in-cryptodev-engine.patch +++ /dev/null | |||
| @@ -1,1564 +0,0 @@ | |||
| 1 | From 107a10d45db0f2e58482f698add04ed9183f7268 Mon Sep 17 00:00:00 2001 | ||
| 2 | From: Yashpal Dutta <yashpal.dutta@freescale.com> | ||
| 3 | Date: Tue, 11 Mar 2014 06:29:52 +0545 | ||
| 4 | Subject: [PATCH 08/26] Initial support for PKC in cryptodev engine | ||
| 5 | |||
| 6 | Upstream-status: Pending | ||
| 7 | |||
| 8 | Signed-off-by: Yashpal Dutta <yashpal.dutta@freescale.com> | ||
| 9 | --- | ||
| 10 | crypto/engine/eng_cryptodev.c | 1343 ++++++++++++++++++++++++++++++++++++----- | ||
| 11 | 1 file changed, 1183 insertions(+), 160 deletions(-) | ||
| 12 | |||
| 13 | diff --git a/crypto/engine/eng_cryptodev.c b/crypto/engine/eng_cryptodev.c | ||
| 14 | index e3eb98b..7ee314b 100644 | ||
| 15 | --- a/crypto/engine/eng_cryptodev.c | ||
| 16 | +++ b/crypto/engine/eng_cryptodev.c | ||
| 17 | @@ -54,11 +54,14 @@ ENGINE_load_cryptodev(void) | ||
| 18 | #else | ||
| 19 | |||
| 20 | #include <sys/types.h> | ||
| 21 | -#include <crypto/cryptodev.h> | ||
| 22 | #include <crypto/dh/dh.h> | ||
| 23 | #include <crypto/dsa/dsa.h> | ||
| 24 | #include <crypto/err/err.h> | ||
| 25 | #include <crypto/rsa/rsa.h> | ||
| 26 | +#include <crypto/ecdsa/ecs_locl.h> | ||
| 27 | +#include <crypto/ecdh/ech_locl.h> | ||
| 28 | +#include <crypto/ec/ec_lcl.h> | ||
| 29 | +#include <crypto/ec/ec.h> | ||
| 30 | #include <sys/ioctl.h> | ||
| 31 | #include <errno.h> | ||
| 32 | #include <stdio.h> | ||
| 33 | @@ -68,6 +71,8 @@ ENGINE_load_cryptodev(void) | ||
| 34 | #include <syslog.h> | ||
| 35 | #include <errno.h> | ||
| 36 | #include <string.h> | ||
| 37 | +#include "eng_cryptodev_ec.h" | ||
| 38 | +#include <crypto/cryptodev.h> | ||
| 39 | |||
| 40 | struct dev_crypto_state { | ||
| 41 | struct session_op d_sess; | ||
| 42 | @@ -116,18 +121,10 @@ static int cryptodev_bn_mod_exp(BIGNUM *r, const BIGNUM *a, | ||
| 43 | static int cryptodev_rsa_nocrt_mod_exp(BIGNUM *r0, const BIGNUM *I, | ||
| 44 | RSA *rsa, BN_CTX *ctx); | ||
| 45 | static int cryptodev_rsa_mod_exp(BIGNUM *r0, const BIGNUM *I, RSA *rsa, BN_CTX *ctx); | ||
| 46 | -static int cryptodev_dsa_bn_mod_exp(DSA *dsa, BIGNUM *r, BIGNUM *a, | ||
| 47 | - const BIGNUM *p, const BIGNUM *m, BN_CTX *ctx, BN_MONT_CTX *m_ctx); | ||
| 48 | -static int cryptodev_dsa_dsa_mod_exp(DSA *dsa, BIGNUM *t1, BIGNUM *g, | ||
| 49 | - BIGNUM *u1, BIGNUM *pub_key, BIGNUM *u2, BIGNUM *p, | ||
| 50 | - BN_CTX *ctx, BN_MONT_CTX *mont); | ||
| 51 | static DSA_SIG *cryptodev_dsa_do_sign(const unsigned char *dgst, | ||
| 52 | int dlen, DSA *dsa); | ||
| 53 | static int cryptodev_dsa_verify(const unsigned char *dgst, int dgst_len, | ||
| 54 | DSA_SIG *sig, DSA *dsa); | ||
| 55 | -static int cryptodev_mod_exp_dh(const DH *dh, BIGNUM *r, const BIGNUM *a, | ||
| 56 | - const BIGNUM *p, const BIGNUM *m, BN_CTX *ctx, | ||
| 57 | - BN_MONT_CTX *m_ctx); | ||
| 58 | static int cryptodev_dh_compute_key(unsigned char *key, | ||
| 59 | const BIGNUM *pub_key, DH *dh); | ||
| 60 | static int cryptodev_ctrl(ENGINE *e, int cmd, long i, void *p, | ||
| 61 | @@ -136,6 +133,102 @@ void ENGINE_load_cryptodev(void); | ||
| 62 | const EVP_CIPHER cryptodev_aes_128_cbc_hmac_sha1; | ||
| 63 | const EVP_CIPHER cryptodev_aes_256_cbc_hmac_sha1; | ||
| 64 | |||
| 65 | +static int spcf_bn2bin(BIGNUM *bn, unsigned char **bin, int *bin_len) | ||
| 66 | +{ | ||
| 67 | + int len; | ||
| 68 | + unsigned char *p; | ||
| 69 | + | ||
| 70 | + len = BN_num_bytes(bn); | ||
| 71 | + | ||
| 72 | + if (!len) | ||
| 73 | + return -1; | ||
| 74 | + | ||
| 75 | + p = malloc(len); | ||
| 76 | + if (!p) | ||
| 77 | + return -1; | ||
| 78 | + | ||
| 79 | + BN_bn2bin(bn,p); | ||
| 80 | + | ||
| 81 | + *bin = p; | ||
| 82 | + *bin_len = len; | ||
| 83 | + | ||
| 84 | + return 0; | ||
| 85 | +} | ||
| 86 | + | ||
| 87 | +static int spcf_bn2bin_ex(BIGNUM *bn, unsigned char **bin, int *bin_len) | ||
| 88 | +{ | ||
| 89 | + int len; | ||
| 90 | + unsigned char *p; | ||
| 91 | + | ||
| 92 | + len = BN_num_bytes(bn); | ||
| 93 | + | ||
| 94 | + if (!len) | ||
| 95 | + return -1; | ||
| 96 | + | ||
| 97 | + if (len < *bin_len) | ||
| 98 | + p = malloc(*bin_len); | ||
| 99 | + else | ||
| 100 | + p = malloc(len); | ||
| 101 | + | ||
| 102 | + if (!p) | ||
| 103 | + return -ENOMEM; | ||
| 104 | + | ||
| 105 | + if (len < *bin_len) { | ||
| 106 | + /* place padding */ | ||
| 107 | + memset(p, 0, (*bin_len - len)); | ||
| 108 | + BN_bn2bin(bn,p+(*bin_len-len)); | ||
| 109 | + } else { | ||
| 110 | + BN_bn2bin(bn,p); | ||
| 111 | + } | ||
| 112 | + | ||
| 113 | + *bin = p; | ||
| 114 | + if (len >= *bin_len) | ||
| 115 | + *bin_len = len; | ||
| 116 | + | ||
| 117 | + return 0; | ||
| 118 | +} | ||
| 119 | + | ||
| 120 | +/** | ||
| 121 | + * Convert an ECC F2m 'b' parameter into the 'c' parameter. | ||
| 122 | + *Inputs: | ||
| 123 | + * q, the curve's modulus | ||
| 124 | + * b, the curve's b parameter | ||
| 125 | + * (a bignum for b, a buffer for c) | ||
| 126 | + * Output: | ||
| 127 | + * c, written into bin, right-adjusted to fill q_len bytes. | ||
| 128 | + */ | ||
| 129 | +static int | ||
| 130 | +eng_ec_compute_cparam(const BIGNUM* b, const BIGNUM* q, | ||
| 131 | + unsigned char **bin, int *bin_len) | ||
| 132 | +{ | ||
| 133 | + BIGNUM* c = BN_new(); | ||
| 134 | + BIGNUM* exp = BN_new(); | ||
| 135 | + BN_CTX *ctx = BN_CTX_new(); | ||
| 136 | + int m = BN_num_bits(q) - 1; | ||
| 137 | + int ok = 0; | ||
| 138 | + | ||
| 139 | + if (!c || !exp || !ctx || *bin) | ||
| 140 | + goto err; | ||
| 141 | + | ||
| 142 | + /* | ||
| 143 | + * We have to compute c, where b = c^4, i.e., the fourth root of b. | ||
| 144 | + * The equation for c is c = b^(2^(m-2)) | ||
| 145 | + * Compute exp = 2^(m-2) | ||
| 146 | + * (1 << x) == 2^x | ||
| 147 | + * and then compute c = b^exp | ||
| 148 | + */ | ||
| 149 | + BN_lshift(exp, BN_value_one(), m-2); | ||
| 150 | + BN_GF2m_mod_exp(c, b, exp, q, ctx); | ||
| 151 | + /* Store c */ | ||
| 152 | + spcf_bn2bin_ex(c, bin, bin_len); | ||
| 153 | + ok = 1; | ||
| 154 | +err: | ||
| 155 | + if (ctx) BN_CTX_free(ctx); | ||
| 156 | + if (c) BN_free(c); | ||
| 157 | + if (exp) BN_free(exp); | ||
| 158 | + return ok; | ||
| 159 | +} | ||
| 160 | + | ||
| 161 | static const ENGINE_CMD_DEFN cryptodev_defns[] = { | ||
| 162 | { 0, NULL, NULL, 0 } | ||
| 163 | }; | ||
| 164 | @@ -1139,7 +1232,6 @@ cryptodev_engine_digests(ENGINE *e, const EVP_MD **digest, | ||
| 165 | static int | ||
| 166 | bn2crparam(const BIGNUM *a, struct crparam *crp) | ||
| 167 | { | ||
| 168 | - int i, j, k; | ||
| 169 | ssize_t bytes, bits; | ||
| 170 | u_char *b; | ||
| 171 | |||
| 172 | @@ -1156,15 +1248,7 @@ bn2crparam(const BIGNUM *a, struct crparam *crp) | ||
| 173 | |||
| 174 | crp->crp_p = (caddr_t) b; | ||
| 175 | crp->crp_nbits = bits; | ||
| 176 | - | ||
| 177 | - for (i = 0, j = 0; i < a->top; i++) { | ||
| 178 | - for (k = 0; k < BN_BITS2 / 8; k++) { | ||
| 179 | - if ((j + k) >= bytes) | ||
| 180 | - return (0); | ||
| 181 | - b[j + k] = a->d[i] >> (k * 8); | ||
| 182 | - } | ||
| 183 | - j += BN_BITS2 / 8; | ||
| 184 | - } | ||
| 185 | + BN_bn2bin(a, crp->crp_p); | ||
| 186 | return (0); | ||
| 187 | } | ||
| 188 | |||
| 189 | @@ -1172,22 +1256,14 @@ bn2crparam(const BIGNUM *a, struct crparam *crp) | ||
| 190 | static int | ||
| 191 | crparam2bn(struct crparam *crp, BIGNUM *a) | ||
| 192 | { | ||
| 193 | - u_int8_t *pd; | ||
| 194 | - int i, bytes; | ||
| 195 | + int bytes; | ||
| 196 | |||
| 197 | bytes = (crp->crp_nbits + 7) / 8; | ||
| 198 | |||
| 199 | if (bytes == 0) | ||
| 200 | return (-1); | ||
| 201 | |||
| 202 | - if ((pd = (u_int8_t *) malloc(bytes)) == NULL) | ||
| 203 | - return (-1); | ||
| 204 | - | ||
| 205 | - for (i = 0; i < bytes; i++) | ||
| 206 | - pd[i] = crp->crp_p[bytes - i - 1]; | ||
| 207 | - | ||
| 208 | - BN_bin2bn(pd, bytes, a); | ||
| 209 | - free(pd); | ||
| 210 | + BN_bin2bn(crp->crp_p, bytes, a); | ||
| 211 | |||
| 212 | return (0); | ||
| 213 | } | ||
| 214 | @@ -1235,6 +1311,32 @@ cryptodev_asym(struct crypt_kop *kop, int rlen, BIGNUM *r, int slen, BIGNUM *s) | ||
| 215 | return (ret); | ||
| 216 | } | ||
| 217 | |||
| 218 | +/* Close an opened instance of cryptodev engine */ | ||
| 219 | +void cryptodev_close_instance(void *handle) | ||
| 220 | +{ | ||
| 221 | + int fd; | ||
| 222 | + | ||
| 223 | + if (handle) { | ||
| 224 | + fd = *(int *)handle; | ||
| 225 | + close(fd); | ||
| 226 | + free(handle); | ||
| 227 | + } | ||
| 228 | +} | ||
| 229 | + | ||
| 230 | +/* Create an instance of cryptodev for asynchronous interface */ | ||
| 231 | +void *cryptodev_init_instance(void) | ||
| 232 | +{ | ||
| 233 | + int *fd = malloc(sizeof(int)); | ||
| 234 | + | ||
| 235 | + if (fd) { | ||
| 236 | + if ((*fd = open("/dev/crypto", O_RDWR, 0)) == -1) { | ||
| 237 | + free(fd); | ||
| 238 | + return NULL; | ||
| 239 | + } | ||
| 240 | + } | ||
| 241 | + return fd; | ||
| 242 | +} | ||
| 243 | + | ||
| 244 | static int | ||
| 245 | cryptodev_bn_mod_exp(BIGNUM *r, const BIGNUM *a, const BIGNUM *p, | ||
| 246 | const BIGNUM *m, BN_CTX *ctx, BN_MONT_CTX *in_mont) | ||
| 247 | @@ -1250,9 +1352,9 @@ cryptodev_bn_mod_exp(BIGNUM *r, const BIGNUM *a, const BIGNUM *p, | ||
| 248 | return (ret); | ||
| 249 | } | ||
| 250 | |||
| 251 | - memset(&kop, 0, sizeof kop); | ||
| 252 | kop.crk_op = CRK_MOD_EXP; | ||
| 253 | - | ||
| 254 | + kop.crk_oparams = 0; | ||
| 255 | + kop.crk_status = 0; | ||
| 256 | /* inputs: a^p % m */ | ||
| 257 | if (bn2crparam(a, &kop.crk_param[0])) | ||
| 258 | goto err; | ||
| 259 | @@ -1293,28 +1395,38 @@ static int | ||
| 260 | cryptodev_rsa_mod_exp(BIGNUM *r0, const BIGNUM *I, RSA *rsa, BN_CTX *ctx) | ||
| 261 | { | ||
| 262 | struct crypt_kop kop; | ||
| 263 | - int ret = 1; | ||
| 264 | + int ret = 1, f_len, p_len, q_len; | ||
| 265 | + unsigned char *f = NULL, *p = NULL, *q = NULL, *dp = NULL, *dq = NULL, *c = NULL; | ||
| 266 | |||
| 267 | if (!rsa->p || !rsa->q || !rsa->dmp1 || !rsa->dmq1 || !rsa->iqmp) { | ||
| 268 | /* XXX 0 means failure?? */ | ||
| 269 | return (0); | ||
| 270 | } | ||
| 271 | |||
| 272 | - memset(&kop, 0, sizeof kop); | ||
| 273 | + kop.crk_oparams = 0; | ||
| 274 | + kop.crk_status = 0; | ||
| 275 | kop.crk_op = CRK_MOD_EXP_CRT; | ||
| 276 | + f_len = BN_num_bytes(rsa->n); | ||
| 277 | + spcf_bn2bin_ex(I, &f, &f_len); | ||
| 278 | + spcf_bn2bin(rsa->p, &p, &p_len); | ||
| 279 | + spcf_bn2bin(rsa->q, &q, &q_len); | ||
| 280 | + spcf_bn2bin_ex(rsa->dmp1, &dp, &p_len); | ||
| 281 | + spcf_bn2bin_ex(rsa->iqmp, &c, &p_len); | ||
| 282 | + spcf_bn2bin_ex(rsa->dmq1, &dq, &q_len); | ||
| 283 | /* inputs: rsa->p rsa->q I rsa->dmp1 rsa->dmq1 rsa->iqmp */ | ||
| 284 | - if (bn2crparam(rsa->p, &kop.crk_param[0])) | ||
| 285 | - goto err; | ||
| 286 | - if (bn2crparam(rsa->q, &kop.crk_param[1])) | ||
| 287 | - goto err; | ||
| 288 | - if (bn2crparam(I, &kop.crk_param[2])) | ||
| 289 | - goto err; | ||
| 290 | - if (bn2crparam(rsa->dmp1, &kop.crk_param[3])) | ||
| 291 | - goto err; | ||
| 292 | - if (bn2crparam(rsa->dmq1, &kop.crk_param[4])) | ||
| 293 | - goto err; | ||
| 294 | - if (bn2crparam(rsa->iqmp, &kop.crk_param[5])) | ||
| 295 | - goto err; | ||
| 296 | + kop.crk_param[0].crp_p = p; | ||
| 297 | + kop.crk_param[0].crp_nbits = p_len * 8; | ||
| 298 | + kop.crk_param[1].crp_p = q; | ||
| 299 | + kop.crk_param[1].crp_nbits = q_len * 8; | ||
| 300 | + kop.crk_param[2].crp_p = f; | ||
| 301 | + kop.crk_param[2].crp_nbits = f_len * 8; | ||
| 302 | + kop.crk_param[3].crp_p = dp; | ||
| 303 | + kop.crk_param[3].crp_nbits = p_len * 8; | ||
| 304 | + /* dq must of length q, rest all of length p*/ | ||
| 305 | + kop.crk_param[4].crp_p = dq; | ||
| 306 | + kop.crk_param[4].crp_nbits = q_len * 8; | ||
| 307 | + kop.crk_param[5].crp_p = c; | ||
| 308 | + kop.crk_param[5].crp_nbits = p_len * 8; | ||
| 309 | kop.crk_iparams = 6; | ||
| 310 | |||
| 311 | if (cryptodev_asym(&kop, BN_num_bytes(rsa->n), r0, 0, NULL)) { | ||
| 312 | @@ -1350,90 +1462,117 @@ static RSA_METHOD cryptodev_rsa = { | ||
| 313 | NULL /* rsa_verify */ | ||
| 314 | }; | ||
| 315 | |||
| 316 | -static int | ||
| 317 | -cryptodev_dsa_bn_mod_exp(DSA *dsa, BIGNUM *r, BIGNUM *a, const BIGNUM *p, | ||
| 318 | - const BIGNUM *m, BN_CTX *ctx, BN_MONT_CTX *m_ctx) | ||
| 319 | -{ | ||
| 320 | - return (cryptodev_bn_mod_exp(r, a, p, m, ctx, m_ctx)); | ||
| 321 | -} | ||
| 322 | - | ||
| 323 | -static int | ||
| 324 | -cryptodev_dsa_dsa_mod_exp(DSA *dsa, BIGNUM *t1, BIGNUM *g, | ||
| 325 | - BIGNUM *u1, BIGNUM *pub_key, BIGNUM *u2, BIGNUM *p, | ||
| 326 | - BN_CTX *ctx, BN_MONT_CTX *mont) | ||
| 327 | +static DSA_SIG * | ||
| 328 | +cryptodev_dsa_do_sign(const unsigned char *dgst, int dlen, DSA *dsa) | ||
| 329 | { | ||
| 330 | - BIGNUM t2; | ||
| 331 | - int ret = 0; | ||
| 332 | - | ||
| 333 | - BN_init(&t2); | ||
| 334 | - | ||
| 335 | - /* v = ( g^u1 * y^u2 mod p ) mod q */ | ||
| 336 | - /* let t1 = g ^ u1 mod p */ | ||
| 337 | - ret = 0; | ||
| 338 | + struct crypt_kop kop; | ||
| 339 | + BIGNUM *c = NULL, *d = NULL; | ||
| 340 | + DSA_SIG *dsaret = NULL; | ||
| 341 | + int q_len = 0, r_len = 0, g_len = 0; | ||
| 342 | + int priv_key_len = 0, ret; | ||
| 343 | + unsigned char *q = NULL, *r = NULL, *g = NULL, *priv_key = NULL, *f = NULL; | ||
| 344 | |||
| 345 | - if (!dsa->meth->bn_mod_exp(dsa,t1,dsa->g,u1,dsa->p,ctx,mont)) | ||
| 346 | + memset(&kop, 0, sizeof kop); | ||
| 347 | + if ((c = BN_new()) == NULL) { | ||
| 348 | + DSAerr(DSA_F_DSA_DO_SIGN, ERR_R_MALLOC_FAILURE); | ||
| 349 | goto err; | ||
| 350 | + } | ||
| 351 | |||
| 352 | - /* let t2 = y ^ u2 mod p */ | ||
| 353 | - if (!dsa->meth->bn_mod_exp(dsa,&t2,dsa->pub_key,u2,dsa->p,ctx,mont)) | ||
| 354 | + if ((d = BN_new()) == NULL) { | ||
| 355 | + BN_free(c); | ||
| 356 | + DSAerr(DSA_F_DSA_DO_SIGN, ERR_R_MALLOC_FAILURE); | ||
| 357 | goto err; | ||
| 358 | - /* let u1 = t1 * t2 mod p */ | ||
| 359 | - if (!BN_mod_mul(u1,t1,&t2,dsa->p,ctx)) | ||
| 360 | + } | ||
| 361 | + | ||
| 362 | + if (spcf_bn2bin(dsa->p, &q, &q_len)) { | ||
| 363 | + DSAerr(DSA_F_DSA_DO_SIGN, DSA_R_DATA_TOO_LARGE_FOR_KEY_SIZE); | ||
| 364 | goto err; | ||
| 365 | + } | ||
| 366 | |||
| 367 | - BN_copy(t1,u1); | ||
| 368 | + /* Get order of the field of private keys into plain buffer */ | ||
| 369 | + if (spcf_bn2bin (dsa->q, &r, &r_len)) { | ||
| 370 | + DSAerr(DSA_F_DSA_DO_SIGN, ERR_R_MALLOC_FAILURE); | ||
| 371 | + goto err; | ||
| 372 | + } | ||
| 373 | |||
| 374 | - ret = 1; | ||
| 375 | -err: | ||
| 376 | - BN_free(&t2); | ||
| 377 | - return(ret); | ||
| 378 | -} | ||
| 379 | + /* sanity test */ | ||
| 380 | + if (dlen > r_len) { | ||
| 381 | + DSAerr(DSA_F_DSA_DO_SIGN, DSA_R_DATA_TOO_LARGE_FOR_KEY_SIZE); | ||
| 382 | + goto err; | ||
| 383 | + } | ||
| 384 | |||
| 385 | -static DSA_SIG * | ||
| 386 | -cryptodev_dsa_do_sign(const unsigned char *dgst, int dlen, DSA *dsa) | ||
| 387 | -{ | ||
| 388 | - struct crypt_kop kop; | ||
| 389 | - BIGNUM *r = NULL, *s = NULL; | ||
| 390 | - DSA_SIG *dsaret = NULL; | ||
| 391 | + g_len = q_len; | ||
| 392 | + /** | ||
| 393 | + * Get generator into a plain buffer. If length is less than | ||
| 394 | + * q_len then add leading padding bytes. | ||
| 395 | + */ | ||
| 396 | + if (spcf_bn2bin_ex(dsa->g, &g, &g_len)) { | ||
| 397 | + DSAerr(DSA_F_DSA_DO_SIGN, ERR_R_MALLOC_FAILURE); | ||
| 398 | + goto err; | ||
| 399 | + } | ||
| 400 | |||
| 401 | - if ((r = BN_new()) == NULL) | ||
| 402 | + priv_key_len = r_len; | ||
| 403 | + /** | ||
| 404 | + * Get private key into a plain buffer. If length is less than | ||
| 405 | + * r_len then add leading padding bytes. | ||
| 406 | + */ | ||
| 407 | + if (spcf_bn2bin_ex(dsa->priv_key, &priv_key, &priv_key_len)) { | ||
| 408 | + DSAerr(DSA_F_DSA_DO_SIGN, ERR_R_MALLOC_FAILURE); | ||
| 409 | goto err; | ||
| 410 | - if ((s = BN_new()) == NULL) { | ||
| 411 | - BN_free(r); | ||
| 412 | + } | ||
| 413 | + | ||
| 414 | + /* Allocate memory to store hash. */ | ||
| 415 | + f = OPENSSL_malloc (r_len); | ||
| 416 | + if (!f) { | ||
| 417 | + DSAerr(DSA_F_DSA_DO_SIGN, ERR_R_MALLOC_FAILURE); | ||
| 418 | goto err; | ||
| 419 | } | ||
| 420 | |||
| 421 | - memset(&kop, 0, sizeof kop); | ||
| 422 | + /* Add padding, since SEC expects hash to of size r_len */ | ||
| 423 | + if (dlen < r_len) | ||
| 424 | + memset(f, 0, r_len - dlen); | ||
| 425 | + | ||
| 426 | + /* Skip leading bytes if dgst_len < r_len */ | ||
| 427 | + memcpy(f + r_len - dlen, dgst, dlen); | ||
| 428 | + | ||
| 429 | kop.crk_op = CRK_DSA_SIGN; | ||
| 430 | |||
| 431 | /* inputs: dgst dsa->p dsa->q dsa->g dsa->priv_key */ | ||
| 432 | - kop.crk_param[0].crp_p = (caddr_t)dgst; | ||
| 433 | - kop.crk_param[0].crp_nbits = dlen * 8; | ||
| 434 | - if (bn2crparam(dsa->p, &kop.crk_param[1])) | ||
| 435 | - goto err; | ||
| 436 | - if (bn2crparam(dsa->q, &kop.crk_param[2])) | ||
| 437 | - goto err; | ||
| 438 | - if (bn2crparam(dsa->g, &kop.crk_param[3])) | ||
| 439 | - goto err; | ||
| 440 | - if (bn2crparam(dsa->priv_key, &kop.crk_param[4])) | ||
| 441 | - goto err; | ||
| 442 | + kop.crk_param[0].crp_p = (void*)f; | ||
| 443 | + kop.crk_param[0].crp_nbits = r_len * 8; | ||
| 444 | + kop.crk_param[1].crp_p = (void*)q; | ||
| 445 | + kop.crk_param[1].crp_nbits = q_len * 8; | ||
| 446 | + kop.crk_param[2].crp_p = (void*)r; | ||
| 447 | + kop.crk_param[2].crp_nbits = r_len * 8; | ||
| 448 | + kop.crk_param[3].crp_p = (void*)g; | ||
| 449 | + kop.crk_param[3].crp_nbits = g_len * 8; | ||
| 450 | + kop.crk_param[4].crp_p = (void*)priv_key; | ||
| 451 | + kop.crk_param[4].crp_nbits = priv_key_len * 8; | ||
| 452 | kop.crk_iparams = 5; | ||
| 453 | |||
| 454 | - if (cryptodev_asym(&kop, BN_num_bytes(dsa->q), r, | ||
| 455 | - BN_num_bytes(dsa->q), s) == 0) { | ||
| 456 | - dsaret = DSA_SIG_new(); | ||
| 457 | - dsaret->r = r; | ||
| 458 | - dsaret->s = s; | ||
| 459 | - } else { | ||
| 460 | - const DSA_METHOD *meth = DSA_OpenSSL(); | ||
| 461 | - BN_free(r); | ||
| 462 | - BN_free(s); | ||
| 463 | - dsaret = (meth->dsa_do_sign)(dgst, dlen, dsa); | ||
| 464 | + ret = cryptodev_asym(&kop, r_len, c, r_len, d); | ||
| 465 | + | ||
| 466 | + if (ret) { | ||
| 467 | + DSAerr(DSA_F_DSA_DO_SIGN, DSA_R_DECODE_ERROR); | ||
| 468 | + goto err; | ||
| 469 | } | ||
| 470 | -err: | ||
| 471 | - kop.crk_param[0].crp_p = NULL; | ||
| 472 | + | ||
| 473 | + dsaret = DSA_SIG_new(); | ||
| 474 | + dsaret->r = c; | ||
| 475 | + dsaret->s = d; | ||
| 476 | + | ||
| 477 | zapparams(&kop); | ||
| 478 | return (dsaret); | ||
| 479 | +err: | ||
| 480 | + { | ||
| 481 | + const DSA_METHOD *meth = DSA_OpenSSL(); | ||
| 482 | + if (c) | ||
| 483 | + BN_free(c); | ||
| 484 | + if (d) | ||
| 485 | + BN_free(d); | ||
| 486 | + dsaret = (meth->dsa_do_sign)(dgst, dlen, dsa); | ||
| 487 | + return (dsaret); | ||
| 488 | + } | ||
| 489 | } | ||
| 490 | |||
| 491 | static int | ||
| 492 | @@ -1441,42 +1580,179 @@ cryptodev_dsa_verify(const unsigned char *dgst, int dlen, | ||
| 493 | DSA_SIG *sig, DSA *dsa) | ||
| 494 | { | ||
| 495 | struct crypt_kop kop; | ||
| 496 | - int dsaret = 1; | ||
| 497 | + int dsaret = 1, q_len = 0, r_len = 0, g_len = 0; | ||
| 498 | + int w_len = 0 ,c_len = 0, d_len = 0, ret = -1; | ||
| 499 | + unsigned char * q = NULL, * r = NULL, * w = NULL, * g = NULL; | ||
| 500 | + unsigned char * c = NULL, * d = NULL, *f = NULL; | ||
| 501 | |||
| 502 | memset(&kop, 0, sizeof kop); | ||
| 503 | kop.crk_op = CRK_DSA_VERIFY; | ||
| 504 | |||
| 505 | - /* inputs: dgst dsa->p dsa->q dsa->g dsa->pub_key sig->r sig->s */ | ||
| 506 | - kop.crk_param[0].crp_p = (caddr_t)dgst; | ||
| 507 | - kop.crk_param[0].crp_nbits = dlen * 8; | ||
| 508 | - if (bn2crparam(dsa->p, &kop.crk_param[1])) | ||
| 509 | + if (spcf_bn2bin(dsa->p, &q, &q_len)) { | ||
| 510 | + DSAerr(DSA_F_DSA_DO_VERIFY, ERR_R_MALLOC_FAILURE); | ||
| 511 | + return ret; | ||
| 512 | + } | ||
| 513 | + | ||
| 514 | + /* Get Order of field of private keys */ | ||
| 515 | + if (spcf_bn2bin(dsa->q, &r, &r_len)) { | ||
| 516 | + DSAerr(DSA_F_DSA_DO_VERIFY, ERR_R_MALLOC_FAILURE); | ||
| 517 | goto err; | ||
| 518 | - if (bn2crparam(dsa->q, &kop.crk_param[2])) | ||
| 519 | + } | ||
| 520 | + | ||
| 521 | + g_len = q_len; | ||
| 522 | + /** | ||
| 523 | + * Get generator into a plain buffer. If length is less than | ||
| 524 | + * q_len then add leading padding bytes. | ||
| 525 | + */ | ||
| 526 | + if (spcf_bn2bin_ex(dsa->g, &g, &g_len)) { | ||
| 527 | + DSAerr(DSA_F_DSA_DO_VERIFY, ERR_R_MALLOC_FAILURE); | ||
| 528 | goto err; | ||
| 529 | - if (bn2crparam(dsa->g, &kop.crk_param[3])) | ||
| 530 | + } | ||
| 531 | + w_len = q_len; | ||
| 532 | + /** | ||
| 533 | + * Get public key into a plain buffer. If length is less than | ||
| 534 | + * q_len then add leading padding bytes. | ||
| 535 | + */ | ||
| 536 | + if (spcf_bn2bin_ex(dsa->pub_key, &w, &w_len)) { | ||
| 537 | + DSAerr(DSA_F_DSA_DO_VERIFY, ERR_R_MALLOC_FAILURE); | ||
| 538 | + goto err; | ||
| 539 | + } | ||
| 540 | + /** | ||
| 541 | + * Get the 1st part of signature into a flat buffer with | ||
| 542 | + * appropriate padding | ||
| 543 | + */ | ||
| 544 | + c_len = r_len; | ||
| 545 | + | ||
| 546 | + if (spcf_bn2bin_ex(sig->r, &c, &c_len)) { | ||
| 547 | + ECDSAerr(ECDSA_F_ECDSA_DO_VERIFY, ERR_R_MALLOC_FAILURE); | ||
| 548 | goto err; | ||
| 549 | - if (bn2crparam(dsa->pub_key, &kop.crk_param[4])) | ||
| 550 | + } | ||
| 551 | + | ||
| 552 | + /** | ||
| 553 | + * Get the 2nd part of signature into a flat buffer with | ||
| 554 | + * appropriate padding | ||
| 555 | + */ | ||
| 556 | + d_len = r_len; | ||
| 557 | + | ||
| 558 | + if (spcf_bn2bin_ex(sig->s, &d, &d_len)) { | ||
| 559 | + ECDSAerr(ECDSA_F_ECDSA_DO_VERIFY, ERR_R_MALLOC_FAILURE); | ||
| 560 | goto err; | ||
| 561 | - if (bn2crparam(sig->r, &kop.crk_param[5])) | ||
| 562 | + } | ||
| 563 | + | ||
| 564 | + | ||
| 565 | + /* Sanity test */ | ||
| 566 | + if (dlen > r_len) { | ||
| 567 | + ECDSAerr(ECDSA_F_ECDSA_DO_VERIFY, ERR_R_MALLOC_FAILURE); | ||
| 568 | goto err; | ||
| 569 | - if (bn2crparam(sig->s, &kop.crk_param[6])) | ||
| 570 | + } | ||
| 571 | + | ||
| 572 | + /* Allocate memory to store hash. */ | ||
| 573 | + f = OPENSSL_malloc (r_len); | ||
| 574 | + if (!f) { | ||
| 575 | + DSAerr(ECDSA_F_ECDSA_DO_VERIFY, ERR_R_MALLOC_FAILURE); | ||
| 576 | goto err; | ||
| 577 | + } | ||
| 578 | + | ||
| 579 | + /* Add padding, since SEC expects hash to of size r_len */ | ||
| 580 | + if (dlen < r_len) | ||
| 581 | + memset(f, 0, r_len - dlen); | ||
| 582 | + | ||
| 583 | + /* Skip leading bytes if dgst_len < r_len */ | ||
| 584 | + memcpy(f + r_len - dlen, dgst, dlen); | ||
| 585 | + | ||
| 586 | + /* inputs: dgst dsa->p dsa->q dsa->g dsa->pub_key sig->r sig->s */ | ||
| 587 | + kop.crk_param[0].crp_p = (void*)f; | ||
| 588 | + kop.crk_param[0].crp_nbits = r_len * 8; | ||
| 589 | + kop.crk_param[1].crp_p = q; | ||
| 590 | + kop.crk_param[1].crp_nbits = q_len * 8; | ||
| 591 | + kop.crk_param[2].crp_p = r; | ||
| 592 | + kop.crk_param[2].crp_nbits = r_len * 8; | ||
| 593 | + kop.crk_param[3].crp_p = g; | ||
| 594 | + kop.crk_param[3].crp_nbits = g_len * 8; | ||
| 595 | + kop.crk_param[4].crp_p = w; | ||
| 596 | + kop.crk_param[4].crp_nbits = w_len * 8; | ||
| 597 | + kop.crk_param[5].crp_p = c; | ||
| 598 | + kop.crk_param[5].crp_nbits = c_len * 8; | ||
| 599 | + kop.crk_param[6].crp_p = d; | ||
| 600 | + kop.crk_param[6].crp_nbits = d_len * 8; | ||
| 601 | kop.crk_iparams = 7; | ||
| 602 | |||
| 603 | - if (cryptodev_asym(&kop, 0, NULL, 0, NULL) == 0) { | ||
| 604 | -/*OCF success value is 0, if not zero, change dsaret to fail*/ | ||
| 605 | - if(0 != kop.crk_status) dsaret = 0; | ||
| 606 | - } else { | ||
| 607 | - const DSA_METHOD *meth = DSA_OpenSSL(); | ||
| 608 | + if ((cryptodev_asym(&kop, 0, NULL, 0, NULL))) { | ||
| 609 | + ECDSAerr(ECDSA_F_ECDSA_DO_VERIFY, DSA_R_DECODE_ERROR); | ||
| 610 | + goto err; | ||
| 611 | + } | ||
| 612 | |||
| 613 | - dsaret = (meth->dsa_do_verify)(dgst, dlen, sig, dsa); | ||
| 614 | + /*OCF success value is 0, if not zero, change dsaret to fail*/ | ||
| 615 | + if(0 != kop.crk_status) { | ||
| 616 | + ECDSAerr(ECDSA_F_ECDSA_DO_VERIFY, DSA_R_DECODE_ERROR); | ||
| 617 | + goto err; | ||
| 618 | } | ||
| 619 | -err: | ||
| 620 | - kop.crk_param[0].crp_p = NULL; | ||
| 621 | + | ||
| 622 | zapparams(&kop); | ||
| 623 | return (dsaret); | ||
| 624 | +err: | ||
| 625 | + { | ||
| 626 | + const DSA_METHOD *meth = DSA_OpenSSL(); | ||
| 627 | + | ||
| 628 | + dsaret = (meth->dsa_do_verify)(dgst, dlen, sig, dsa); | ||
| 629 | + } | ||
| 630 | + return dsaret; | ||
| 631 | } | ||
| 632 | |||
| 633 | +/* Cryptodev DSA Key Gen routine */ | ||
| 634 | +static int cryptodev_dsa_keygen(DSA *dsa) | ||
| 635 | +{ | ||
| 636 | + struct crypt_kop kop; | ||
| 637 | + int ret = 1, g_len; | ||
| 638 | + unsigned char *g = NULL; | ||
| 639 | + | ||
| 640 | + if (dsa->priv_key == NULL) { | ||
| 641 | + if ((dsa->priv_key=BN_new()) == NULL) | ||
| 642 | + goto sw_try; | ||
| 643 | + } | ||
| 644 | + | ||
| 645 | + if (dsa->pub_key == NULL) { | ||
| 646 | + if ((dsa->pub_key=BN_new()) == NULL) | ||
| 647 | + goto sw_try; | ||
| 648 | + } | ||
| 649 | + | ||
| 650 | + g_len = BN_num_bytes(dsa->p); | ||
| 651 | + /** | ||
| 652 | + * Get generator into a plain buffer. If length is less than | ||
| 653 | + * p_len then add leading padding bytes. | ||
| 654 | + */ | ||
| 655 | + if (spcf_bn2bin_ex(dsa->g, &g, &g_len)) { | ||
| 656 | + DSAerr(DSA_F_DSA_GENERATE_KEY, ERR_R_MALLOC_FAILURE); | ||
| 657 | + goto sw_try; | ||
| 658 | + } | ||
| 659 | + | ||
| 660 | + memset(&kop, 0, sizeof kop); | ||
| 661 | + | ||
| 662 | + kop.crk_op = CRK_DSA_GENERATE_KEY; | ||
| 663 | + if (bn2crparam(dsa->p, &kop.crk_param[0])) | ||
| 664 | + goto sw_try; | ||
| 665 | + if (bn2crparam(dsa->q, &kop.crk_param[1])) | ||
| 666 | + goto sw_try; | ||
| 667 | + kop.crk_param[2].crp_p = g; | ||
| 668 | + kop.crk_param[2].crp_nbits = g_len * 8; | ||
| 669 | + kop.crk_iparams = 3; | ||
| 670 | + | ||
| 671 | + /* pub_key is or prime length while priv key is of length of order */ | ||
| 672 | + if (cryptodev_asym(&kop, BN_num_bytes(dsa->p), dsa->pub_key, | ||
| 673 | + BN_num_bytes(dsa->q), dsa->priv_key)) | ||
| 674 | + goto sw_try; | ||
| 675 | + | ||
| 676 | + return ret; | ||
| 677 | +sw_try: | ||
| 678 | + { | ||
| 679 | + const DSA_METHOD *meth = DSA_OpenSSL(); | ||
| 680 | + ret = (meth->dsa_keygen)(dsa); | ||
| 681 | + } | ||
| 682 | + return ret; | ||
| 683 | +} | ||
| 684 | + | ||
| 685 | + | ||
| 686 | + | ||
| 687 | static DSA_METHOD cryptodev_dsa = { | ||
| 688 | "cryptodev DSA method", | ||
| 689 | NULL, | ||
| 690 | @@ -1490,12 +1766,543 @@ static DSA_METHOD cryptodev_dsa = { | ||
| 691 | NULL /* app_data */ | ||
| 692 | }; | ||
| 693 | |||
| 694 | -static int | ||
| 695 | -cryptodev_mod_exp_dh(const DH *dh, BIGNUM *r, const BIGNUM *a, | ||
| 696 | - const BIGNUM *p, const BIGNUM *m, BN_CTX *ctx, | ||
| 697 | - BN_MONT_CTX *m_ctx) | ||
| 698 | +static ECDSA_METHOD cryptodev_ecdsa = { | ||
| 699 | + "cryptodev ECDSA method", | ||
| 700 | + NULL, | ||
| 701 | + NULL, /* ecdsa_sign_setup */ | ||
| 702 | + NULL, | ||
| 703 | + NULL, | ||
| 704 | + 0, /* flags */ | ||
| 705 | + NULL /* app_data */ | ||
| 706 | +}; | ||
| 707 | + | ||
| 708 | +typedef enum ec_curve_s | ||
| 709 | +{ | ||
| 710 | + EC_PRIME, | ||
| 711 | + EC_BINARY | ||
| 712 | +} ec_curve_t; | ||
| 713 | + | ||
| 714 | +/* ENGINE handler for ECDSA Sign */ | ||
| 715 | +static ECDSA_SIG *cryptodev_ecdsa_do_sign( const unsigned char *dgst, | ||
| 716 | + int dgst_len, const BIGNUM *in_kinv, const BIGNUM *in_r, EC_KEY *eckey) | ||
| 717 | { | ||
| 718 | - return (cryptodev_bn_mod_exp(r, a, p, m, ctx, m_ctx)); | ||
| 719 | + BIGNUM *m = NULL, *p = NULL, *a = NULL; | ||
| 720 | + BIGNUM *b = NULL, *x = NULL, *y = NULL; | ||
| 721 | + BN_CTX *ctx = NULL; | ||
| 722 | + ECDSA_SIG *ret = NULL; | ||
| 723 | + ECDSA_DATA *ecdsa = NULL; | ||
| 724 | + unsigned char * q = NULL, *r = NULL, *ab = NULL, *g_xy = NULL; | ||
| 725 | + unsigned char * s = NULL, *c = NULL, *d = NULL, *f = NULL, *tmp_dgst = NULL; | ||
| 726 | + int i = 0, q_len = 0, priv_key_len = 0, r_len = 0; | ||
| 727 | + int g_len = 0, d_len = 0, ab_len = 0; | ||
| 728 | + const BIGNUM *order = NULL, *priv_key=NULL; | ||
| 729 | + const EC_GROUP *group = NULL; | ||
| 730 | + struct crypt_kop kop; | ||
| 731 | + ec_curve_t ec_crv = EC_PRIME; | ||
| 732 | + | ||
| 733 | + memset(&kop, 0, sizeof(kop)); | ||
| 734 | + ecdsa = ecdsa_check(eckey); | ||
| 735 | + if (!ecdsa) { | ||
| 736 | + ECDSAerr(ECDSA_F_ECDSA_DO_SIGN, ERR_R_PASSED_NULL_PARAMETER); | ||
| 737 | + return NULL; | ||
| 738 | + } | ||
| 739 | + | ||
| 740 | + group = EC_KEY_get0_group(eckey); | ||
| 741 | + priv_key = EC_KEY_get0_private_key(eckey); | ||
| 742 | + | ||
| 743 | + if (!group || !priv_key) { | ||
| 744 | + ECDSAerr(ECDSA_F_ECDSA_DO_SIGN, ERR_R_PASSED_NULL_PARAMETER); | ||
| 745 | + return NULL; | ||
| 746 | + } | ||
| 747 | + | ||
| 748 | + if ((ctx = BN_CTX_new()) == NULL || (m = BN_new()) == NULL || | ||
| 749 | + (a = BN_new()) == NULL || (b = BN_new()) == NULL || | ||
| 750 | + (p = BN_new()) == NULL || (x = BN_new()) == NULL || | ||
| 751 | + (y = BN_new()) == NULL) { | ||
| 752 | + ECDSAerr(ECDSA_F_ECDSA_DO_SIGN, ERR_R_MALLOC_FAILURE); | ||
| 753 | + goto err; | ||
| 754 | + } | ||
| 755 | + | ||
| 756 | + order = &group->order; | ||
| 757 | + if (!order || BN_is_zero(order)) { | ||
| 758 | + ECDSAerr(ECDSA_F_ECDSA_DO_SIGN, ECDSA_R_MISSING_PARAMETERS); | ||
| 759 | + goto err; | ||
| 760 | + } | ||
| 761 | + | ||
| 762 | + i = BN_num_bits(order); | ||
| 763 | + /* Need to truncate digest if it is too long: first truncate whole | ||
| 764 | + bytes */ | ||
| 765 | + if (8 * dgst_len > i) | ||
| 766 | + dgst_len = (i + 7)/8; | ||
| 767 | + | ||
| 768 | + if (!BN_bin2bn(dgst, dgst_len, m)) { | ||
| 769 | + ECDSAerr(ECDSA_F_ECDSA_DO_SIGN, ERR_R_BN_LIB); | ||
| 770 | + goto err; | ||
| 771 | + } | ||
| 772 | + | ||
| 773 | + /* If still too long truncate remaining bits with a shift */ | ||
| 774 | + if ((8 * dgst_len > i) && !BN_rshift(m, m, 8 - (i & 0x7))) { | ||
| 775 | + ECDSAerr(ECDSA_F_ECDSA_DO_SIGN, ERR_R_BN_LIB); | ||
| 776 | + goto err; | ||
| 777 | + } | ||
| 778 | + | ||
| 779 | + /* copy the truncated bits into plain buffer */ | ||
| 780 | + if (spcf_bn2bin(m, &tmp_dgst, &dgst_len)) { | ||
| 781 | + fprintf(stderr, "%s:%d: OPENSSL_malloc failec\n", __FUNCTION__, __LINE__); | ||
| 782 | + goto err; | ||
| 783 | + } | ||
| 784 | + | ||
| 785 | + ret = ECDSA_SIG_new(); | ||
| 786 | + if (!ret) { | ||
| 787 | + ECDSAerr(ECDSA_F_ECDSA_DO_SIGN, ERR_R_BN_LIB); | ||
| 788 | + goto err; | ||
| 789 | + } | ||
| 790 | + | ||
| 791 | + /* check if this is prime or binary EC request */ | ||
| 792 | + if (EC_METHOD_get_field_type(EC_GROUP_method_of(group)) == NID_X9_62_prime_field) { | ||
| 793 | + ec_crv = EC_PRIME; | ||
| 794 | + /* get the generator point pair */ | ||
| 795 | + if (!EC_POINT_get_affine_coordinates_GFp (group, EC_GROUP_get0_generator(group), | ||
| 796 | + x, y,ctx)) { | ||
| 797 | + ECDSAerr(ECDSA_F_ECDSA_DO_SIGN, ERR_R_EC_LIB); | ||
| 798 | + goto err; | ||
| 799 | + } | ||
| 800 | + | ||
| 801 | + /* get the ECC curve parameters */ | ||
| 802 | + if (!EC_GROUP_get_curve_GFp(group, p, a, b , ctx)) { | ||
| 803 | + ECDSAerr(ECDSA_F_ECDSA_DO_SIGN, ERR_R_EC_LIB); | ||
| 804 | + goto err; | ||
| 805 | + } | ||
| 806 | + } else if (EC_METHOD_get_field_type(EC_GROUP_method_of(group)) == NID_X9_62_characteristic_two_field) { | ||
| 807 | + ec_crv = EC_BINARY; | ||
| 808 | + /* get the ECC curve parameters */ | ||
| 809 | + if (!EC_GROUP_get_curve_GF2m(group, p, a, b , ctx)) { | ||
| 810 | + ECDSAerr(ECDSA_F_ECDSA_DO_SIGN, ERR_R_EC_LIB); | ||
| 811 | + goto err; | ||
| 812 | + } | ||
| 813 | + | ||
| 814 | + /* get the generator point pair */ | ||
| 815 | + if (!EC_POINT_get_affine_coordinates_GF2m(group, | ||
| 816 | + EC_GROUP_get0_generator(group), x, y,ctx)) { | ||
| 817 | + ECDSAerr(ECDSA_F_ECDSA_DO_SIGN, ERR_R_EC_LIB); | ||
| 818 | + goto err; | ||
| 819 | + } | ||
| 820 | + } else { | ||
| 821 | + ECDSAerr(ECDSA_F_ECDSA_DO_SIGN, ERR_R_EC_LIB); | ||
| 822 | + goto err; | ||
| 823 | + } | ||
| 824 | + | ||
| 825 | + if (spcf_bn2bin(order, &r, &r_len)) { | ||
| 826 | + ECDSAerr(ECDSA_F_ECDSA_DO_SIGN, ERR_R_MALLOC_FAILURE); | ||
| 827 | + goto err; | ||
| 828 | + } | ||
| 829 | + | ||
| 830 | + if (spcf_bn2bin(p, &q, &q_len)) { | ||
| 831 | + ECDSAerr(ECDSA_F_ECDSA_DO_SIGN, ERR_R_MALLOC_FAILURE); | ||
| 832 | + goto err; | ||
| 833 | + } | ||
| 834 | + | ||
| 835 | + priv_key_len = r_len; | ||
| 836 | + | ||
| 837 | + /** | ||
| 838 | + * If BN_num_bytes of priv_key returns less then r_len then | ||
| 839 | + * add padding bytes before the key | ||
| 840 | + */ | ||
| 841 | + if (spcf_bn2bin_ex(priv_key, &s, &priv_key_len)) { | ||
| 842 | + ECDSAerr(ECDSA_F_ECDSA_DO_SIGN, ERR_R_MALLOC_FAILURE); | ||
| 843 | + goto err; | ||
| 844 | + } | ||
| 845 | + | ||
| 846 | + /* Generation of ECC curve parameters */ | ||
| 847 | + ab_len = 2*q_len; | ||
| 848 | + ab = eng_copy_curve_points(a, b, ab_len, q_len); | ||
| 849 | + if (!ab) { | ||
| 850 | + ECDSAerr(ECDSA_F_ECDSA_DO_SIGN, ERR_R_MALLOC_FAILURE); | ||
| 851 | + goto err; | ||
| 852 | + } | ||
| 853 | + | ||
| 854 | + if (ec_crv == EC_BINARY) { | ||
| 855 | + if (eng_ec_get_cparam(EC_GROUP_get_curve_name(group), ab+q_len, q_len)) | ||
| 856 | + { | ||
| 857 | + unsigned char *c_temp = NULL; | ||
| 858 | + int c_temp_len = q_len; | ||
| 859 | + if (eng_ec_compute_cparam(b, p, &c_temp, &c_temp_len)) | ||
| 860 | + memcpy(ab+q_len, c_temp, q_len); | ||
| 861 | + else | ||
| 862 | + goto err; | ||
| 863 | + } | ||
| 864 | + kop.curve_type = ECC_BINARY; | ||
| 865 | + } | ||
| 866 | + | ||
| 867 | + /* Calculation of Generator point */ | ||
| 868 | + g_len = 2*q_len; | ||
| 869 | + g_xy = eng_copy_curve_points(x, y, g_len, q_len); | ||
| 870 | + if (!g_xy) { | ||
| 871 | + ECDSAerr(ECDSA_F_ECDSA_DO_SIGN, ERR_R_MALLOC_FAILURE); | ||
| 872 | + goto err; | ||
| 873 | + } | ||
| 874 | + | ||
| 875 | + /* Memory allocation for first part of digital signature */ | ||
| 876 | + c = malloc(r_len); | ||
| 877 | + if (!c) { | ||
| 878 | + ECDSAerr(ECDSA_F_ECDSA_DO_SIGN, ERR_R_MALLOC_FAILURE); | ||
| 879 | + goto err; | ||
| 880 | + } | ||
| 881 | + | ||
| 882 | + d_len = r_len; | ||
| 883 | + | ||
| 884 | + /* Memory allocation for second part of digital signature */ | ||
| 885 | + d = malloc(d_len); | ||
| 886 | + if (!d) { | ||
| 887 | + ECDSAerr(ECDSA_F_ECDSA_DO_SIGN, ERR_R_MALLOC_FAILURE); | ||
| 888 | + goto err; | ||
| 889 | + } | ||
| 890 | + | ||
| 891 | + /* memory for message representative */ | ||
| 892 | + f = malloc(r_len); | ||
| 893 | + if (!f) { | ||
| 894 | + ECDSAerr(ECDSA_F_ECDSA_DO_SIGN, ERR_R_MALLOC_FAILURE); | ||
| 895 | + goto err; | ||
| 896 | + } | ||
| 897 | + | ||
| 898 | + /* Add padding, since SEC expects hash to of size r_len */ | ||
| 899 | + memset(f, 0, r_len - dgst_len); | ||
| 900 | + | ||
| 901 | + /* Skip leading bytes if dgst_len < r_len */ | ||
| 902 | + memcpy(f + r_len - dgst_len, tmp_dgst, dgst_len); | ||
| 903 | + | ||
| 904 | + dgst_len += r_len - dgst_len; | ||
| 905 | + kop.crk_op = CRK_DSA_SIGN; | ||
| 906 | + /* inputs: dgst dsa->p dsa->q dsa->g dsa->priv_key */ | ||
| 907 | + kop.crk_param[0].crp_p = f; | ||
| 908 | + kop.crk_param[0].crp_nbits = dgst_len * 8; | ||
| 909 | + kop.crk_param[1].crp_p = q; | ||
| 910 | + kop.crk_param[1].crp_nbits = q_len * 8; | ||
| 911 | + kop.crk_param[2].crp_p = r; | ||
| 912 | + kop.crk_param[2].crp_nbits = r_len * 8; | ||
| 913 | + kop.crk_param[3].crp_p = g_xy; | ||
| 914 | + kop.crk_param[3].crp_nbits = g_len * 8; | ||
| 915 | + kop.crk_param[4].crp_p = s; | ||
| 916 | + kop.crk_param[4].crp_nbits = priv_key_len * 8; | ||
| 917 | + kop.crk_param[5].crp_p = ab; | ||
| 918 | + kop.crk_param[5].crp_nbits = ab_len * 8; | ||
| 919 | + kop.crk_iparams = 6; | ||
| 920 | + kop.crk_param[6].crp_p = c; | ||
| 921 | + kop.crk_param[6].crp_nbits = d_len * 8; | ||
| 922 | + kop.crk_param[7].crp_p = d; | ||
| 923 | + kop.crk_param[7].crp_nbits = d_len * 8; | ||
| 924 | + kop.crk_oparams = 2; | ||
| 925 | + | ||
| 926 | + if (cryptodev_asym(&kop, 0, NULL, 0, NULL) == 0) { | ||
| 927 | + /* Check if ret->r and s needs to allocated */ | ||
| 928 | + crparam2bn(&kop.crk_param[6], ret->r); | ||
| 929 | + crparam2bn(&kop.crk_param[7], ret->s); | ||
| 930 | + } else { | ||
| 931 | + const ECDSA_METHOD *meth = ECDSA_OpenSSL(); | ||
| 932 | + ret = (meth->ecdsa_do_sign)(dgst, dgst_len, in_kinv, in_r, eckey); | ||
| 933 | + } | ||
| 934 | + kop.crk_param[0].crp_p = NULL; | ||
| 935 | + zapparams(&kop); | ||
| 936 | +err: | ||
| 937 | + if (!ret) { | ||
| 938 | + ECDSA_SIG_free(ret); | ||
| 939 | + ret = NULL; | ||
| 940 | + } | ||
| 941 | + return ret; | ||
| 942 | +} | ||
| 943 | + | ||
| 944 | +static int cryptodev_ecdsa_verify(const unsigned char *dgst, int dgst_len, | ||
| 945 | + ECDSA_SIG *sig, EC_KEY *eckey) | ||
| 946 | +{ | ||
| 947 | + BIGNUM *m = NULL, *p = NULL, *a = NULL, *b = NULL; | ||
| 948 | + BIGNUM *x = NULL, *y = NULL, *w_x = NULL, *w_y = NULL; | ||
| 949 | + BN_CTX *ctx = NULL; | ||
| 950 | + ECDSA_DATA *ecdsa = NULL; | ||
| 951 | + unsigned char *q = NULL, *r = NULL, *ab = NULL, *g_xy = NULL, *w_xy = NULL; | ||
| 952 | + unsigned char *c = NULL, *d = NULL, *f = NULL, *tmp_dgst = NULL; | ||
| 953 | + int i = 0, q_len = 0, pub_key_len = 0, r_len = 0, c_len = 0, g_len = 0; | ||
| 954 | + int d_len = 0, ab_len = 0, ret = -1; | ||
| 955 | + const EC_POINT *pub_key = NULL; | ||
| 956 | + const BIGNUM *order = NULL; | ||
| 957 | + const EC_GROUP *group=NULL; | ||
| 958 | + ec_curve_t ec_crv = EC_PRIME; | ||
| 959 | + struct crypt_kop kop; | ||
| 960 | + | ||
| 961 | + memset(&kop, 0, sizeof kop); | ||
| 962 | + ecdsa = ecdsa_check(eckey); | ||
| 963 | + if (!ecdsa) { | ||
| 964 | + ECDSAerr(ECDSA_F_ECDSA_DO_VERIFY, ERR_R_PASSED_NULL_PARAMETER); | ||
| 965 | + return ret; | ||
| 966 | + } | ||
| 967 | + | ||
| 968 | + group = EC_KEY_get0_group(eckey); | ||
| 969 | + pub_key = EC_KEY_get0_public_key(eckey); | ||
| 970 | + | ||
| 971 | + if (!group || !pub_key) { | ||
| 972 | + ECDSAerr(ECDSA_F_ECDSA_DO_VERIFY, ERR_R_PASSED_NULL_PARAMETER); | ||
| 973 | + return ret; | ||
| 974 | + } | ||
| 975 | + | ||
| 976 | + if ((ctx = BN_CTX_new()) == NULL || (m = BN_new()) == NULL || | ||
| 977 | + (a = BN_new()) == NULL || (b = BN_new()) == NULL || | ||
| 978 | + (p = BN_new()) == NULL || (x = BN_new()) == NULL || | ||
| 979 | + (y = BN_new()) == NULL || (w_x = BN_new()) == NULL || | ||
| 980 | + (w_y = BN_new()) == NULL) { | ||
| 981 | + ECDSAerr(ECDSA_F_ECDSA_DO_VERIFY, ERR_R_MALLOC_FAILURE); | ||
| 982 | + goto err; | ||
| 983 | + } | ||
| 984 | + | ||
| 985 | + order = &group->order; | ||
| 986 | + if (!order || BN_is_zero(order)) { | ||
| 987 | + ECDSAerr(ECDSA_F_ECDSA_DO_VERIFY, ECDSA_R_MISSING_PARAMETERS); | ||
| 988 | + goto err; | ||
| 989 | + } | ||
| 990 | + | ||
| 991 | + i = BN_num_bits(order); | ||
| 992 | + /* Need to truncate digest if it is too long: first truncate whole | ||
| 993 | + * bytes */ | ||
| 994 | + if (8 * dgst_len > i) | ||
| 995 | + dgst_len = (i + 7)/8; | ||
| 996 | + | ||
| 997 | + if (!BN_bin2bn(dgst, dgst_len, m)) { | ||
| 998 | + ECDSAerr(ECDSA_F_ECDSA_DO_VERIFY, ERR_R_BN_LIB); | ||
| 999 | + goto err; | ||
| 1000 | + } | ||
| 1001 | + | ||
| 1002 | + /* If still too long truncate remaining bits with a shift */ | ||
| 1003 | + if ((8 * dgst_len > i) && !BN_rshift(m, m, 8 - (i & 0x7))) { | ||
| 1004 | + ECDSAerr(ECDSA_F_ECDSA_DO_VERIFY, ERR_R_BN_LIB); | ||
| 1005 | + goto err; | ||
| 1006 | + } | ||
| 1007 | + /* copy the truncated bits into plain buffer */ | ||
| 1008 | + if (spcf_bn2bin(m, &tmp_dgst, &dgst_len)) { | ||
| 1009 | + ECDSAerr(ECDSA_F_ECDSA_DO_VERIFY, ERR_R_MALLOC_FAILURE); | ||
| 1010 | + goto err; | ||
| 1011 | + } | ||
| 1012 | + | ||
| 1013 | + /* check if this is prime or binary EC request */ | ||
| 1014 | + if (EC_METHOD_get_field_type(EC_GROUP_method_of(group)) == NID_X9_62_prime_field) { | ||
| 1015 | + ec_crv = EC_PRIME; | ||
| 1016 | + | ||
| 1017 | + /* get the generator point pair */ | ||
| 1018 | + if (!EC_POINT_get_affine_coordinates_GFp (group, | ||
| 1019 | + EC_GROUP_get0_generator(group), x, y,ctx)) { | ||
| 1020 | + ECDSAerr(ECDSA_F_ECDSA_DO_VERIFY, ERR_R_EC_LIB); | ||
| 1021 | + goto err; | ||
| 1022 | + } | ||
| 1023 | + | ||
| 1024 | + /* get the public key pair for prime curve */ | ||
| 1025 | + if (!EC_POINT_get_affine_coordinates_GFp (group, | ||
| 1026 | + pub_key, w_x, w_y,ctx)) { | ||
| 1027 | + ECDSAerr(ECDSA_F_ECDSA_DO_VERIFY, ERR_R_EC_LIB); | ||
| 1028 | + goto err; | ||
| 1029 | + } | ||
| 1030 | + | ||
| 1031 | + /* get the ECC curve parameters */ | ||
| 1032 | + if (!EC_GROUP_get_curve_GFp(group, p, a, b, ctx)) { | ||
| 1033 | + ECDSAerr(ECDSA_F_ECDSA_DO_VERIFY, ERR_R_EC_LIB); | ||
| 1034 | + goto err; | ||
| 1035 | + } | ||
| 1036 | + } else if (EC_METHOD_get_field_type(EC_GROUP_method_of(group)) == NID_X9_62_characteristic_two_field){ | ||
| 1037 | + ec_crv = EC_BINARY; | ||
| 1038 | + /* get the ECC curve parameters */ | ||
| 1039 | + if (!EC_GROUP_get_curve_GF2m(group, p, a, b , ctx)) { | ||
| 1040 | + ECDSAerr(ECDSA_F_ECDSA_DO_VERIFY, ERR_R_EC_LIB); | ||
| 1041 | + goto err; | ||
| 1042 | + } | ||
| 1043 | + | ||
| 1044 | + /* get the generator point pair */ | ||
| 1045 | + if (!EC_POINT_get_affine_coordinates_GF2m(group, | ||
| 1046 | + EC_GROUP_get0_generator(group),x, y,ctx)) { | ||
| 1047 | + ECDSAerr(ECDSA_F_ECDSA_DO_VERIFY, ERR_R_EC_LIB); | ||
| 1048 | + goto err; | ||
| 1049 | + } | ||
| 1050 | + | ||
| 1051 | + /* get the public key pair for binary curve */ | ||
| 1052 | + if (!EC_POINT_get_affine_coordinates_GF2m(group, | ||
| 1053 | + pub_key, w_x, w_y,ctx)) { | ||
| 1054 | + ECDSAerr(ECDSA_F_ECDSA_DO_VERIFY, ERR_R_EC_LIB); | ||
| 1055 | + goto err; | ||
| 1056 | + } | ||
| 1057 | + }else { | ||
| 1058 | + ECDSAerr(ECDSA_F_ECDSA_DO_VERIFY, ERR_R_EC_LIB); | ||
| 1059 | + goto err; | ||
| 1060 | + } | ||
| 1061 | + | ||
| 1062 | + /* Get the order of the subgroup of private keys */ | ||
| 1063 | + if (spcf_bn2bin((BIGNUM*)order, &r, &r_len)) { | ||
| 1064 | + ECDSAerr(ECDSA_F_ECDSA_DO_VERIFY, ERR_R_MALLOC_FAILURE); | ||
| 1065 | + goto err; | ||
| 1066 | + } | ||
| 1067 | + | ||
| 1068 | + /* Get the irreducible polynomial that creates the field */ | ||
| 1069 | + if (spcf_bn2bin(p, &q, &q_len)) { | ||
| 1070 | + ECDSAerr(ECDSA_F_ECDSA_DO_VERIFY, ERR_R_MALLOC_FAILURE); | ||
| 1071 | + goto err; | ||
| 1072 | + } | ||
| 1073 | + | ||
| 1074 | + /* Get the public key into a flat buffer with appropriate padding */ | ||
| 1075 | + pub_key_len = 2 * q_len; | ||
| 1076 | + | ||
| 1077 | + w_xy = eng_copy_curve_points (w_x, w_y, pub_key_len, q_len); | ||
| 1078 | + if (!w_xy) { | ||
| 1079 | + ECDSAerr(ECDSA_F_ECDSA_DO_VERIFY, ERR_R_MALLOC_FAILURE); | ||
| 1080 | + goto err; | ||
| 1081 | + } | ||
| 1082 | + | ||
| 1083 | + /* Generation of ECC curve parameters */ | ||
| 1084 | + ab_len = 2*q_len; | ||
| 1085 | + | ||
| 1086 | + ab = eng_copy_curve_points (a, b, ab_len, q_len); | ||
| 1087 | + if (!ab) { | ||
| 1088 | + ECDSAerr(ECDSA_F_ECDSA_DO_VERIFY, ERR_R_MALLOC_FAILURE); | ||
| 1089 | + goto err; | ||
| 1090 | + } | ||
| 1091 | + | ||
| 1092 | + if (ec_crv == EC_BINARY) { | ||
| 1093 | + /* copy b' i.e c(b), instead of only b */ | ||
| 1094 | + if (eng_ec_get_cparam(EC_GROUP_get_curve_name(group), ab+q_len, q_len)) | ||
| 1095 | + { | ||
| 1096 | + unsigned char *c_temp = NULL; | ||
| 1097 | + int c_temp_len = q_len; | ||
| 1098 | + if (eng_ec_compute_cparam(b, p, &c_temp, &c_temp_len)) | ||
| 1099 | + memcpy(ab+q_len, c_temp, q_len); | ||
| 1100 | + else | ||
| 1101 | + goto err; | ||
| 1102 | + } | ||
| 1103 | + kop.curve_type = ECC_BINARY; | ||
| 1104 | + } | ||
| 1105 | + | ||
| 1106 | + /* Calculation of Generator point */ | ||
| 1107 | + g_len = 2 * q_len; | ||
| 1108 | + | ||
| 1109 | + g_xy = eng_copy_curve_points (x, y, g_len, q_len); | ||
| 1110 | + if (!g_xy) { | ||
| 1111 | + ECDSAerr(ECDSA_F_ECDSA_DO_VERIFY, ERR_R_MALLOC_FAILURE); | ||
| 1112 | + goto err; | ||
| 1113 | + } | ||
| 1114 | + | ||
| 1115 | + /** | ||
| 1116 | + * Get the 1st part of signature into a flat buffer with | ||
| 1117 | + * appropriate padding | ||
| 1118 | + */ | ||
| 1119 | + if (BN_num_bytes(sig->r) < r_len) | ||
| 1120 | + c_len = r_len; | ||
| 1121 | + | ||
| 1122 | + if (spcf_bn2bin_ex(sig->r, &c, &c_len)) { | ||
| 1123 | + ECDSAerr(ECDSA_F_ECDSA_DO_VERIFY, ERR_R_MALLOC_FAILURE); | ||
| 1124 | + goto err; | ||
| 1125 | + } | ||
| 1126 | + | ||
| 1127 | + /** | ||
| 1128 | + * Get the 2nd part of signature into a flat buffer with | ||
| 1129 | + * appropriate padding | ||
| 1130 | + */ | ||
| 1131 | + if (BN_num_bytes(sig->s) < r_len) | ||
| 1132 | + d_len = r_len; | ||
| 1133 | + | ||
| 1134 | + if (spcf_bn2bin_ex(sig->s, &d, &d_len)) { | ||
| 1135 | + ECDSAerr(ECDSA_F_ECDSA_DO_VERIFY, ERR_R_MALLOC_FAILURE); | ||
| 1136 | + goto err; | ||
| 1137 | + } | ||
| 1138 | + | ||
| 1139 | + /* memory for message representative */ | ||
| 1140 | + f = malloc(r_len); | ||
| 1141 | + if (!f) { | ||
| 1142 | + ECDSAerr(ECDSA_F_ECDSA_DO_VERIFY, ERR_R_MALLOC_FAILURE); | ||
| 1143 | + goto err; | ||
| 1144 | + } | ||
| 1145 | + | ||
| 1146 | + /* Add padding, since SEC expects hash to of size r_len */ | ||
| 1147 | + memset(f, 0, r_len-dgst_len); | ||
| 1148 | + | ||
| 1149 | + /* Skip leading bytes if dgst_len < r_len */ | ||
| 1150 | + memcpy(f + r_len-dgst_len, tmp_dgst, dgst_len); | ||
| 1151 | + dgst_len += r_len-dgst_len; | ||
| 1152 | + kop.crk_op = CRK_DSA_VERIFY; | ||
| 1153 | + /* inputs: dgst dsa->p dsa->q dsa->g dsa->priv_key */ | ||
| 1154 | + kop.crk_param[0].crp_p = f; | ||
| 1155 | + kop.crk_param[0].crp_nbits = dgst_len * 8; | ||
| 1156 | + kop.crk_param[1].crp_p = q; | ||
| 1157 | + kop.crk_param[1].crp_nbits = q_len * 8; | ||
| 1158 | + kop.crk_param[2].crp_p = r; | ||
| 1159 | + kop.crk_param[2].crp_nbits = r_len * 8; | ||
| 1160 | + kop.crk_param[3].crp_p = g_xy; | ||
| 1161 | + kop.crk_param[3].crp_nbits = g_len * 8; | ||
| 1162 | + kop.crk_param[4].crp_p = w_xy; | ||
| 1163 | + kop.crk_param[4].crp_nbits = pub_key_len * 8; | ||
| 1164 | + kop.crk_param[5].crp_p = ab; | ||
| 1165 | + kop.crk_param[5].crp_nbits = ab_len * 8; | ||
| 1166 | + kop.crk_param[6].crp_p = c; | ||
| 1167 | + kop.crk_param[6].crp_nbits = d_len * 8; | ||
| 1168 | + kop.crk_param[7].crp_p = d; | ||
| 1169 | + kop.crk_param[7].crp_nbits = d_len * 8; | ||
| 1170 | + kop.crk_iparams = 8; | ||
| 1171 | + | ||
| 1172 | + if (cryptodev_asym(&kop, 0, NULL, 0, NULL) == 0) { | ||
| 1173 | + /*OCF success value is 0, if not zero, change ret to fail*/ | ||
| 1174 | + if(0 == kop.crk_status) | ||
| 1175 | + ret = 1; | ||
| 1176 | + } else { | ||
| 1177 | + const ECDSA_METHOD *meth = ECDSA_OpenSSL(); | ||
| 1178 | + | ||
| 1179 | + ret = (meth->ecdsa_do_verify)(dgst, dgst_len, sig, eckey); | ||
| 1180 | + } | ||
| 1181 | + kop.crk_param[0].crp_p = NULL; | ||
| 1182 | + zapparams(&kop); | ||
| 1183 | + | ||
| 1184 | +err: | ||
| 1185 | + return ret; | ||
| 1186 | +} | ||
| 1187 | + | ||
| 1188 | +static int cryptodev_dh_keygen(DH *dh) | ||
| 1189 | +{ | ||
| 1190 | + struct crypt_kop kop; | ||
| 1191 | + int ret = 1, g_len; | ||
| 1192 | + unsigned char *g = NULL; | ||
| 1193 | + | ||
| 1194 | + if (dh->priv_key == NULL) { | ||
| 1195 | + if ((dh->priv_key=BN_new()) == NULL) | ||
| 1196 | + goto sw_try; | ||
| 1197 | + } | ||
| 1198 | + | ||
| 1199 | + if (dh->pub_key == NULL) { | ||
| 1200 | + if ((dh->pub_key=BN_new()) == NULL) | ||
| 1201 | + goto sw_try; | ||
| 1202 | + } | ||
| 1203 | + | ||
| 1204 | + g_len = BN_num_bytes(dh->p); | ||
| 1205 | + /** | ||
| 1206 | + * Get generator into a plain buffer. If length is less than | ||
| 1207 | + * q_len then add leading padding bytes. | ||
| 1208 | + */ | ||
| 1209 | + if (spcf_bn2bin_ex(dh->g, &g, &g_len)) { | ||
| 1210 | + DSAerr(DH_F_DH_GENERATE_KEY, ERR_R_MALLOC_FAILURE); | ||
| 1211 | + goto sw_try; | ||
| 1212 | + } | ||
| 1213 | + | ||
| 1214 | + memset(&kop, 0, sizeof kop); | ||
| 1215 | + kop.crk_op = CRK_DH_GENERATE_KEY; | ||
| 1216 | + if (bn2crparam(dh->p, &kop.crk_param[0])) | ||
| 1217 | + goto sw_try; | ||
| 1218 | + if (bn2crparam(dh->q, &kop.crk_param[1])) | ||
| 1219 | + goto sw_try; | ||
| 1220 | + kop.crk_param[2].crp_p = g; | ||
| 1221 | + kop.crk_param[2].crp_nbits = g_len * 8; | ||
| 1222 | + kop.crk_iparams = 3; | ||
| 1223 | + | ||
| 1224 | + /* pub_key is or prime length while priv key is of length of order */ | ||
| 1225 | + if (cryptodev_asym(&kop, BN_num_bytes(dh->p), dh->pub_key, | ||
| 1226 | + BN_num_bytes(dh->q), dh->priv_key)) | ||
| 1227 | + goto sw_try; | ||
| 1228 | + | ||
| 1229 | + return ret; | ||
| 1230 | +sw_try: | ||
| 1231 | + { | ||
| 1232 | + const DH_METHOD *meth = DH_OpenSSL(); | ||
| 1233 | + ret = (meth->generate_key)(dh); | ||
| 1234 | + } | ||
| 1235 | + return ret; | ||
| 1236 | } | ||
| 1237 | |||
| 1238 | static int | ||
| 1239 | @@ -1503,43 +2310,234 @@ cryptodev_dh_compute_key(unsigned char *key, const BIGNUM *pub_key, DH *dh) | ||
| 1240 | { | ||
| 1241 | struct crypt_kop kop; | ||
| 1242 | int dhret = 1; | ||
| 1243 | - int fd, keylen; | ||
| 1244 | + int fd, p_len; | ||
| 1245 | + BIGNUM *temp = NULL; | ||
| 1246 | + unsigned char *padded_pub_key = NULL, *p = NULL; | ||
| 1247 | + | ||
| 1248 | + if ((fd = get_asym_dev_crypto()) < 0) | ||
| 1249 | + goto sw_try; | ||
| 1250 | + | ||
| 1251 | + memset(&kop, 0, sizeof kop); | ||
| 1252 | + kop.crk_op = CRK_DH_COMPUTE_KEY; | ||
| 1253 | + /* inputs: dh->priv_key pub_key dh->p key */ | ||
| 1254 | + spcf_bn2bin(dh->p, &p, &p_len); | ||
| 1255 | + spcf_bn2bin_ex(pub_key, &padded_pub_key, &p_len); | ||
| 1256 | + if (bn2crparam(dh->priv_key, &kop.crk_param[0])) | ||
| 1257 | + goto sw_try; | ||
| 1258 | + | ||
| 1259 | + kop.crk_param[1].crp_p = padded_pub_key; | ||
| 1260 | + kop.crk_param[1].crp_nbits = p_len * 8; | ||
| 1261 | + kop.crk_param[2].crp_p = p; | ||
| 1262 | + kop.crk_param[2].crp_nbits = p_len * 8; | ||
| 1263 | + kop.crk_iparams = 3; | ||
| 1264 | + kop.crk_param[3].crp_p = (void*) key; | ||
| 1265 | + kop.crk_param[3].crp_nbits = p_len * 8; | ||
| 1266 | + kop.crk_oparams = 1; | ||
| 1267 | + dhret = p_len; | ||
| 1268 | + | ||
| 1269 | + if (ioctl(fd, CIOCKEY, &kop)) | ||
| 1270 | + goto sw_try; | ||
| 1271 | |||
| 1272 | - if ((fd = get_asym_dev_crypto()) < 0) { | ||
| 1273 | + if ((temp = BN_new())) { | ||
| 1274 | + if (!BN_bin2bn(key, p_len, temp)) { | ||
| 1275 | + ECDSAerr(ECDSA_F_ECDSA_DO_SIGN, ERR_R_BN_LIB); | ||
| 1276 | + goto sw_try; | ||
| 1277 | + } | ||
| 1278 | + if (dhret > BN_num_bytes(temp)) | ||
| 1279 | + dhret=BN_bn2bin(temp,key); | ||
| 1280 | + BN_free(temp); | ||
| 1281 | + } | ||
| 1282 | + | ||
| 1283 | + kop.crk_param[3].crp_p = NULL; | ||
| 1284 | + zapparams(&kop); | ||
| 1285 | + return (dhret); | ||
| 1286 | +sw_try: | ||
| 1287 | + { | ||
| 1288 | const DH_METHOD *meth = DH_OpenSSL(); | ||
| 1289 | |||
| 1290 | - return ((meth->compute_key)(key, pub_key, dh)); | ||
| 1291 | + dhret = (meth->compute_key)(key, pub_key, dh); | ||
| 1292 | } | ||
| 1293 | + return (dhret); | ||
| 1294 | +} | ||
| 1295 | |||
| 1296 | - keylen = BN_num_bits(dh->p); | ||
| 1297 | +int cryptodev_ecdh_compute_key(void *out, size_t outlen, | ||
| 1298 | + const EC_POINT *pub_key, EC_KEY *ecdh, void *(*KDF)(const void *in, size_t inlen, | ||
| 1299 | + void *out, size_t *outlen)) | ||
| 1300 | +{ | ||
| 1301 | + ec_curve_t ec_crv = EC_PRIME; | ||
| 1302 | + unsigned char * q = NULL, *w_xy = NULL, *ab = NULL, *s = NULL, *r = NULL; | ||
| 1303 | + BIGNUM * w_x = NULL, *w_y = NULL; | ||
| 1304 | + int q_len = 0, ab_len = 0, pub_key_len = 0, r_len = 0, priv_key_len = 0; | ||
| 1305 | + BIGNUM * p = NULL, *a = NULL, *b = NULL; | ||
| 1306 | + BN_CTX *ctx; | ||
| 1307 | + EC_POINT *tmp=NULL; | ||
| 1308 | + BIGNUM *x=NULL, *y=NULL; | ||
| 1309 | + const BIGNUM *priv_key; | ||
| 1310 | + const EC_GROUP* group = NULL; | ||
| 1311 | + int ret = -1; | ||
| 1312 | + size_t buflen, len; | ||
| 1313 | + struct crypt_kop kop; | ||
| 1314 | |||
| 1315 | memset(&kop, 0, sizeof kop); | ||
| 1316 | - kop.crk_op = CRK_DH_COMPUTE_KEY; | ||
| 1317 | |||
| 1318 | - /* inputs: dh->priv_key pub_key dh->p key */ | ||
| 1319 | - if (bn2crparam(dh->priv_key, &kop.crk_param[0])) | ||
| 1320 | + if ((ctx = BN_CTX_new()) == NULL) goto err; | ||
| 1321 | + BN_CTX_start(ctx); | ||
| 1322 | + x = BN_CTX_get(ctx); | ||
| 1323 | + y = BN_CTX_get(ctx); | ||
| 1324 | + p = BN_CTX_get(ctx); | ||
| 1325 | + a = BN_CTX_get(ctx); | ||
| 1326 | + b = BN_CTX_get(ctx); | ||
| 1327 | + w_x = BN_CTX_get(ctx); | ||
| 1328 | + w_y = BN_CTX_get(ctx); | ||
| 1329 | + | ||
| 1330 | + if (!x || !y || !p || !a || !b || !w_x || !w_y) { | ||
| 1331 | + ECDHerr(ECDH_F_ECDH_COMPUTE_KEY,ERR_R_MALLOC_FAILURE); | ||
| 1332 | goto err; | ||
| 1333 | - if (bn2crparam(pub_key, &kop.crk_param[1])) | ||
| 1334 | + } | ||
| 1335 | + | ||
| 1336 | + priv_key = EC_KEY_get0_private_key(ecdh); | ||
| 1337 | + if (priv_key == NULL) { | ||
| 1338 | + ECDHerr(ECDH_F_ECDH_COMPUTE_KEY,ECDH_R_NO_PRIVATE_VALUE); | ||
| 1339 | goto err; | ||
| 1340 | - if (bn2crparam(dh->p, &kop.crk_param[2])) | ||
| 1341 | + } | ||
| 1342 | + | ||
| 1343 | + group = EC_KEY_get0_group(ecdh); | ||
| 1344 | + if ((tmp=EC_POINT_new(group)) == NULL) { | ||
| 1345 | + ECDHerr(ECDH_F_ECDH_COMPUTE_KEY,ERR_R_MALLOC_FAILURE); | ||
| 1346 | goto err; | ||
| 1347 | - kop.crk_iparams = 3; | ||
| 1348 | + } | ||
| 1349 | |||
| 1350 | - kop.crk_param[3].crp_p = (caddr_t) key; | ||
| 1351 | - kop.crk_param[3].crp_nbits = keylen * 8; | ||
| 1352 | - kop.crk_oparams = 1; | ||
| 1353 | + if (EC_METHOD_get_field_type(EC_GROUP_method_of(group)) == | ||
| 1354 | + NID_X9_62_prime_field) { | ||
| 1355 | + ec_crv = EC_PRIME; | ||
| 1356 | |||
| 1357 | - if (ioctl(fd, CIOCKEY, &kop) == -1) { | ||
| 1358 | - const DH_METHOD *meth = DH_OpenSSL(); | ||
| 1359 | + if (!EC_POINT_get_affine_coordinates_GFp(group, | ||
| 1360 | + EC_GROUP_get0_generator(group), x, y, ctx)) { | ||
| 1361 | + ECDHerr(ECDH_F_ECDH_COMPUTE_KEY,ECDH_R_POINT_ARITHMETIC_FAILURE); | ||
| 1362 | + goto err; | ||
| 1363 | + } | ||
| 1364 | |||
| 1365 | - dhret = (meth->compute_key)(key, pub_key, dh); | ||
| 1366 | + /* get the ECC curve parameters */ | ||
| 1367 | + if (!EC_GROUP_get_curve_GFp(group, p, a, b, ctx)) { | ||
| 1368 | + ECDHerr(ECDH_F_ECDH_COMPUTE_KEY,ERR_R_BN_LIB); | ||
| 1369 | + goto err; | ||
| 1370 | + } | ||
| 1371 | + | ||
| 1372 | + /* get the public key pair for prime curve */ | ||
| 1373 | + if (!EC_POINT_get_affine_coordinates_GFp (group, pub_key, w_x, w_y,ctx)) { | ||
| 1374 | + ECDHerr(ECDH_F_ECDH_COMPUTE_KEY,ERR_R_BN_LIB); | ||
| 1375 | + goto err; | ||
| 1376 | + } | ||
| 1377 | + } else { | ||
| 1378 | + ec_crv = EC_BINARY; | ||
| 1379 | + | ||
| 1380 | + if (!EC_POINT_get_affine_coordinates_GF2m(group, | ||
| 1381 | + EC_GROUP_get0_generator(group), x, y, ctx)) { | ||
| 1382 | + ECDHerr(ECDH_F_ECDH_COMPUTE_KEY,ECDH_R_POINT_ARITHMETIC_FAILURE); | ||
| 1383 | + goto err; | ||
| 1384 | + } | ||
| 1385 | + | ||
| 1386 | + /* get the ECC curve parameters */ | ||
| 1387 | + if (!EC_GROUP_get_curve_GF2m(group, p, a, b , ctx)) { | ||
| 1388 | + ECDHerr(ECDH_F_ECDH_COMPUTE_KEY,ERR_R_BN_LIB); | ||
| 1389 | + goto err; | ||
| 1390 | + } | ||
| 1391 | + | ||
| 1392 | + /* get the public key pair for binary curve */ | ||
| 1393 | + if (!EC_POINT_get_affine_coordinates_GF2m(group, | ||
| 1394 | + pub_key, w_x, w_y,ctx)) { | ||
| 1395 | + ECDSAerr(ECDSA_F_ECDSA_DO_SIGN, ERR_R_EC_LIB); | ||
| 1396 | + goto err; | ||
| 1397 | + } | ||
| 1398 | + } | ||
| 1399 | + | ||
| 1400 | + /* irreducible polynomial that creates the field */ | ||
| 1401 | + if (spcf_bn2bin((BIGNUM*)&group->order, &r, &r_len)) { | ||
| 1402 | + ECDSAerr(ECDSA_F_ECDSA_DO_SIGN, ERR_R_MALLOC_FAILURE); | ||
| 1403 | + goto err; | ||
| 1404 | + } | ||
| 1405 | + | ||
| 1406 | + /* Get the irreducible polynomial that creates the field */ | ||
| 1407 | + if (spcf_bn2bin(p, &q, &q_len)) { | ||
| 1408 | + ECDHerr(ECDH_F_ECDH_COMPUTE_KEY,ERR_R_BN_LIB); | ||
| 1409 | + goto err; | ||
| 1410 | } | ||
| 1411 | + | ||
| 1412 | + /* Get the public key into a flat buffer with appropriate padding */ | ||
| 1413 | + pub_key_len = 2 * q_len; | ||
| 1414 | + w_xy = eng_copy_curve_points (w_x, w_y, pub_key_len, q_len); | ||
| 1415 | + if (!w_xy) { | ||
| 1416 | + ECDSAerr(ECDSA_F_ECDSA_DO_SIGN, ERR_R_MALLOC_FAILURE); | ||
| 1417 | + goto err; | ||
| 1418 | + } | ||
| 1419 | + | ||
| 1420 | + /* Generation of ECC curve parameters */ | ||
| 1421 | + ab_len = 2*q_len; | ||
| 1422 | + ab = eng_copy_curve_points (a, b, ab_len, q_len); | ||
| 1423 | + if (!ab) { | ||
| 1424 | + ECDHerr(ECDH_F_ECDH_COMPUTE_KEY,ERR_R_BN_LIB); | ||
| 1425 | + goto err; | ||
| 1426 | + } | ||
| 1427 | + | ||
| 1428 | + if (ec_crv == EC_BINARY) { | ||
| 1429 | + /* copy b' i.e c(b), instead of only b */ | ||
| 1430 | + if (eng_ec_get_cparam(EC_GROUP_get_curve_name(group), ab+q_len, q_len)) | ||
| 1431 | + { | ||
| 1432 | + unsigned char *c_temp = NULL; | ||
| 1433 | + int c_temp_len = q_len; | ||
| 1434 | + if (eng_ec_compute_cparam(b, p, &c_temp, &c_temp_len)) | ||
| 1435 | + memcpy(ab+q_len, c_temp, q_len); | ||
| 1436 | + else | ||
| 1437 | + goto err; | ||
| 1438 | + } | ||
| 1439 | + kop.curve_type = ECC_BINARY; | ||
| 1440 | + } else | ||
| 1441 | + kop.curve_type = ECC_PRIME; | ||
| 1442 | + | ||
| 1443 | + priv_key_len = r_len; | ||
| 1444 | + | ||
| 1445 | + /* | ||
| 1446 | + * If BN_num_bytes of priv_key returns less then r_len then | ||
| 1447 | + * add padding bytes before the key | ||
| 1448 | + */ | ||
| 1449 | + if (spcf_bn2bin_ex((BIGNUM *)priv_key, &s, &priv_key_len)) { | ||
| 1450 | + ECDSAerr(ECDSA_F_ECDSA_DO_SIGN, ERR_R_MALLOC_FAILURE); | ||
| 1451 | + goto err; | ||
| 1452 | + } | ||
| 1453 | + | ||
| 1454 | + buflen = (EC_GROUP_get_degree(group) + 7)/8; | ||
| 1455 | + len = BN_num_bytes(x); | ||
| 1456 | + if (len > buflen || q_len < buflen) { | ||
| 1457 | + ECDHerr(ECDH_F_ECDH_COMPUTE_KEY,ERR_R_INTERNAL_ERROR); | ||
| 1458 | + goto err; | ||
| 1459 | + } | ||
| 1460 | + | ||
| 1461 | + kop.crk_op = CRK_DH_COMPUTE_KEY; | ||
| 1462 | + kop.crk_param[0].crp_p = (void*) s; | ||
| 1463 | + kop.crk_param[0].crp_nbits = priv_key_len*8; | ||
| 1464 | + kop.crk_param[1].crp_p = (void*) w_xy; | ||
| 1465 | + kop.crk_param[1].crp_nbits = pub_key_len*8; | ||
| 1466 | + kop.crk_param[2].crp_p = (void*) q; | ||
| 1467 | + kop.crk_param[2].crp_nbits = q_len*8; | ||
| 1468 | + kop.crk_param[3].crp_p = (void*) ab; | ||
| 1469 | + kop.crk_param[3].crp_nbits = ab_len*8; | ||
| 1470 | + kop.crk_iparams = 4; | ||
| 1471 | + kop.crk_param[4].crp_p = (void*) out; | ||
| 1472 | + kop.crk_param[4].crp_nbits = q_len*8; | ||
| 1473 | + kop.crk_oparams = 1; | ||
| 1474 | + ret = q_len; | ||
| 1475 | + if (cryptodev_asym(&kop, 0, NULL, 0, NULL)) { | ||
| 1476 | + const ECDH_METHOD *meth = ECDH_OpenSSL(); | ||
| 1477 | + ret = (meth->compute_key)(out, outlen, pub_key, ecdh, KDF); | ||
| 1478 | + } else | ||
| 1479 | + ret = q_len; | ||
| 1480 | err: | ||
| 1481 | - kop.crk_param[3].crp_p = NULL; | ||
| 1482 | + kop.crk_param[4].crp_p = NULL; | ||
| 1483 | zapparams(&kop); | ||
| 1484 | - return (dhret); | ||
| 1485 | + return ret; | ||
| 1486 | } | ||
| 1487 | |||
| 1488 | + | ||
| 1489 | static DH_METHOD cryptodev_dh = { | ||
| 1490 | "cryptodev DH method", | ||
| 1491 | NULL, /* cryptodev_dh_generate_key */ | ||
| 1492 | @@ -1551,6 +2549,14 @@ static DH_METHOD cryptodev_dh = { | ||
| 1493 | NULL /* app_data */ | ||
| 1494 | }; | ||
| 1495 | |||
| 1496 | +static ECDH_METHOD cryptodev_ecdh = { | ||
| 1497 | + "cryptodev ECDH method", | ||
| 1498 | + NULL, /* cryptodev_ecdh_compute_key */ | ||
| 1499 | + NULL, | ||
| 1500 | + 0, /* flags */ | ||
| 1501 | + NULL /* app_data */ | ||
| 1502 | +}; | ||
| 1503 | + | ||
| 1504 | /* | ||
| 1505 | * ctrl right now is just a wrapper that doesn't do much | ||
| 1506 | * but I expect we'll want some options soon. | ||
| 1507 | @@ -1634,25 +2640,42 @@ ENGINE_load_cryptodev(void) | ||
| 1508 | memcpy(&cryptodev_dsa, meth, sizeof(DSA_METHOD)); | ||
| 1509 | if (cryptodev_asymfeat & CRF_DSA_SIGN) | ||
| 1510 | cryptodev_dsa.dsa_do_sign = cryptodev_dsa_do_sign; | ||
| 1511 | - if (cryptodev_asymfeat & CRF_MOD_EXP) { | ||
| 1512 | - cryptodev_dsa.bn_mod_exp = cryptodev_dsa_bn_mod_exp; | ||
| 1513 | - cryptodev_dsa.dsa_mod_exp = cryptodev_dsa_dsa_mod_exp; | ||
| 1514 | - } | ||
| 1515 | if (cryptodev_asymfeat & CRF_DSA_VERIFY) | ||
| 1516 | cryptodev_dsa.dsa_do_verify = cryptodev_dsa_verify; | ||
| 1517 | + if (cryptodev_asymfeat & CRF_DSA_GENERATE_KEY) | ||
| 1518 | + cryptodev_dsa.dsa_keygen = cryptodev_dsa_keygen; | ||
| 1519 | } | ||
| 1520 | |||
| 1521 | if (ENGINE_set_DH(engine, &cryptodev_dh)){ | ||
| 1522 | const DH_METHOD *dh_meth = DH_OpenSSL(); | ||
| 1523 | + memcpy(&cryptodev_dh, dh_meth, sizeof(DH_METHOD)); | ||
| 1524 | + if (cryptodev_asymfeat & CRF_DH_COMPUTE_KEY) { | ||
| 1525 | + cryptodev_dh.compute_key = | ||
| 1526 | + cryptodev_dh_compute_key; | ||
| 1527 | + } | ||
| 1528 | + if (cryptodev_asymfeat & CRF_DH_GENERATE_KEY) { | ||
| 1529 | + cryptodev_dh.generate_key = | ||
| 1530 | + cryptodev_dh_keygen; | ||
| 1531 | + } | ||
| 1532 | + } | ||
| 1533 | |||
| 1534 | - cryptodev_dh.generate_key = dh_meth->generate_key; | ||
| 1535 | - cryptodev_dh.compute_key = dh_meth->compute_key; | ||
| 1536 | - cryptodev_dh.bn_mod_exp = dh_meth->bn_mod_exp; | ||
| 1537 | - if (cryptodev_asymfeat & CRF_MOD_EXP) { | ||
| 1538 | - cryptodev_dh.bn_mod_exp = cryptodev_mod_exp_dh; | ||
| 1539 | - if (cryptodev_asymfeat & CRF_DH_COMPUTE_KEY) | ||
| 1540 | - cryptodev_dh.compute_key = | ||
| 1541 | - cryptodev_dh_compute_key; | ||
| 1542 | + if (ENGINE_set_ECDSA(engine, &cryptodev_ecdsa)) { | ||
| 1543 | + const ECDSA_METHOD *meth = ECDSA_OpenSSL(); | ||
| 1544 | + memcpy(&cryptodev_ecdsa, meth, sizeof(ECDSA_METHOD)); | ||
| 1545 | + if (cryptodev_asymfeat & CRF_DSA_SIGN) { | ||
| 1546 | + cryptodev_ecdsa.ecdsa_do_sign = cryptodev_ecdsa_do_sign; | ||
| 1547 | + } | ||
| 1548 | + if (cryptodev_asymfeat & CRF_DSA_VERIFY) { | ||
| 1549 | + cryptodev_ecdsa.ecdsa_do_verify = | ||
| 1550 | + cryptodev_ecdsa_verify; | ||
| 1551 | + } | ||
| 1552 | + } | ||
| 1553 | + | ||
| 1554 | + if (ENGINE_set_ECDH(engine, &cryptodev_ecdh)) { | ||
| 1555 | + const ECDH_METHOD *ecdh_meth = ECDH_OpenSSL(); | ||
| 1556 | + memcpy(&cryptodev_ecdh, ecdh_meth, sizeof(ECDH_METHOD)); | ||
| 1557 | + if (cryptodev_asymfeat & CRF_DH_COMPUTE_KEY) { | ||
| 1558 | + cryptodev_ecdh.compute_key = cryptodev_ecdh_compute_key; | ||
| 1559 | } | ||
| 1560 | } | ||
| 1561 | |||
| 1562 | -- | ||
| 1563 | 2.3.5 | ||
| 1564 | |||
diff --git a/recipes-connectivity/openssl/openssl-qoriq/qoriq/0009-Added-hwrng-dev-file-as-source-of-RNG.patch b/recipes-connectivity/openssl/openssl-qoriq/qoriq/0009-Added-hwrng-dev-file-as-source-of-RNG.patch deleted file mode 100644 index 0fb018217..000000000 --- a/recipes-connectivity/openssl/openssl-qoriq/qoriq/0009-Added-hwrng-dev-file-as-source-of-RNG.patch +++ /dev/null | |||
| @@ -1,28 +0,0 @@ | |||
| 1 | From 81c4c62a4f5f5542843381bfb34e39a6171d5cdd Mon Sep 17 00:00:00 2001 | ||
| 2 | From: Yashpal Dutta <yashpal.dutta@freescale.com> | ||
| 3 | Date: Tue, 11 Mar 2014 06:42:59 +0545 | ||
| 4 | Subject: [PATCH 09/26] Added hwrng dev file as source of RNG | ||
| 5 | |||
| 6 | Upstream-status: Pending | ||
| 7 | |||
| 8 | Signed-off-by: Yashpal Dutta <yashpal.dutta@freescale.com> | ||
| 9 | --- | ||
| 10 | e_os.h | 2 +- | ||
| 11 | 1 file changed, 1 insertion(+), 1 deletion(-) | ||
| 12 | |||
| 13 | diff --git a/e_os.h b/e_os.h | ||
| 14 | index 6a0aad1..57c0563 100644 | ||
| 15 | --- a/e_os.h | ||
| 16 | +++ b/e_os.h | ||
| 17 | @@ -79,7 +79,7 @@ extern "C" { | ||
| 18 | #ifndef DEVRANDOM | ||
| 19 | /* set this to a comma-separated list of 'random' device files to try out. | ||
| 20 | * My default, we will try to read at least one of these files */ | ||
| 21 | -#define DEVRANDOM "/dev/urandom","/dev/random","/dev/srandom" | ||
| 22 | +#define DEVRANDOM "/dev/hwrng","/dev/urandom","/dev/random","/dev/srandom" | ||
| 23 | #endif | ||
| 24 | #ifndef DEVRANDOM_EGD | ||
| 25 | /* set this to a comma-seperated list of 'egd' sockets to try out. These | ||
| 26 | -- | ||
| 27 | 2.3.5 | ||
| 28 | |||
diff --git a/recipes-connectivity/openssl/openssl-qoriq/qoriq/0009-RSA-Keygen-Fix.patch b/recipes-connectivity/openssl/openssl-qoriq/qoriq/0009-RSA-Keygen-Fix.patch new file mode 100644 index 000000000..d4cd02fd2 --- /dev/null +++ b/recipes-connectivity/openssl/openssl-qoriq/qoriq/0009-RSA-Keygen-Fix.patch | |||
| @@ -0,0 +1,64 @@ | |||
| 1 | From ca7adb9cf57497d27136a599531ea5b9671876c7 Mon Sep 17 00:00:00 2001 | ||
| 2 | From: Yashpal Dutta <yashpal.dutta@freescale.com> | ||
| 3 | Date: Wed, 16 Apr 2014 22:53:04 +0545 | ||
| 4 | Subject: [PATCH 09/48] RSA Keygen Fix | ||
| 5 | |||
| 6 | Upstream-status: Pending | ||
| 7 | |||
| 8 | If Kernel driver doesn't support RSA Keygen or same returns | ||
| 9 | error handling the keygen operation, the keygen is gracefully | ||
| 10 | handled by software supported rsa_keygen handler | ||
| 11 | |||
| 12 | Signed-off-by: Yashpal Dutta <yashpal.dutta@freescale.com> | ||
| 13 | Tested-by: Cristian Stoica <cristian.stoica@freescale.com> | ||
| 14 | --- | ||
| 15 | crypto/engine/eng_cryptodev.c | 12 +++++++----- | ||
| 16 | 1 file changed, 7 insertions(+), 5 deletions(-) | ||
| 17 | |||
| 18 | diff --git a/crypto/engine/eng_cryptodev.c b/crypto/engine/eng_cryptodev.c | ||
| 19 | index 44017a3..eac5fb6 100644 | ||
| 20 | --- a/crypto/engine/eng_cryptodev.c | ||
| 21 | +++ b/crypto/engine/eng_cryptodev.c | ||
| 22 | @@ -2018,7 +2018,7 @@ static int cryptodev_rsa_keygen(RSA *rsa, int bits, BIGNUM *e, BN_GENCB *cb) | ||
| 23 | int i; | ||
| 24 | |||
| 25 | if ((fd = get_asym_dev_crypto()) < 0) | ||
| 26 | - return fd; | ||
| 27 | + goto sw_try; | ||
| 28 | |||
| 29 | if (!rsa->n && ((rsa->n = BN_new()) == NULL)) | ||
| 30 | goto err; | ||
| 31 | @@ -2047,7 +2047,7 @@ static int cryptodev_rsa_keygen(RSA *rsa, int bits, BIGNUM *e, BN_GENCB *cb) | ||
| 32 | /* p length */ | ||
| 33 | kop.crk_param[kop.crk_iparams].crp_p = calloc(p_len + 1, sizeof(char)); | ||
| 34 | if (!kop.crk_param[kop.crk_iparams].crp_p) | ||
| 35 | - goto err; | ||
| 36 | + goto sw_try; | ||
| 37 | kop.crk_param[kop.crk_iparams].crp_nbits = p_len * 8; | ||
| 38 | memset(kop.crk_param[kop.crk_iparams].crp_p, 0xff, p_len + 1); | ||
| 39 | kop.crk_iparams++; | ||
| 40 | @@ -2055,7 +2055,7 @@ static int cryptodev_rsa_keygen(RSA *rsa, int bits, BIGNUM *e, BN_GENCB *cb) | ||
| 41 | /* q length */ | ||
| 42 | kop.crk_param[kop.crk_iparams].crp_p = calloc(q_len + 1, sizeof(char)); | ||
| 43 | if (!kop.crk_param[kop.crk_iparams].crp_p) | ||
| 44 | - goto err; | ||
| 45 | + goto sw_try; | ||
| 46 | kop.crk_param[kop.crk_iparams].crp_nbits = q_len * 8; | ||
| 47 | memset(kop.crk_param[kop.crk_iparams].crp_p, 0xff, q_len + 1); | ||
| 48 | kop.crk_iparams++; | ||
| 49 | @@ -2115,8 +2115,10 @@ static int cryptodev_rsa_keygen(RSA *rsa, int bits, BIGNUM *e, BN_GENCB *cb) | ||
| 50 | } | ||
| 51 | sw_try: | ||
| 52 | { | ||
| 53 | - const RSA_METHOD *meth = RSA_PKCS1_SSLeay(); | ||
| 54 | - ret = (meth->rsa_keygen) (rsa, bits, e, cb); | ||
| 55 | + const RSA_METHOD *meth = rsa->meth; | ||
| 56 | + rsa->meth = RSA_PKCS1_SSLeay(); | ||
| 57 | + ret = RSA_generate_key_ex(rsa, bits, e, cb); | ||
| 58 | + rsa->meth = meth; | ||
| 59 | } | ||
| 60 | return ret; | ||
| 61 | |||
| 62 | -- | ||
| 63 | 2.7.0 | ||
| 64 | |||
diff --git a/recipes-connectivity/openssl/openssl-qoriq/qoriq/0010-Asynchronous-interface-added-for-PKC-cryptodev-inter.patch b/recipes-connectivity/openssl/openssl-qoriq/qoriq/0010-Asynchronous-interface-added-for-PKC-cryptodev-inter.patch deleted file mode 100644 index 0f889c0fc..000000000 --- a/recipes-connectivity/openssl/openssl-qoriq/qoriq/0010-Asynchronous-interface-added-for-PKC-cryptodev-inter.patch +++ /dev/null | |||
| @@ -1,2039 +0,0 @@ | |||
| 1 | From a933e6341fd8989bdd82f8a5446b6f04aa00eef9 Mon Sep 17 00:00:00 2001 | ||
| 2 | From: Yashpal Dutta <yashpal.dutta@freescale.com> | ||
| 3 | Date: Tue, 11 Mar 2014 07:14:30 +0545 | ||
| 4 | Subject: [PATCH 10/26] Asynchronous interface added for PKC cryptodev | ||
| 5 | interface | ||
| 6 | |||
| 7 | Upstream-status: Pending | ||
| 8 | |||
| 9 | Signed-off-by: Yashpal Dutta <yashpal.dutta@freescale.com> | ||
| 10 | --- | ||
| 11 | crypto/crypto.h | 16 + | ||
| 12 | crypto/dh/dh.h | 4 +- | ||
| 13 | crypto/dsa/dsa.h | 5 + | ||
| 14 | crypto/ecdh/ech_locl.h | 3 + | ||
| 15 | crypto/ecdsa/ecs_locl.h | 5 + | ||
| 16 | crypto/engine/eng_cryptodev.c | 1578 +++++++++++++++++++++++++++++++++++++---- | ||
| 17 | crypto/engine/eng_int.h | 24 +- | ||
| 18 | crypto/engine/eng_lib.c | 46 ++ | ||
| 19 | crypto/engine/engine.h | 24 + | ||
| 20 | crypto/rsa/rsa.h | 23 + | ||
| 21 | 10 files changed, 1582 insertions(+), 146 deletions(-) | ||
| 22 | |||
| 23 | diff --git a/crypto/crypto.h b/crypto/crypto.h | ||
| 24 | index f92fc51..ce12731 100644 | ||
| 25 | --- a/crypto/crypto.h | ||
| 26 | +++ b/crypto/crypto.h | ||
| 27 | @@ -605,6 +605,22 @@ void ERR_load_CRYPTO_strings(void); | ||
| 28 | #define CRYPTO_R_FIPS_MODE_NOT_SUPPORTED 101 | ||
| 29 | #define CRYPTO_R_NO_DYNLOCK_CREATE_CALLBACK 100 | ||
| 30 | |||
| 31 | +/* Additions for Asynchronous PKC Infrastructure */ | ||
| 32 | +struct pkc_cookie_s { | ||
| 33 | + void *cookie; /* To be filled by openssl library primitive method function caller */ | ||
| 34 | + void *eng_cookie; /* To be filled by Engine */ | ||
| 35 | + /* | ||
| 36 | + * Callback handler to be provided by caller. Ensure to pass a | ||
| 37 | + * handler which takes the crypto operation to completion. | ||
| 38 | + * cookie: Container cookie from library | ||
| 39 | + * status: Status of the crypto Job completion. | ||
| 40 | + * 0: Job handled without any issue | ||
| 41 | + * -EINVAL: Parameters Invalid | ||
| 42 | + */ | ||
| 43 | + void (*pkc_callback)(struct pkc_cookie_s *cookie, int status); | ||
| 44 | + void *eng_handle; | ||
| 45 | +}; | ||
| 46 | + | ||
| 47 | #ifdef __cplusplus | ||
| 48 | } | ||
| 49 | #endif | ||
| 50 | diff --git a/crypto/dh/dh.h b/crypto/dh/dh.h | ||
| 51 | index ea59e61..20ffad2 100644 | ||
| 52 | --- a/crypto/dh/dh.h | ||
| 53 | +++ b/crypto/dh/dh.h | ||
| 54 | @@ -118,7 +118,9 @@ struct dh_method | ||
| 55 | int (*bn_mod_exp)(const DH *dh, BIGNUM *r, const BIGNUM *a, | ||
| 56 | const BIGNUM *p, const BIGNUM *m, BN_CTX *ctx, | ||
| 57 | BN_MONT_CTX *m_ctx); /* Can be null */ | ||
| 58 | - | ||
| 59 | + int (*compute_key_async)(unsigned char *key,const BIGNUM *pub_key,DH *dh, | ||
| 60 | + struct pkc_cookie_s *cookie); | ||
| 61 | + int (*generate_key_async)(DH *dh, struct pkc_cookie_s *cookie); | ||
| 62 | int (*init)(DH *dh); | ||
| 63 | int (*finish)(DH *dh); | ||
| 64 | int flags; | ||
| 65 | diff --git a/crypto/dsa/dsa.h b/crypto/dsa/dsa.h | ||
| 66 | index a6f6d0b..b04a029 100644 | ||
| 67 | --- a/crypto/dsa/dsa.h | ||
| 68 | +++ b/crypto/dsa/dsa.h | ||
| 69 | @@ -140,6 +140,10 @@ struct dsa_method | ||
| 70 | int (*bn_mod_exp)(DSA *dsa, BIGNUM *r, BIGNUM *a, const BIGNUM *p, | ||
| 71 | const BIGNUM *m, BN_CTX *ctx, | ||
| 72 | BN_MONT_CTX *m_ctx); /* Can be null */ | ||
| 73 | + int (*dsa_do_sign_async)(const unsigned char *dgst, int dlen, DSA *dsa, | ||
| 74 | + DSA_SIG *sig, struct pkc_cookie_s *cookie); | ||
| 75 | + int (*dsa_do_verify_async)(const unsigned char *dgst, int dgst_len, | ||
| 76 | + DSA_SIG *sig, DSA *dsa, struct pkc_cookie_s *cookie); | ||
| 77 | int (*init)(DSA *dsa); | ||
| 78 | int (*finish)(DSA *dsa); | ||
| 79 | int flags; | ||
| 80 | @@ -151,6 +155,7 @@ struct dsa_method | ||
| 81 | BN_GENCB *cb); | ||
| 82 | /* If this is non-NULL, it is used to generate DSA keys */ | ||
| 83 | int (*dsa_keygen)(DSA *dsa); | ||
| 84 | + int (*dsa_keygen_async)(DSA *dsa, struct pkc_cookie_s *cookie); | ||
| 85 | }; | ||
| 86 | |||
| 87 | struct dsa_st | ||
| 88 | diff --git a/crypto/ecdh/ech_locl.h b/crypto/ecdh/ech_locl.h | ||
| 89 | index f6cad6a..adce6b3 100644 | ||
| 90 | --- a/crypto/ecdh/ech_locl.h | ||
| 91 | +++ b/crypto/ecdh/ech_locl.h | ||
| 92 | @@ -67,6 +67,9 @@ struct ecdh_method | ||
| 93 | const char *name; | ||
| 94 | int (*compute_key)(void *key, size_t outlen, const EC_POINT *pub_key, EC_KEY *ecdh, | ||
| 95 | void *(*KDF)(const void *in, size_t inlen, void *out, size_t *outlen)); | ||
| 96 | + int (*compute_key_async)(void *key, size_t outlen, const EC_POINT *pub_key, EC_KEY *ecdh, | ||
| 97 | + void *(*KDF)(const void *in, size_t inlen, void *out, size_t *outlen), | ||
| 98 | + struct pkc_cookie_s *cookie); | ||
| 99 | #if 0 | ||
| 100 | int (*init)(EC_KEY *eckey); | ||
| 101 | int (*finish)(EC_KEY *eckey); | ||
| 102 | diff --git a/crypto/ecdsa/ecs_locl.h b/crypto/ecdsa/ecs_locl.h | ||
| 103 | index cb3be13..eb0ebe0 100644 | ||
| 104 | --- a/crypto/ecdsa/ecs_locl.h | ||
| 105 | +++ b/crypto/ecdsa/ecs_locl.h | ||
| 106 | @@ -74,6 +74,11 @@ struct ecdsa_method | ||
| 107 | BIGNUM **r); | ||
| 108 | int (*ecdsa_do_verify)(const unsigned char *dgst, int dgst_len, | ||
| 109 | const ECDSA_SIG *sig, EC_KEY *eckey); | ||
| 110 | + int (*ecdsa_do_sign_async)(const unsigned char *dgst, int dgst_len, | ||
| 111 | + const BIGNUM *inv, const BIGNUM *rp, EC_KEY *eckey, | ||
| 112 | + ECDSA_SIG *sig, struct pkc_cookie_s *cookie); | ||
| 113 | + int (*ecdsa_do_verify_async)(const unsigned char *dgst, int dgst_len, | ||
| 114 | + const ECDSA_SIG *sig, EC_KEY *eckey, struct pkc_cookie_s *cookie); | ||
| 115 | #if 0 | ||
| 116 | int (*init)(EC_KEY *eckey); | ||
| 117 | int (*finish)(EC_KEY *eckey); | ||
| 118 | diff --git a/crypto/engine/eng_cryptodev.c b/crypto/engine/eng_cryptodev.c | ||
| 119 | index 7ee314b..9f2416e 100644 | ||
| 120 | --- a/crypto/engine/eng_cryptodev.c | ||
| 121 | +++ b/crypto/engine/eng_cryptodev.c | ||
| 122 | @@ -1281,6 +1281,56 @@ zapparams(struct crypt_kop *kop) | ||
| 123 | } | ||
| 124 | } | ||
| 125 | |||
| 126 | +/* Any PKC request has at max 2 output parameters and they are stored here to | ||
| 127 | +be used while copying in the check availability */ | ||
| 128 | +struct cryptodev_cookie_s { | ||
| 129 | + BIGNUM *r; | ||
| 130 | + struct crparam r_param; | ||
| 131 | + BIGNUM *s; | ||
| 132 | + struct crparam s_param; | ||
| 133 | + struct crypt_kop *kop; | ||
| 134 | +}; | ||
| 135 | + | ||
| 136 | +static int | ||
| 137 | +cryptodev_asym_async(struct crypt_kop *kop, int rlen, BIGNUM *r, int slen, | ||
| 138 | + BIGNUM *s) | ||
| 139 | +{ | ||
| 140 | + int fd; | ||
| 141 | + struct pkc_cookie_s *cookie = kop->cookie; | ||
| 142 | + struct cryptodev_cookie_s *eng_cookie; | ||
| 143 | + | ||
| 144 | + fd = *(int *)cookie->eng_handle; | ||
| 145 | + | ||
| 146 | + eng_cookie = malloc(sizeof(struct cryptodev_cookie_s)); | ||
| 147 | + | ||
| 148 | + if (eng_cookie) { | ||
| 149 | + memset(eng_cookie, 0, sizeof(struct cryptodev_cookie_s)); | ||
| 150 | + if (r) { | ||
| 151 | + kop->crk_param[kop->crk_iparams].crp_p = calloc(rlen, sizeof(char)); | ||
| 152 | + if (!kop->crk_param[kop->crk_iparams].crp_p) | ||
| 153 | + return -ENOMEM; | ||
| 154 | + kop->crk_param[kop->crk_iparams].crp_nbits = rlen * 8; | ||
| 155 | + kop->crk_oparams++; | ||
| 156 | + eng_cookie->r = r; | ||
| 157 | + eng_cookie->r_param = kop->crk_param[kop->crk_iparams]; | ||
| 158 | + } | ||
| 159 | + if (s) { | ||
| 160 | + kop->crk_param[kop->crk_iparams+1].crp_p = calloc(slen, sizeof(char)); | ||
| 161 | + if (!kop->crk_param[kop->crk_iparams+1].crp_p) | ||
| 162 | + return -ENOMEM; | ||
| 163 | + kop->crk_param[kop->crk_iparams+1].crp_nbits = slen * 8; | ||
| 164 | + kop->crk_oparams++; | ||
| 165 | + eng_cookie->s = s; | ||
| 166 | + eng_cookie->s_param = kop->crk_param[kop->crk_iparams + 1]; | ||
| 167 | + } | ||
| 168 | + } else | ||
| 169 | + return -ENOMEM; | ||
| 170 | + | ||
| 171 | + eng_cookie->kop = kop; | ||
| 172 | + cookie->eng_cookie = eng_cookie; | ||
| 173 | + return ioctl(fd, CIOCASYMASYNCRYPT, kop); | ||
| 174 | +} | ||
| 175 | + | ||
| 176 | static int | ||
| 177 | cryptodev_asym(struct crypt_kop *kop, int rlen, BIGNUM *r, int slen, BIGNUM *s) | ||
| 178 | { | ||
| 179 | @@ -1337,6 +1387,44 @@ void *cryptodev_init_instance(void) | ||
| 180 | return fd; | ||
| 181 | } | ||
| 182 | |||
| 183 | +#include <poll.h> | ||
| 184 | + | ||
| 185 | +/* Return 0 on success and 1 on failure */ | ||
| 186 | +int cryptodev_check_availability(void *eng_handle) | ||
| 187 | +{ | ||
| 188 | + int fd = *(int *)eng_handle; | ||
| 189 | + struct pkc_cookie_list_s cookie_list; | ||
| 190 | + struct pkc_cookie_s *cookie; | ||
| 191 | + int i; | ||
| 192 | + | ||
| 193 | + /* FETCH COOKIE returns number of cookies extracted */ | ||
| 194 | + if (ioctl(fd, CIOCASYMFETCHCOOKIE, &cookie_list) <= 0) | ||
| 195 | + return 1; | ||
| 196 | + | ||
| 197 | + for (i = 0; i < cookie_list.cookie_available; i++) { | ||
| 198 | + cookie = cookie_list.cookie[i]; | ||
| 199 | + if (cookie) { | ||
| 200 | + struct cryptodev_cookie_s *eng_cookie = cookie->eng_cookie; | ||
| 201 | + if (eng_cookie) { | ||
| 202 | + struct crypt_kop *kop = eng_cookie->kop; | ||
| 203 | + | ||
| 204 | + if (eng_cookie->r) | ||
| 205 | + crparam2bn(&eng_cookie->r_param, eng_cookie->r); | ||
| 206 | + if (eng_cookie->s) | ||
| 207 | + crparam2bn(&eng_cookie->s_param, eng_cookie->s); | ||
| 208 | + if (kop->crk_op == CRK_DH_COMPUTE_KEY) | ||
| 209 | + kop->crk_oparams = 0; | ||
| 210 | + | ||
| 211 | + zapparams(eng_cookie->kop); | ||
| 212 | + free(eng_cookie->kop); | ||
| 213 | + free (eng_cookie); | ||
| 214 | + } | ||
| 215 | + cookie->pkc_callback(cookie, cookie_list.status[i]); | ||
| 216 | + } | ||
| 217 | + } | ||
| 218 | + return 0; | ||
| 219 | +} | ||
| 220 | + | ||
| 221 | static int | ||
| 222 | cryptodev_bn_mod_exp(BIGNUM *r, const BIGNUM *a, const BIGNUM *p, | ||
| 223 | const BIGNUM *m, BN_CTX *ctx, BN_MONT_CTX *in_mont) | ||
| 224 | @@ -1382,6 +1470,63 @@ err: | ||
| 225 | } | ||
| 226 | |||
| 227 | static int | ||
| 228 | +cryptodev_bn_mod_exp_async(BIGNUM *r, const BIGNUM *a, const BIGNUM *p, | ||
| 229 | + const BIGNUM *m, BN_CTX *ctx, BN_MONT_CTX *in_mont, struct pkc_cookie_s *cookie) | ||
| 230 | +{ | ||
| 231 | + struct crypt_kop *kop = malloc(sizeof(struct crypt_kop)); | ||
| 232 | + int ret = 1; | ||
| 233 | + | ||
| 234 | + /* Currently, we know we can do mod exp iff we can do any | ||
| 235 | + * asymmetric operations at all. | ||
| 236 | + */ | ||
| 237 | + if (cryptodev_asymfeat == 0 || !kop) { | ||
| 238 | + ret = BN_mod_exp(r, a, p, m, ctx); | ||
| 239 | + return (ret); | ||
| 240 | + } | ||
| 241 | + | ||
| 242 | + kop->crk_oparams = 0; | ||
| 243 | + kop->crk_status = 0; | ||
| 244 | + kop->crk_op = CRK_MOD_EXP; | ||
| 245 | + kop->cookie = cookie; | ||
| 246 | + /* inputs: a^p % m */ | ||
| 247 | + if (bn2crparam(a, &kop->crk_param[0])) | ||
| 248 | + goto err; | ||
| 249 | + if (bn2crparam(p, &kop->crk_param[1])) | ||
| 250 | + goto err; | ||
| 251 | + if (bn2crparam(m, &kop->crk_param[2])) | ||
| 252 | + goto err; | ||
| 253 | + | ||
| 254 | + kop->crk_iparams = 3; | ||
| 255 | + if (cryptodev_asym_async(kop, BN_num_bytes(m), r, 0, NULL)) | ||
| 256 | + goto err; | ||
| 257 | + | ||
| 258 | + return ret; | ||
| 259 | +err: | ||
| 260 | + { | ||
| 261 | + const RSA_METHOD *meth = RSA_PKCS1_SSLeay(); | ||
| 262 | + | ||
| 263 | + if (kop) | ||
| 264 | + free(kop); | ||
| 265 | + ret = meth->bn_mod_exp(r, a, p, m, ctx, in_mont); | ||
| 266 | + if (ret) | ||
| 267 | + /* Call the completion handler immediately */ | ||
| 268 | + cookie->pkc_callback(cookie, 0); | ||
| 269 | + } | ||
| 270 | + return ret; | ||
| 271 | +} | ||
| 272 | + | ||
| 273 | +static int | ||
| 274 | +cryptodev_rsa_nocrt_mod_exp_async(BIGNUM *r0, const BIGNUM *I, | ||
| 275 | + RSA *rsa, BN_CTX *ctx, struct pkc_cookie_s *cookie) | ||
| 276 | +{ | ||
| 277 | + int r; | ||
| 278 | + ctx = BN_CTX_new(); | ||
| 279 | + r = cryptodev_bn_mod_exp_async(r0, I, rsa->d, rsa->n, ctx, NULL, cookie); | ||
| 280 | + BN_CTX_free(ctx); | ||
| 281 | + return r; | ||
| 282 | +} | ||
| 283 | + | ||
| 284 | +static int | ||
| 285 | cryptodev_rsa_nocrt_mod_exp(BIGNUM *r0, const BIGNUM *I, RSA *rsa, BN_CTX *ctx) | ||
| 286 | { | ||
| 287 | int r; | ||
| 288 | @@ -1446,6 +1591,62 @@ err: | ||
| 289 | return (ret); | ||
| 290 | } | ||
| 291 | |||
| 292 | +static int | ||
| 293 | +cryptodev_rsa_mod_exp_async(BIGNUM *r0, const BIGNUM *I, RSA *rsa, BN_CTX *ctx, | ||
| 294 | + struct pkc_cookie_s *cookie) | ||
| 295 | +{ | ||
| 296 | + struct crypt_kop *kop = malloc(sizeof(struct crypt_kop)); | ||
| 297 | + int ret = 1, f_len, p_len, q_len; | ||
| 298 | + unsigned char *f = NULL, *p = NULL, *q = NULL, *dp = NULL, *dq = NULL, *c = NULL; | ||
| 299 | + | ||
| 300 | + if (!rsa->p || !rsa->q || !rsa->dmp1 || !rsa->dmq1 || !rsa->iqmp || !kop) { | ||
| 301 | + return (0); | ||
| 302 | + } | ||
| 303 | + | ||
| 304 | + kop->crk_oparams = 0; | ||
| 305 | + kop->crk_status = 0; | ||
| 306 | + kop->crk_op = CRK_MOD_EXP_CRT; | ||
| 307 | + f_len = BN_num_bytes(rsa->n); | ||
| 308 | + spcf_bn2bin_ex(I, &f, &f_len); | ||
| 309 | + spcf_bn2bin(rsa->p, &p, &p_len); | ||
| 310 | + spcf_bn2bin(rsa->q, &q, &q_len); | ||
| 311 | + spcf_bn2bin_ex(rsa->dmp1, &dp, &p_len); | ||
| 312 | + spcf_bn2bin_ex(rsa->iqmp, &c, &p_len); | ||
| 313 | + spcf_bn2bin_ex(rsa->dmq1, &dq, &q_len); | ||
| 314 | + /* inputs: rsa->p rsa->q I rsa->dmp1 rsa->dmq1 rsa->iqmp */ | ||
| 315 | + kop->crk_param[0].crp_p = p; | ||
| 316 | + kop->crk_param[0].crp_nbits = p_len * 8; | ||
| 317 | + kop->crk_param[1].crp_p = q; | ||
| 318 | + kop->crk_param[1].crp_nbits = q_len * 8; | ||
| 319 | + kop->crk_param[2].crp_p = f; | ||
| 320 | + kop->crk_param[2].crp_nbits = f_len * 8; | ||
| 321 | + kop->crk_param[3].crp_p = dp; | ||
| 322 | + kop->crk_param[3].crp_nbits = p_len * 8; | ||
| 323 | + /* dq must of length q, rest all of length p*/ | ||
| 324 | + kop->crk_param[4].crp_p = dq; | ||
| 325 | + kop->crk_param[4].crp_nbits = q_len * 8; | ||
| 326 | + kop->crk_param[5].crp_p = c; | ||
| 327 | + kop->crk_param[5].crp_nbits = p_len * 8; | ||
| 328 | + kop->crk_iparams = 6; | ||
| 329 | + kop->cookie = cookie; | ||
| 330 | + if (cryptodev_asym_async(kop, BN_num_bytes(rsa->n), r0, 0, NULL)) | ||
| 331 | + goto err; | ||
| 332 | + | ||
| 333 | + return ret; | ||
| 334 | +err: | ||
| 335 | + { | ||
| 336 | + const RSA_METHOD *meth = RSA_PKCS1_SSLeay(); | ||
| 337 | + | ||
| 338 | + if (kop) | ||
| 339 | + free(kop); | ||
| 340 | + ret = (*meth->rsa_mod_exp)(r0, I, rsa, ctx); | ||
| 341 | + if (ret) | ||
| 342 | + /* Call user completion handler immediately */ | ||
| 343 | + cookie->pkc_callback(cookie, 0); | ||
| 344 | + } | ||
| 345 | + return (ret); | ||
| 346 | +} | ||
| 347 | + | ||
| 348 | static RSA_METHOD cryptodev_rsa = { | ||
| 349 | "cryptodev RSA method", | ||
| 350 | NULL, /* rsa_pub_enc */ | ||
| 351 | @@ -1454,6 +1655,12 @@ static RSA_METHOD cryptodev_rsa = { | ||
| 352 | NULL, /* rsa_priv_dec */ | ||
| 353 | NULL, | ||
| 354 | NULL, | ||
| 355 | + NULL, /* rsa_pub_enc */ | ||
| 356 | + NULL, /* rsa_pub_dec */ | ||
| 357 | + NULL, /* rsa_priv_enc */ | ||
| 358 | + NULL, /* rsa_priv_dec */ | ||
| 359 | + NULL, | ||
| 360 | + NULL, | ||
| 361 | NULL, /* init */ | ||
| 362 | NULL, /* finish */ | ||
| 363 | 0, /* flags */ | ||
| 364 | @@ -1751,126 +1958,424 @@ sw_try: | ||
| 365 | return ret; | ||
| 366 | } | ||
| 367 | |||
| 368 | +/* Cryptodev DSA Key Gen routine */ | ||
| 369 | +static int cryptodev_dsa_keygen_async(DSA *dsa, struct pkc_cookie_s *cookie) | ||
| 370 | +{ | ||
| 371 | + struct crypt_kop *kop = malloc(sizeof(struct crypt_kop)); | ||
| 372 | + int ret = 1, g_len; | ||
| 373 | + unsigned char *g = NULL; | ||
| 374 | |||
| 375 | + if (!kop) | ||
| 376 | + goto sw_try; | ||
| 377 | |||
| 378 | -static DSA_METHOD cryptodev_dsa = { | ||
| 379 | - "cryptodev DSA method", | ||
| 380 | - NULL, | ||
| 381 | - NULL, /* dsa_sign_setup */ | ||
| 382 | - NULL, | ||
| 383 | - NULL, /* dsa_mod_exp */ | ||
| 384 | - NULL, | ||
| 385 | - NULL, /* init */ | ||
| 386 | - NULL, /* finish */ | ||
| 387 | - 0, /* flags */ | ||
| 388 | - NULL /* app_data */ | ||
| 389 | -}; | ||
| 390 | + if (dsa->priv_key == NULL) { | ||
| 391 | + if ((dsa->priv_key=BN_new()) == NULL) | ||
| 392 | + goto sw_try; | ||
| 393 | + } | ||
| 394 | |||
| 395 | -static ECDSA_METHOD cryptodev_ecdsa = { | ||
| 396 | - "cryptodev ECDSA method", | ||
| 397 | - NULL, | ||
| 398 | - NULL, /* ecdsa_sign_setup */ | ||
| 399 | - NULL, | ||
| 400 | - NULL, | ||
| 401 | - 0, /* flags */ | ||
| 402 | - NULL /* app_data */ | ||
| 403 | -}; | ||
| 404 | + if (dsa->pub_key == NULL) { | ||
| 405 | + if ((dsa->pub_key=BN_new()) == NULL) | ||
| 406 | + goto sw_try; | ||
| 407 | + } | ||
| 408 | |||
| 409 | -typedef enum ec_curve_s | ||
| 410 | -{ | ||
| 411 | - EC_PRIME, | ||
| 412 | - EC_BINARY | ||
| 413 | -} ec_curve_t; | ||
| 414 | + g_len = BN_num_bytes(dsa->p); | ||
| 415 | + /** | ||
| 416 | + * Get generator into a plain buffer. If length is less than | ||
| 417 | + * q_len then add leading padding bytes. | ||
| 418 | + */ | ||
| 419 | + if (spcf_bn2bin_ex(dsa->g, &g, &g_len)) { | ||
| 420 | + DSAerr(DSA_F_DSA_GENERATE_KEY, ERR_R_MALLOC_FAILURE); | ||
| 421 | + goto sw_try; | ||
| 422 | + } | ||
| 423 | |||
| 424 | -/* ENGINE handler for ECDSA Sign */ | ||
| 425 | -static ECDSA_SIG *cryptodev_ecdsa_do_sign( const unsigned char *dgst, | ||
| 426 | - int dgst_len, const BIGNUM *in_kinv, const BIGNUM *in_r, EC_KEY *eckey) | ||
| 427 | -{ | ||
| 428 | - BIGNUM *m = NULL, *p = NULL, *a = NULL; | ||
| 429 | - BIGNUM *b = NULL, *x = NULL, *y = NULL; | ||
| 430 | - BN_CTX *ctx = NULL; | ||
| 431 | - ECDSA_SIG *ret = NULL; | ||
| 432 | - ECDSA_DATA *ecdsa = NULL; | ||
| 433 | - unsigned char * q = NULL, *r = NULL, *ab = NULL, *g_xy = NULL; | ||
| 434 | - unsigned char * s = NULL, *c = NULL, *d = NULL, *f = NULL, *tmp_dgst = NULL; | ||
| 435 | - int i = 0, q_len = 0, priv_key_len = 0, r_len = 0; | ||
| 436 | - int g_len = 0, d_len = 0, ab_len = 0; | ||
| 437 | - const BIGNUM *order = NULL, *priv_key=NULL; | ||
| 438 | - const EC_GROUP *group = NULL; | ||
| 439 | - struct crypt_kop kop; | ||
| 440 | - ec_curve_t ec_crv = EC_PRIME; | ||
| 441 | + memset(kop, 0, sizeof(struct crypt_kop)); | ||
| 442 | + kop->crk_op = CRK_DSA_GENERATE_KEY; | ||
| 443 | + if (bn2crparam(dsa->p, &kop->crk_param[0])) | ||
| 444 | + goto sw_try; | ||
| 445 | + if (bn2crparam(dsa->q, &kop->crk_param[1])) | ||
| 446 | + goto sw_try; | ||
| 447 | + kop->crk_param[2].crp_p = g; | ||
| 448 | + kop->crk_param[2].crp_nbits = g_len * 8; | ||
| 449 | + kop->crk_iparams = 3; | ||
| 450 | + kop->cookie = cookie; | ||
| 451 | |||
| 452 | - memset(&kop, 0, sizeof(kop)); | ||
| 453 | - ecdsa = ecdsa_check(eckey); | ||
| 454 | - if (!ecdsa) { | ||
| 455 | - ECDSAerr(ECDSA_F_ECDSA_DO_SIGN, ERR_R_PASSED_NULL_PARAMETER); | ||
| 456 | - return NULL; | ||
| 457 | + /* pub_key is or prime length while priv key is of length of order */ | ||
| 458 | + if (cryptodev_asym_async(kop, BN_num_bytes(dsa->p), dsa->pub_key, | ||
| 459 | + BN_num_bytes(dsa->q), dsa->priv_key)) | ||
| 460 | + goto sw_try; | ||
| 461 | + | ||
| 462 | + return ret; | ||
| 463 | +sw_try: | ||
| 464 | + { | ||
| 465 | + const DSA_METHOD *meth = DSA_OpenSSL(); | ||
| 466 | + | ||
| 467 | + if (kop) | ||
| 468 | + free(kop); | ||
| 469 | + ret = (meth->dsa_keygen)(dsa); | ||
| 470 | + cookie->pkc_callback(cookie, 0); | ||
| 471 | } | ||
| 472 | + return ret; | ||
| 473 | +} | ||
| 474 | |||
| 475 | - group = EC_KEY_get0_group(eckey); | ||
| 476 | - priv_key = EC_KEY_get0_private_key(eckey); | ||
| 477 | +static int | ||
| 478 | +cryptodev_dsa_do_sign_async(const unsigned char *dgst, int dlen, DSA *dsa, | ||
| 479 | + DSA_SIG *sig, struct pkc_cookie_s *cookie) | ||
| 480 | +{ | ||
| 481 | + struct crypt_kop *kop = malloc(sizeof(struct crypt_kop)); | ||
| 482 | + DSA_SIG *dsaret = NULL; | ||
| 483 | + int q_len = 0, r_len = 0, g_len = 0; | ||
| 484 | + int priv_key_len = 0, ret = 1; | ||
| 485 | + unsigned char *q = NULL, *r = NULL, *g = NULL, *priv_key = NULL, *f = NULL; | ||
| 486 | |||
| 487 | - if (!group || !priv_key) { | ||
| 488 | - ECDSAerr(ECDSA_F_ECDSA_DO_SIGN, ERR_R_PASSED_NULL_PARAMETER); | ||
| 489 | - return NULL; | ||
| 490 | + if (((sig->r = BN_new()) == NULL) || !kop) { | ||
| 491 | + DSAerr(DSA_F_DSA_DO_SIGN, ERR_R_MALLOC_FAILURE); | ||
| 492 | + goto err; | ||
| 493 | } | ||
| 494 | |||
| 495 | - if ((ctx = BN_CTX_new()) == NULL || (m = BN_new()) == NULL || | ||
| 496 | - (a = BN_new()) == NULL || (b = BN_new()) == NULL || | ||
| 497 | - (p = BN_new()) == NULL || (x = BN_new()) == NULL || | ||
| 498 | - (y = BN_new()) == NULL) { | ||
| 499 | - ECDSAerr(ECDSA_F_ECDSA_DO_SIGN, ERR_R_MALLOC_FAILURE); | ||
| 500 | + if ((sig->s = BN_new()) == NULL) { | ||
| 501 | + BN_free(sig->r); | ||
| 502 | + DSAerr(DSA_F_DSA_DO_SIGN, ERR_R_MALLOC_FAILURE); | ||
| 503 | goto err; | ||
| 504 | } | ||
| 505 | |||
| 506 | - order = &group->order; | ||
| 507 | - if (!order || BN_is_zero(order)) { | ||
| 508 | - ECDSAerr(ECDSA_F_ECDSA_DO_SIGN, ECDSA_R_MISSING_PARAMETERS); | ||
| 509 | + if (spcf_bn2bin(dsa->p, &q, &q_len)) { | ||
| 510 | + DSAerr(DSA_F_DSA_DO_SIGN, DSA_R_DATA_TOO_LARGE_FOR_KEY_SIZE); | ||
| 511 | goto err; | ||
| 512 | } | ||
| 513 | |||
| 514 | - i = BN_num_bits(order); | ||
| 515 | - /* Need to truncate digest if it is too long: first truncate whole | ||
| 516 | - bytes */ | ||
| 517 | - if (8 * dgst_len > i) | ||
| 518 | - dgst_len = (i + 7)/8; | ||
| 519 | + /* Get order of the field of private keys into plain buffer */ | ||
| 520 | + if (spcf_bn2bin (dsa->q, &r, &r_len)) { | ||
| 521 | + DSAerr(DSA_F_DSA_DO_SIGN, ERR_R_MALLOC_FAILURE); | ||
| 522 | + goto err; | ||
| 523 | + } | ||
| 524 | |||
| 525 | - if (!BN_bin2bn(dgst, dgst_len, m)) { | ||
| 526 | - ECDSAerr(ECDSA_F_ECDSA_DO_SIGN, ERR_R_BN_LIB); | ||
| 527 | + /* sanity test */ | ||
| 528 | + if (dlen > r_len) { | ||
| 529 | + DSAerr(DSA_F_DSA_DO_SIGN, DSA_R_DATA_TOO_LARGE_FOR_KEY_SIZE); | ||
| 530 | goto err; | ||
| 531 | } | ||
| 532 | |||
| 533 | - /* If still too long truncate remaining bits with a shift */ | ||
| 534 | - if ((8 * dgst_len > i) && !BN_rshift(m, m, 8 - (i & 0x7))) { | ||
| 535 | - ECDSAerr(ECDSA_F_ECDSA_DO_SIGN, ERR_R_BN_LIB); | ||
| 536 | + g_len = q_len; | ||
| 537 | + /** | ||
| 538 | + * Get generator into a plain buffer. If length is less than | ||
| 539 | + * q_len then add leading padding bytes. | ||
| 540 | + */ | ||
| 541 | + if (spcf_bn2bin_ex(dsa->g, &g, &g_len)) { | ||
| 542 | + DSAerr(DSA_F_DSA_DO_SIGN, ERR_R_MALLOC_FAILURE); | ||
| 543 | goto err; | ||
| 544 | } | ||
| 545 | |||
| 546 | - /* copy the truncated bits into plain buffer */ | ||
| 547 | - if (spcf_bn2bin(m, &tmp_dgst, &dgst_len)) { | ||
| 548 | - fprintf(stderr, "%s:%d: OPENSSL_malloc failec\n", __FUNCTION__, __LINE__); | ||
| 549 | + priv_key_len = r_len; | ||
| 550 | + /** | ||
| 551 | + * Get private key into a plain buffer. If length is less than | ||
| 552 | + * r_len then add leading padding bytes. | ||
| 553 | + */ | ||
| 554 | + if (spcf_bn2bin_ex(dsa->priv_key, &priv_key, &priv_key_len)) { | ||
| 555 | + DSAerr(DSA_F_DSA_DO_SIGN, ERR_R_MALLOC_FAILURE); | ||
| 556 | goto err; | ||
| 557 | } | ||
| 558 | |||
| 559 | - ret = ECDSA_SIG_new(); | ||
| 560 | - if (!ret) { | ||
| 561 | - ECDSAerr(ECDSA_F_ECDSA_DO_SIGN, ERR_R_BN_LIB); | ||
| 562 | + /* Allocate memory to store hash. */ | ||
| 563 | + f = OPENSSL_malloc (r_len); | ||
| 564 | + if (!f) { | ||
| 565 | + DSAerr(DSA_F_DSA_DO_SIGN, ERR_R_MALLOC_FAILURE); | ||
| 566 | goto err; | ||
| 567 | } | ||
| 568 | |||
| 569 | - /* check if this is prime or binary EC request */ | ||
| 570 | - if (EC_METHOD_get_field_type(EC_GROUP_method_of(group)) == NID_X9_62_prime_field) { | ||
| 571 | - ec_crv = EC_PRIME; | ||
| 572 | - /* get the generator point pair */ | ||
| 573 | - if (!EC_POINT_get_affine_coordinates_GFp (group, EC_GROUP_get0_generator(group), | ||
| 574 | - x, y,ctx)) { | ||
| 575 | - ECDSAerr(ECDSA_F_ECDSA_DO_SIGN, ERR_R_EC_LIB); | ||
| 576 | - goto err; | ||
| 577 | - } | ||
| 578 | + /* Add padding, since SEC expects hash to of size r_len */ | ||
| 579 | + if (dlen < r_len) | ||
| 580 | + memset(f, 0, r_len - dlen); | ||
| 581 | |||
| 582 | - /* get the ECC curve parameters */ | ||
| 583 | - if (!EC_GROUP_get_curve_GFp(group, p, a, b , ctx)) { | ||
| 584 | - ECDSAerr(ECDSA_F_ECDSA_DO_SIGN, ERR_R_EC_LIB); | ||
| 585 | + /* Skip leading bytes if dgst_len < r_len */ | ||
| 586 | + memcpy(f + r_len - dlen, dgst, dlen); | ||
| 587 | + | ||
| 588 | + dlen = r_len; | ||
| 589 | + | ||
| 590 | + memset(kop, 0, sizeof( struct crypt_kop)); | ||
| 591 | + kop->crk_op = CRK_DSA_SIGN; | ||
| 592 | + | ||
| 593 | + /* inputs: dgst dsa->p dsa->q dsa->g dsa->priv_key */ | ||
| 594 | + kop->crk_param[0].crp_p = (void*)f; | ||
| 595 | + kop->crk_param[0].crp_nbits = dlen * 8; | ||
| 596 | + kop->crk_param[1].crp_p = (void*)q; | ||
| 597 | + kop->crk_param[1].crp_nbits = q_len * 8; | ||
| 598 | + kop->crk_param[2].crp_p = (void*)r; | ||
| 599 | + kop->crk_param[2].crp_nbits = r_len * 8; | ||
| 600 | + kop->crk_param[3].crp_p = (void*)g; | ||
| 601 | + kop->crk_param[3].crp_nbits = g_len * 8; | ||
| 602 | + kop->crk_param[4].crp_p = (void*)priv_key; | ||
| 603 | + kop->crk_param[4].crp_nbits = priv_key_len * 8; | ||
| 604 | + kop->crk_iparams = 5; | ||
| 605 | + kop->cookie = cookie; | ||
| 606 | + | ||
| 607 | + if (cryptodev_asym_async(kop, r_len, sig->r, r_len, sig->s)) | ||
| 608 | + goto err; | ||
| 609 | + | ||
| 610 | + return ret; | ||
| 611 | +err: | ||
| 612 | + { | ||
| 613 | + const DSA_METHOD *meth = DSA_OpenSSL(); | ||
| 614 | + | ||
| 615 | + if (kop) | ||
| 616 | + free(kop); | ||
| 617 | + BN_free(sig->r); | ||
| 618 | + BN_free(sig->s); | ||
| 619 | + dsaret = (meth->dsa_do_sign)(dgst, dlen, dsa); | ||
| 620 | + sig->r = dsaret->r; | ||
| 621 | + sig->s = dsaret->s; | ||
| 622 | + /* Call user callback immediately */ | ||
| 623 | + cookie->pkc_callback(cookie, 0); | ||
| 624 | + ret = dsaret; | ||
| 625 | + } | ||
| 626 | + return ret; | ||
| 627 | +} | ||
| 628 | + | ||
| 629 | +static int | ||
| 630 | +cryptodev_dsa_verify_async(const unsigned char *dgst, int dlen, | ||
| 631 | + DSA_SIG *sig, DSA *dsa, struct pkc_cookie_s *cookie) | ||
| 632 | +{ | ||
| 633 | + struct crypt_kop *kop = malloc(sizeof(struct crypt_kop)); | ||
| 634 | + int q_len = 0, r_len = 0, g_len = 0; | ||
| 635 | + int w_len = 0 ,c_len = 0, d_len = 0, ret = 1; | ||
| 636 | + unsigned char * q = NULL, * r = NULL, * w = NULL, * g = NULL; | ||
| 637 | + unsigned char *c = NULL, * d = NULL, *f = NULL; | ||
| 638 | + | ||
| 639 | + if (!kop) | ||
| 640 | + goto err; | ||
| 641 | + | ||
| 642 | + if (spcf_bn2bin(dsa->p, &q, &q_len)) { | ||
| 643 | + DSAerr(DSA_F_DSA_DO_VERIFY, ERR_R_MALLOC_FAILURE); | ||
| 644 | + return ret; | ||
| 645 | + } | ||
| 646 | + | ||
| 647 | + /* Get Order of field of private keys */ | ||
| 648 | + if (spcf_bn2bin(dsa->q, &r, &r_len)) { | ||
| 649 | + DSAerr(DSA_F_DSA_DO_VERIFY, ERR_R_MALLOC_FAILURE); | ||
| 650 | + goto err; | ||
| 651 | + } | ||
| 652 | + | ||
| 653 | + g_len = q_len; | ||
| 654 | + /** | ||
| 655 | + * Get generator into a plain buffer. If length is less than | ||
| 656 | + * q_len then add leading padding bytes. | ||
| 657 | + */ | ||
| 658 | + if (spcf_bn2bin_ex(dsa->g, &g, &g_len)) { | ||
| 659 | + DSAerr(DSA_F_DSA_DO_VERIFY, ERR_R_MALLOC_FAILURE); | ||
| 660 | + goto err; | ||
| 661 | + } | ||
| 662 | + w_len = q_len; | ||
| 663 | + /** | ||
| 664 | + * Get public key into a plain buffer. If length is less than | ||
| 665 | + * q_len then add leading padding bytes. | ||
| 666 | + */ | ||
| 667 | + if (spcf_bn2bin_ex(dsa->pub_key, &w, &w_len)) { | ||
| 668 | + DSAerr(DSA_F_DSA_DO_VERIFY, ERR_R_MALLOC_FAILURE); | ||
| 669 | + goto err; | ||
| 670 | + } | ||
| 671 | + /** | ||
| 672 | + * Get the 1st part of signature into a flat buffer with | ||
| 673 | + * appropriate padding | ||
| 674 | + */ | ||
| 675 | + c_len = r_len; | ||
| 676 | + | ||
| 677 | + if (spcf_bn2bin_ex(sig->r, &c, &c_len)) { | ||
| 678 | + ECDSAerr(ECDSA_F_ECDSA_DO_VERIFY, ERR_R_MALLOC_FAILURE); | ||
| 679 | + goto err; | ||
| 680 | + } | ||
| 681 | + | ||
| 682 | + /** | ||
| 683 | + * Get the 2nd part of signature into a flat buffer with | ||
| 684 | + * appropriate padding | ||
| 685 | + */ | ||
| 686 | + d_len = r_len; | ||
| 687 | + | ||
| 688 | + if (spcf_bn2bin_ex(sig->s, &d, &d_len)) { | ||
| 689 | + ECDSAerr(ECDSA_F_ECDSA_DO_VERIFY, ERR_R_MALLOC_FAILURE); | ||
| 690 | + goto err; | ||
| 691 | + } | ||
| 692 | + | ||
| 693 | + | ||
| 694 | + /* Sanity test */ | ||
| 695 | + if (dlen > r_len) { | ||
| 696 | + ECDSAerr(ECDSA_F_ECDSA_DO_VERIFY, ERR_R_MALLOC_FAILURE); | ||
| 697 | + goto err; | ||
| 698 | + } | ||
| 699 | + | ||
| 700 | + /* Allocate memory to store hash. */ | ||
| 701 | + f = OPENSSL_malloc (r_len); | ||
| 702 | + if (!f) { | ||
| 703 | + DSAerr(ECDSA_F_ECDSA_DO_VERIFY, ERR_R_MALLOC_FAILURE); | ||
| 704 | + goto err; | ||
| 705 | + } | ||
| 706 | + | ||
| 707 | + /* Add padding, since SEC expects hash to of size r_len */ | ||
| 708 | + if (dlen < r_len) | ||
| 709 | + memset(f, 0, r_len - dlen); | ||
| 710 | + | ||
| 711 | + /* Skip leading bytes if dgst_len < r_len */ | ||
| 712 | + memcpy(f + r_len - dlen, dgst, dlen); | ||
| 713 | + | ||
| 714 | + dlen = r_len; | ||
| 715 | + memset(kop, 0, sizeof(struct crypt_kop)); | ||
| 716 | + | ||
| 717 | + /* inputs: dgst dsa->p dsa->q dsa->g dsa->pub_key sig->r sig->s */ | ||
| 718 | + kop->crk_param[0].crp_p = (void*)f; | ||
| 719 | + kop->crk_param[0].crp_nbits = dlen * 8; | ||
| 720 | + kop->crk_param[1].crp_p = q; | ||
| 721 | + kop->crk_param[1].crp_nbits = q_len * 8; | ||
| 722 | + kop->crk_param[2].crp_p = r; | ||
| 723 | + kop->crk_param[2].crp_nbits = r_len * 8; | ||
| 724 | + kop->crk_param[3].crp_p = g; | ||
| 725 | + kop->crk_param[3].crp_nbits = g_len * 8; | ||
| 726 | + kop->crk_param[4].crp_p = w; | ||
| 727 | + kop->crk_param[4].crp_nbits = w_len * 8; | ||
| 728 | + kop->crk_param[5].crp_p = c; | ||
| 729 | + kop->crk_param[5].crp_nbits = c_len * 8; | ||
| 730 | + kop->crk_param[6].crp_p = d; | ||
| 731 | + kop->crk_param[6].crp_nbits = d_len * 8; | ||
| 732 | + kop->crk_iparams = 7; | ||
| 733 | + kop->crk_op = CRK_DSA_VERIFY; | ||
| 734 | + kop->cookie = cookie; | ||
| 735 | + if (cryptodev_asym_async(kop, 0, NULL, 0, NULL)) | ||
| 736 | + goto err; | ||
| 737 | + | ||
| 738 | + return ret; | ||
| 739 | +err: | ||
| 740 | + { | ||
| 741 | + const DSA_METHOD *meth = DSA_OpenSSL(); | ||
| 742 | + | ||
| 743 | + if (kop) | ||
| 744 | + free(kop); | ||
| 745 | + | ||
| 746 | + ret = (meth->dsa_do_verify)(dgst, dlen, sig, dsa); | ||
| 747 | + cookie->pkc_callback(cookie, 0); | ||
| 748 | + } | ||
| 749 | + return ret; | ||
| 750 | +} | ||
| 751 | + | ||
| 752 | +static DSA_METHOD cryptodev_dsa = { | ||
| 753 | + "cryptodev DSA method", | ||
| 754 | + NULL, | ||
| 755 | + NULL, /* dsa_sign_setup */ | ||
| 756 | + NULL, | ||
| 757 | + NULL, /* dsa_mod_exp */ | ||
| 758 | + NULL, | ||
| 759 | + NULL, | ||
| 760 | + NULL, | ||
| 761 | + NULL, | ||
| 762 | + NULL, /* init */ | ||
| 763 | + NULL, /* finish */ | ||
| 764 | + 0, /* flags */ | ||
| 765 | + NULL /* app_data */ | ||
| 766 | +}; | ||
| 767 | + | ||
| 768 | +static ECDSA_METHOD cryptodev_ecdsa = { | ||
| 769 | + "cryptodev ECDSA method", | ||
| 770 | + NULL, | ||
| 771 | + NULL, /* ecdsa_sign_setup */ | ||
| 772 | + NULL, | ||
| 773 | + NULL, | ||
| 774 | + NULL, | ||
| 775 | + NULL, | ||
| 776 | + 0, /* flags */ | ||
| 777 | + NULL /* app_data */ | ||
| 778 | +}; | ||
| 779 | + | ||
| 780 | +typedef enum ec_curve_s | ||
| 781 | +{ | ||
| 782 | + EC_PRIME, | ||
| 783 | + EC_BINARY | ||
| 784 | +} ec_curve_t; | ||
| 785 | + | ||
| 786 | +/* ENGINE handler for ECDSA Sign */ | ||
| 787 | +static ECDSA_SIG *cryptodev_ecdsa_do_sign( const unsigned char *dgst, | ||
| 788 | + int dgst_len, const BIGNUM *in_kinv, const BIGNUM *in_r, EC_KEY *eckey) | ||
| 789 | +{ | ||
| 790 | + BIGNUM *m = NULL, *p = NULL, *a = NULL; | ||
| 791 | + BIGNUM *b = NULL, *x = NULL, *y = NULL; | ||
| 792 | + BN_CTX *ctx = NULL; | ||
| 793 | + ECDSA_SIG *ret = NULL; | ||
| 794 | + ECDSA_DATA *ecdsa = NULL; | ||
| 795 | + unsigned char * q = NULL, *r = NULL, *ab = NULL, *g_xy = NULL; | ||
| 796 | + unsigned char * s = NULL, *c = NULL, *d = NULL, *f = NULL, *tmp_dgst = NULL; | ||
| 797 | + int i = 0, q_len = 0, priv_key_len = 0, r_len = 0; | ||
| 798 | + int g_len = 0, d_len = 0, ab_len = 0; | ||
| 799 | + const BIGNUM *order = NULL, *priv_key=NULL; | ||
| 800 | + const EC_GROUP *group = NULL; | ||
| 801 | + struct crypt_kop kop; | ||
| 802 | + ec_curve_t ec_crv = EC_PRIME; | ||
| 803 | + | ||
| 804 | + memset(&kop, 0, sizeof(kop)); | ||
| 805 | + ecdsa = ecdsa_check(eckey); | ||
| 806 | + if (!ecdsa) { | ||
| 807 | + ECDSAerr(ECDSA_F_ECDSA_DO_SIGN, ERR_R_PASSED_NULL_PARAMETER); | ||
| 808 | + return NULL; | ||
| 809 | + } | ||
| 810 | + | ||
| 811 | + group = EC_KEY_get0_group(eckey); | ||
| 812 | + priv_key = EC_KEY_get0_private_key(eckey); | ||
| 813 | + | ||
| 814 | + if (!group || !priv_key) { | ||
| 815 | + ECDSAerr(ECDSA_F_ECDSA_DO_SIGN, ERR_R_PASSED_NULL_PARAMETER); | ||
| 816 | + return NULL; | ||
| 817 | + } | ||
| 818 | + | ||
| 819 | + if ((ctx = BN_CTX_new()) == NULL || (m = BN_new()) == NULL || | ||
| 820 | + (a = BN_new()) == NULL || (b = BN_new()) == NULL || | ||
| 821 | + (p = BN_new()) == NULL || (x = BN_new()) == NULL || | ||
| 822 | + (y = BN_new()) == NULL) { | ||
| 823 | + ECDSAerr(ECDSA_F_ECDSA_DO_SIGN, ERR_R_MALLOC_FAILURE); | ||
| 824 | + goto err; | ||
| 825 | + } | ||
| 826 | + | ||
| 827 | + order = &group->order; | ||
| 828 | + if (!order || BN_is_zero(order)) { | ||
| 829 | + ECDSAerr(ECDSA_F_ECDSA_DO_SIGN, ECDSA_R_MISSING_PARAMETERS); | ||
| 830 | + goto err; | ||
| 831 | + } | ||
| 832 | + | ||
| 833 | + i = BN_num_bits(order); | ||
| 834 | + /* Need to truncate digest if it is too long: first truncate whole | ||
| 835 | + bytes */ | ||
| 836 | + if (8 * dgst_len > i) | ||
| 837 | + dgst_len = (i + 7)/8; | ||
| 838 | + | ||
| 839 | + if (!BN_bin2bn(dgst, dgst_len, m)) { | ||
| 840 | + ECDSAerr(ECDSA_F_ECDSA_DO_SIGN, ERR_R_BN_LIB); | ||
| 841 | + goto err; | ||
| 842 | + } | ||
| 843 | + | ||
| 844 | + /* If still too long truncate remaining bits with a shift */ | ||
| 845 | + if ((8 * dgst_len > i) && !BN_rshift(m, m, 8 - (i & 0x7))) { | ||
| 846 | + ECDSAerr(ECDSA_F_ECDSA_DO_SIGN, ERR_R_BN_LIB); | ||
| 847 | + goto err; | ||
| 848 | + } | ||
| 849 | + | ||
| 850 | + /* copy the truncated bits into plain buffer */ | ||
| 851 | + if (spcf_bn2bin(m, &tmp_dgst, &dgst_len)) { | ||
| 852 | + fprintf(stderr, "%s:%d: OPENSSL_malloc failec\n", __FUNCTION__, __LINE__); | ||
| 853 | + goto err; | ||
| 854 | + } | ||
| 855 | + | ||
| 856 | + ret = ECDSA_SIG_new(); | ||
| 857 | + if (!ret) { | ||
| 858 | + ECDSAerr(ECDSA_F_ECDSA_DO_SIGN, ERR_R_BN_LIB); | ||
| 859 | + goto err; | ||
| 860 | + } | ||
| 861 | + | ||
| 862 | + /* check if this is prime or binary EC request */ | ||
| 863 | + if (EC_METHOD_get_field_type(EC_GROUP_method_of(group)) == NID_X9_62_prime_field) { | ||
| 864 | + ec_crv = EC_PRIME; | ||
| 865 | + /* get the generator point pair */ | ||
| 866 | + if (!EC_POINT_get_affine_coordinates_GFp (group, EC_GROUP_get0_generator(group), | ||
| 867 | + x, y,ctx)) { | ||
| 868 | + ECDSAerr(ECDSA_F_ECDSA_DO_SIGN, ERR_R_EC_LIB); | ||
| 869 | + goto err; | ||
| 870 | + } | ||
| 871 | + | ||
| 872 | + /* get the ECC curve parameters */ | ||
| 873 | + if (!EC_GROUP_get_curve_GFp(group, p, a, b , ctx)) { | ||
| 874 | + ECDSAerr(ECDSA_F_ECDSA_DO_SIGN, ERR_R_EC_LIB); | ||
| 875 | goto err; | ||
| 876 | } | ||
| 877 | } else if (EC_METHOD_get_field_type(EC_GROUP_method_of(group)) == NID_X9_62_characteristic_two_field) { | ||
| 878 | @@ -2195,63 +2700,581 @@ static int cryptodev_ecdsa_verify(const unsigned char *dgst, int dgst_len, | ||
| 879 | } | ||
| 880 | |||
| 881 | /** | ||
| 882 | - * Get the 2nd part of signature into a flat buffer with | ||
| 883 | - * appropriate padding | ||
| 884 | + * Get the 2nd part of signature into a flat buffer with | ||
| 885 | + * appropriate padding | ||
| 886 | + */ | ||
| 887 | + if (BN_num_bytes(sig->s) < r_len) | ||
| 888 | + d_len = r_len; | ||
| 889 | + | ||
| 890 | + if (spcf_bn2bin_ex(sig->s, &d, &d_len)) { | ||
| 891 | + ECDSAerr(ECDSA_F_ECDSA_DO_VERIFY, ERR_R_MALLOC_FAILURE); | ||
| 892 | + goto err; | ||
| 893 | + } | ||
| 894 | + | ||
| 895 | + /* memory for message representative */ | ||
| 896 | + f = malloc(r_len); | ||
| 897 | + if (!f) { | ||
| 898 | + ECDSAerr(ECDSA_F_ECDSA_DO_VERIFY, ERR_R_MALLOC_FAILURE); | ||
| 899 | + goto err; | ||
| 900 | + } | ||
| 901 | + | ||
| 902 | + /* Add padding, since SEC expects hash to of size r_len */ | ||
| 903 | + memset(f, 0, r_len-dgst_len); | ||
| 904 | + | ||
| 905 | + /* Skip leading bytes if dgst_len < r_len */ | ||
| 906 | + memcpy(f + r_len-dgst_len, tmp_dgst, dgst_len); | ||
| 907 | + dgst_len += r_len-dgst_len; | ||
| 908 | + kop.crk_op = CRK_DSA_VERIFY; | ||
| 909 | + /* inputs: dgst dsa->p dsa->q dsa->g dsa->priv_key */ | ||
| 910 | + kop.crk_param[0].crp_p = f; | ||
| 911 | + kop.crk_param[0].crp_nbits = dgst_len * 8; | ||
| 912 | + kop.crk_param[1].crp_p = q; | ||
| 913 | + kop.crk_param[1].crp_nbits = q_len * 8; | ||
| 914 | + kop.crk_param[2].crp_p = r; | ||
| 915 | + kop.crk_param[2].crp_nbits = r_len * 8; | ||
| 916 | + kop.crk_param[3].crp_p = g_xy; | ||
| 917 | + kop.crk_param[3].crp_nbits = g_len * 8; | ||
| 918 | + kop.crk_param[4].crp_p = w_xy; | ||
| 919 | + kop.crk_param[4].crp_nbits = pub_key_len * 8; | ||
| 920 | + kop.crk_param[5].crp_p = ab; | ||
| 921 | + kop.crk_param[5].crp_nbits = ab_len * 8; | ||
| 922 | + kop.crk_param[6].crp_p = c; | ||
| 923 | + kop.crk_param[6].crp_nbits = d_len * 8; | ||
| 924 | + kop.crk_param[7].crp_p = d; | ||
| 925 | + kop.crk_param[7].crp_nbits = d_len * 8; | ||
| 926 | + kop.crk_iparams = 8; | ||
| 927 | + | ||
| 928 | + if (cryptodev_asym(&kop, 0, NULL, 0, NULL) == 0) { | ||
| 929 | + /*OCF success value is 0, if not zero, change ret to fail*/ | ||
| 930 | + if(0 == kop.crk_status) | ||
| 931 | + ret = 1; | ||
| 932 | + } else { | ||
| 933 | + const ECDSA_METHOD *meth = ECDSA_OpenSSL(); | ||
| 934 | + | ||
| 935 | + ret = (meth->ecdsa_do_verify)(dgst, dgst_len, sig, eckey); | ||
| 936 | + } | ||
| 937 | + kop.crk_param[0].crp_p = NULL; | ||
| 938 | + zapparams(&kop); | ||
| 939 | + | ||
| 940 | +err: | ||
| 941 | + return ret; | ||
| 942 | +} | ||
| 943 | + | ||
| 944 | +static int cryptodev_ecdsa_do_sign_async( const unsigned char *dgst, | ||
| 945 | + int dgst_len, const BIGNUM *in_kinv, const BIGNUM *in_r, EC_KEY *eckey, | ||
| 946 | + ECDSA_SIG *sig, struct pkc_cookie_s *cookie) | ||
| 947 | +{ | ||
| 948 | + BIGNUM *m = NULL, *p = NULL, *a = NULL; | ||
| 949 | + BIGNUM *b = NULL, *x = NULL, *y = NULL; | ||
| 950 | + BN_CTX *ctx = NULL; | ||
| 951 | + ECDSA_SIG *sig_ret = NULL; | ||
| 952 | + ECDSA_DATA *ecdsa = NULL; | ||
| 953 | + unsigned char * q = NULL, *r = NULL, *ab = NULL, *g_xy = NULL; | ||
| 954 | + unsigned char * s = NULL, *f = NULL, *tmp_dgst = NULL; | ||
| 955 | + int i = 0, q_len = 0, priv_key_len = 0, r_len = 0; | ||
| 956 | + int g_len = 0, ab_len = 0, ret = 1; | ||
| 957 | + const BIGNUM *order = NULL, *priv_key=NULL; | ||
| 958 | + const EC_GROUP *group = NULL; | ||
| 959 | + struct crypt_kop *kop = malloc(sizeof(struct crypt_kop)); | ||
| 960 | + ec_curve_t ec_crv = EC_PRIME; | ||
| 961 | + | ||
| 962 | + if (!(sig->r = BN_new()) || !kop) | ||
| 963 | + goto err; | ||
| 964 | + if ((sig->s = BN_new()) == NULL) { | ||
| 965 | + BN_free(r); | ||
| 966 | + goto err; | ||
| 967 | + } | ||
| 968 | + | ||
| 969 | + memset(kop, 0, sizeof(struct crypt_kop)); | ||
| 970 | + ecdsa = ecdsa_check(eckey); | ||
| 971 | + if (!ecdsa) { | ||
| 972 | + ECDSAerr(ECDSA_F_ECDSA_DO_SIGN, ERR_R_PASSED_NULL_PARAMETER); | ||
| 973 | + goto err; | ||
| 974 | + } | ||
| 975 | + | ||
| 976 | + group = EC_KEY_get0_group(eckey); | ||
| 977 | + priv_key = EC_KEY_get0_private_key(eckey); | ||
| 978 | + | ||
| 979 | + if (!group || !priv_key) { | ||
| 980 | + ECDSAerr(ECDSA_F_ECDSA_DO_SIGN, ERR_R_PASSED_NULL_PARAMETER); | ||
| 981 | + goto err; | ||
| 982 | + } | ||
| 983 | + | ||
| 984 | + if ((ctx = BN_CTX_new()) == NULL || (m = BN_new()) == NULL || | ||
| 985 | + (a = BN_new()) == NULL || (b = BN_new()) == NULL || | ||
| 986 | + (p = BN_new()) == NULL || (x = BN_new()) == NULL || | ||
| 987 | + (y = BN_new()) == NULL) { | ||
| 988 | + ECDSAerr(ECDSA_F_ECDSA_DO_SIGN, ERR_R_MALLOC_FAILURE); | ||
| 989 | + goto err; | ||
| 990 | + } | ||
| 991 | + | ||
| 992 | + order = &group->order; | ||
| 993 | + if (!order || BN_is_zero(order)) { | ||
| 994 | + ECDSAerr(ECDSA_F_ECDSA_DO_SIGN, ECDSA_R_MISSING_PARAMETERS); | ||
| 995 | + goto err; | ||
| 996 | + } | ||
| 997 | + | ||
| 998 | + i = BN_num_bits(order); | ||
| 999 | + /* Need to truncate digest if it is too long: first truncate whole | ||
| 1000 | + bytes */ | ||
| 1001 | + if (8 * dgst_len > i) | ||
| 1002 | + dgst_len = (i + 7)/8; | ||
| 1003 | + | ||
| 1004 | + if (!BN_bin2bn(dgst, dgst_len, m)) { | ||
| 1005 | + ECDSAerr(ECDSA_F_ECDSA_DO_SIGN, ERR_R_BN_LIB); | ||
| 1006 | + goto err; | ||
| 1007 | + } | ||
| 1008 | + | ||
| 1009 | + /* If still too long truncate remaining bits with a shift */ | ||
| 1010 | + if ((8 * dgst_len > i) && !BN_rshift(m, m, 8 - (i & 0x7))) { | ||
| 1011 | + ECDSAerr(ECDSA_F_ECDSA_DO_SIGN, ERR_R_BN_LIB); | ||
| 1012 | + goto err; | ||
| 1013 | + } | ||
| 1014 | + | ||
| 1015 | + /* copy the truncated bits into plain buffer */ | ||
| 1016 | + if (spcf_bn2bin(m, &tmp_dgst, &dgst_len)) { | ||
| 1017 | + fprintf(stderr, "%s:%d: OPENSSL_malloc failec\n", __FUNCTION__, __LINE__); | ||
| 1018 | + goto err; | ||
| 1019 | + } | ||
| 1020 | + | ||
| 1021 | + /* check if this is prime or binary EC request */ | ||
| 1022 | + if (EC_METHOD_get_field_type(EC_GROUP_method_of(group)) | ||
| 1023 | + == NID_X9_62_prime_field) { | ||
| 1024 | + ec_crv = EC_PRIME; | ||
| 1025 | + /* get the generator point pair */ | ||
| 1026 | + if (!EC_POINT_get_affine_coordinates_GFp (group, | ||
| 1027 | + EC_GROUP_get0_generator(group), x, y,ctx)) { | ||
| 1028 | + ECDSAerr(ECDSA_F_ECDSA_DO_SIGN, ERR_R_EC_LIB); | ||
| 1029 | + goto err; | ||
| 1030 | + } | ||
| 1031 | + | ||
| 1032 | + /* get the ECC curve parameters */ | ||
| 1033 | + if (!EC_GROUP_get_curve_GFp(group, p, a, b , ctx)) { | ||
| 1034 | + ECDSAerr(ECDSA_F_ECDSA_DO_SIGN, ERR_R_EC_LIB); | ||
| 1035 | + goto err; | ||
| 1036 | + } | ||
| 1037 | + } else if (EC_METHOD_get_field_type(EC_GROUP_method_of(group)) == NID_X9_62_characteristic_two_field) { | ||
| 1038 | + ec_crv = EC_BINARY; | ||
| 1039 | + /* get the ECC curve parameters */ | ||
| 1040 | + if (!EC_GROUP_get_curve_GF2m(group, p, a, b , ctx)) { | ||
| 1041 | + ECDSAerr(ECDSA_F_ECDSA_DO_SIGN, ERR_R_EC_LIB); | ||
| 1042 | + goto err; | ||
| 1043 | + } | ||
| 1044 | + | ||
| 1045 | + /* get the generator point pair */ | ||
| 1046 | + if (!EC_POINT_get_affine_coordinates_GF2m(group, | ||
| 1047 | + EC_GROUP_get0_generator(group), x, y,ctx)) { | ||
| 1048 | + ECDSAerr(ECDSA_F_ECDSA_DO_SIGN, ERR_R_EC_LIB); | ||
| 1049 | + goto err; | ||
| 1050 | + } | ||
| 1051 | + } else { | ||
| 1052 | + printf("Unsupported Curve\n"); | ||
| 1053 | + ECDSAerr(ECDSA_F_ECDSA_DO_SIGN, ERR_R_EC_LIB); | ||
| 1054 | + goto err; | ||
| 1055 | + } | ||
| 1056 | + | ||
| 1057 | + if (spcf_bn2bin(order, &r, &r_len)) { | ||
| 1058 | + ECDSAerr(ECDSA_F_ECDSA_DO_SIGN, ERR_R_MALLOC_FAILURE); | ||
| 1059 | + goto err; | ||
| 1060 | + } | ||
| 1061 | + | ||
| 1062 | + if (spcf_bn2bin(p, &q, &q_len)) { | ||
| 1063 | + ECDSAerr(ECDSA_F_ECDSA_DO_SIGN, ERR_R_MALLOC_FAILURE); | ||
| 1064 | + goto err; | ||
| 1065 | + } | ||
| 1066 | + | ||
| 1067 | + priv_key_len = r_len; | ||
| 1068 | + | ||
| 1069 | + /** | ||
| 1070 | + * If BN_num_bytes of priv_key returns less then r_len then | ||
| 1071 | + * add padding bytes before the key | ||
| 1072 | + */ | ||
| 1073 | + if (spcf_bn2bin_ex(priv_key, &s, &priv_key_len)) { | ||
| 1074 | + ECDSAerr(ECDSA_F_ECDSA_DO_SIGN, ERR_R_MALLOC_FAILURE); | ||
| 1075 | + goto err; | ||
| 1076 | + } | ||
| 1077 | + | ||
| 1078 | + /* Generation of ECC curve parameters */ | ||
| 1079 | + ab_len = 2*q_len; | ||
| 1080 | + ab = eng_copy_curve_points(a, b, ab_len, q_len); | ||
| 1081 | + if (!ab) { | ||
| 1082 | + ECDSAerr(ECDSA_F_ECDSA_DO_SIGN, ERR_R_MALLOC_FAILURE); | ||
| 1083 | + goto err; | ||
| 1084 | + } | ||
| 1085 | + | ||
| 1086 | + if (ec_crv == EC_BINARY) { | ||
| 1087 | + if (eng_ec_get_cparam(EC_GROUP_get_curve_name(group), ab+q_len, q_len)) | ||
| 1088 | + { | ||
| 1089 | + unsigned char *c_temp = NULL; | ||
| 1090 | + int c_temp_len = q_len; | ||
| 1091 | + if (eng_ec_compute_cparam(b, p, &c_temp, &c_temp_len)) | ||
| 1092 | + memcpy(ab+q_len, c_temp, q_len); | ||
| 1093 | + else | ||
| 1094 | + goto err; | ||
| 1095 | + } | ||
| 1096 | + kop->curve_type = ECC_BINARY; | ||
| 1097 | + } | ||
| 1098 | + | ||
| 1099 | + /* Calculation of Generator point */ | ||
| 1100 | + g_len = 2*q_len; | ||
| 1101 | + g_xy = eng_copy_curve_points(x, y, g_len, q_len); | ||
| 1102 | + if (!g_xy) { | ||
| 1103 | + ECDSAerr(ECDSA_F_ECDSA_DO_SIGN, ERR_R_MALLOC_FAILURE); | ||
| 1104 | + goto err; | ||
| 1105 | + } | ||
| 1106 | + | ||
| 1107 | + /* memory for message representative */ | ||
| 1108 | + f = malloc(r_len); | ||
| 1109 | + if (!f) { | ||
| 1110 | + ECDSAerr(ECDSA_F_ECDSA_DO_SIGN, ERR_R_MALLOC_FAILURE); | ||
| 1111 | + goto err; | ||
| 1112 | + } | ||
| 1113 | + | ||
| 1114 | + /* Add padding, since SEC expects hash to of size r_len */ | ||
| 1115 | + memset(f, 0, r_len - dgst_len); | ||
| 1116 | + | ||
| 1117 | + /* Skip leading bytes if dgst_len < r_len */ | ||
| 1118 | + memcpy(f + r_len - dgst_len, tmp_dgst, dgst_len); | ||
| 1119 | + | ||
| 1120 | + dgst_len += r_len - dgst_len; | ||
| 1121 | + | ||
| 1122 | + kop->crk_op = CRK_DSA_SIGN; | ||
| 1123 | + /* inputs: dgst dsa->p dsa->q dsa->g dsa->priv_key */ | ||
| 1124 | + kop->crk_param[0].crp_p = f; | ||
| 1125 | + kop->crk_param[0].crp_nbits = dgst_len * 8; | ||
| 1126 | + kop->crk_param[1].crp_p = q; | ||
| 1127 | + kop->crk_param[1].crp_nbits = q_len * 8; | ||
| 1128 | + kop->crk_param[2].crp_p = r; | ||
| 1129 | + kop->crk_param[2].crp_nbits = r_len * 8; | ||
| 1130 | + kop->crk_param[3].crp_p = g_xy; | ||
| 1131 | + kop->crk_param[3].crp_nbits = g_len * 8; | ||
| 1132 | + kop->crk_param[4].crp_p = s; | ||
| 1133 | + kop->crk_param[4].crp_nbits = priv_key_len * 8; | ||
| 1134 | + kop->crk_param[5].crp_p = ab; | ||
| 1135 | + kop->crk_param[5].crp_nbits = ab_len * 8; | ||
| 1136 | + kop->crk_iparams = 6; | ||
| 1137 | + kop->cookie = cookie; | ||
| 1138 | + | ||
| 1139 | + if (cryptodev_asym_async(kop, r_len, sig->r , r_len, sig->s)) | ||
| 1140 | + goto err; | ||
| 1141 | + | ||
| 1142 | + return ret; | ||
| 1143 | +err: | ||
| 1144 | + { | ||
| 1145 | + const ECDSA_METHOD *meth = ECDSA_OpenSSL(); | ||
| 1146 | + BN_free(sig->r); | ||
| 1147 | + BN_free(sig->s); | ||
| 1148 | + if (kop) | ||
| 1149 | + free(kop); | ||
| 1150 | + sig_ret = (meth->ecdsa_do_sign)(dgst, dgst_len, in_kinv, in_r, eckey); | ||
| 1151 | + sig->r = sig_ret->r; | ||
| 1152 | + sig->s = sig_ret->s; | ||
| 1153 | + cookie->pkc_callback(cookie, 0); | ||
| 1154 | + } | ||
| 1155 | + return ret; | ||
| 1156 | +} | ||
| 1157 | + | ||
| 1158 | +static int cryptodev_ecdsa_verify_async(const unsigned char *dgst, int dgst_len, | ||
| 1159 | + const ECDSA_SIG *sig, EC_KEY *eckey, struct pkc_cookie_s *cookie) | ||
| 1160 | +{ | ||
| 1161 | + BIGNUM *m = NULL, *p = NULL, *a = NULL, *b = NULL; | ||
| 1162 | + BIGNUM *x = NULL, *y = NULL, *w_x = NULL, *w_y = NULL; | ||
| 1163 | + BN_CTX *ctx = NULL; | ||
| 1164 | + ECDSA_DATA *ecdsa = NULL; | ||
| 1165 | + unsigned char *q = NULL, *r = NULL, *ab = NULL, *g_xy = NULL, *w_xy = NULL; | ||
| 1166 | + unsigned char *c = NULL, *d = NULL, *f = NULL, *tmp_dgst = NULL; | ||
| 1167 | + int i = 0, q_len = 0, pub_key_len = 0, r_len = 0, c_len = 0, g_len = 0; | ||
| 1168 | + int d_len = 0, ab_len = 0, ret = 1; | ||
| 1169 | + const EC_POINT *pub_key = NULL; | ||
| 1170 | + const BIGNUM *order = NULL; | ||
| 1171 | + const EC_GROUP *group=NULL; | ||
| 1172 | + ec_curve_t ec_crv = EC_PRIME; | ||
| 1173 | + struct crypt_kop *kop = malloc(sizeof(struct crypt_kop)); | ||
| 1174 | + | ||
| 1175 | + if (!kop) | ||
| 1176 | + goto err; | ||
| 1177 | + | ||
| 1178 | + memset(kop, 0, sizeof(struct crypt_kop)); | ||
| 1179 | + ecdsa = ecdsa_check(eckey); | ||
| 1180 | + if (!ecdsa) { | ||
| 1181 | + ECDSAerr(ECDSA_F_ECDSA_DO_VERIFY, ERR_R_PASSED_NULL_PARAMETER); | ||
| 1182 | + goto err; | ||
| 1183 | + } | ||
| 1184 | + | ||
| 1185 | + group = EC_KEY_get0_group(eckey); | ||
| 1186 | + pub_key = EC_KEY_get0_public_key(eckey); | ||
| 1187 | + | ||
| 1188 | + if (!group || !pub_key) { | ||
| 1189 | + ECDSAerr(ECDSA_F_ECDSA_DO_VERIFY, ERR_R_PASSED_NULL_PARAMETER); | ||
| 1190 | + goto err; | ||
| 1191 | + } | ||
| 1192 | + | ||
| 1193 | + if ((ctx = BN_CTX_new()) == NULL || (m = BN_new()) == NULL || | ||
| 1194 | + (a = BN_new()) == NULL || (b = BN_new()) == NULL || | ||
| 1195 | + (p = BN_new()) == NULL || (x = BN_new()) == NULL || | ||
| 1196 | + (y = BN_new()) == NULL || (w_x = BN_new()) == NULL || | ||
| 1197 | + (w_y = BN_new()) == NULL) { | ||
| 1198 | + ECDSAerr(ECDSA_F_ECDSA_DO_VERIFY, ERR_R_MALLOC_FAILURE); | ||
| 1199 | + goto err; | ||
| 1200 | + } | ||
| 1201 | + | ||
| 1202 | + order = &group->order; | ||
| 1203 | + if (!order || BN_is_zero(order)) { | ||
| 1204 | + ECDSAerr(ECDSA_F_ECDSA_DO_VERIFY, ECDSA_R_MISSING_PARAMETERS); | ||
| 1205 | + goto err; | ||
| 1206 | + } | ||
| 1207 | + | ||
| 1208 | + i = BN_num_bits(order); | ||
| 1209 | + /* Need to truncate digest if it is too long: first truncate whole | ||
| 1210 | + * bytes */ | ||
| 1211 | + if (8 * dgst_len > i) | ||
| 1212 | + dgst_len = (i + 7)/8; | ||
| 1213 | + | ||
| 1214 | + if (!BN_bin2bn(dgst, dgst_len, m)) { | ||
| 1215 | + ECDSAerr(ECDSA_F_ECDSA_DO_VERIFY, ERR_R_BN_LIB); | ||
| 1216 | + goto err; | ||
| 1217 | + } | ||
| 1218 | + | ||
| 1219 | + /* If still too long truncate remaining bits with a shift */ | ||
| 1220 | + if ((8 * dgst_len > i) && !BN_rshift(m, m, 8 - (i & 0x7))) { | ||
| 1221 | + ECDSAerr(ECDSA_F_ECDSA_DO_VERIFY, ERR_R_BN_LIB); | ||
| 1222 | + goto err; | ||
| 1223 | + } | ||
| 1224 | + /* copy the truncated bits into plain buffer */ | ||
| 1225 | + if (spcf_bn2bin(m, &tmp_dgst, &dgst_len)) { | ||
| 1226 | + ECDSAerr(ECDSA_F_ECDSA_DO_VERIFY, ERR_R_MALLOC_FAILURE); | ||
| 1227 | + goto err; | ||
| 1228 | + } | ||
| 1229 | + | ||
| 1230 | + /* check if this is prime or binary EC request */ | ||
| 1231 | + if (EC_METHOD_get_field_type(EC_GROUP_method_of(group)) == NID_X9_62_prime_field) { | ||
| 1232 | + ec_crv = EC_PRIME; | ||
| 1233 | + | ||
| 1234 | + /* get the generator point pair */ | ||
| 1235 | + if (!EC_POINT_get_affine_coordinates_GFp (group, | ||
| 1236 | + EC_GROUP_get0_generator(group), x, y,ctx)) { | ||
| 1237 | + ECDSAerr(ECDSA_F_ECDSA_DO_VERIFY, ERR_R_EC_LIB); | ||
| 1238 | + goto err; | ||
| 1239 | + } | ||
| 1240 | + | ||
| 1241 | + /* get the public key pair for prime curve */ | ||
| 1242 | + if (!EC_POINT_get_affine_coordinates_GFp (group, | ||
| 1243 | + pub_key, w_x, w_y,ctx)) { | ||
| 1244 | + ECDSAerr(ECDSA_F_ECDSA_DO_VERIFY, ERR_R_EC_LIB); | ||
| 1245 | + goto err; | ||
| 1246 | + } | ||
| 1247 | + | ||
| 1248 | + /* get the ECC curve parameters */ | ||
| 1249 | + if (!EC_GROUP_get_curve_GFp(group, p, a, b, ctx)) { | ||
| 1250 | + ECDSAerr(ECDSA_F_ECDSA_DO_VERIFY, ERR_R_EC_LIB); | ||
| 1251 | + goto err; | ||
| 1252 | + } | ||
| 1253 | + } else if (EC_METHOD_get_field_type(EC_GROUP_method_of(group)) == NID_X9_62_characteristic_two_field){ | ||
| 1254 | + ec_crv = EC_BINARY; | ||
| 1255 | + /* get the ECC curve parameters */ | ||
| 1256 | + if (!EC_GROUP_get_curve_GF2m(group, p, a, b , ctx)) { | ||
| 1257 | + ECDSAerr(ECDSA_F_ECDSA_DO_VERIFY, ERR_R_EC_LIB); | ||
| 1258 | + goto err; | ||
| 1259 | + } | ||
| 1260 | + | ||
| 1261 | + /* get the generator point pair */ | ||
| 1262 | + if (!EC_POINT_get_affine_coordinates_GF2m(group, | ||
| 1263 | + EC_GROUP_get0_generator(group),x, y,ctx)) { | ||
| 1264 | + ECDSAerr(ECDSA_F_ECDSA_DO_VERIFY, ERR_R_EC_LIB); | ||
| 1265 | + goto err; | ||
| 1266 | + } | ||
| 1267 | + | ||
| 1268 | + /* get the public key pair for binary curve */ | ||
| 1269 | + if (!EC_POINT_get_affine_coordinates_GF2m(group, | ||
| 1270 | + pub_key, w_x, w_y,ctx)) { | ||
| 1271 | + ECDSAerr(ECDSA_F_ECDSA_DO_VERIFY, ERR_R_EC_LIB); | ||
| 1272 | + goto err; | ||
| 1273 | + } | ||
| 1274 | + }else { | ||
| 1275 | + printf("Unsupported Curve\n"); | ||
| 1276 | + ECDSAerr(ECDSA_F_ECDSA_DO_VERIFY, ERR_R_EC_LIB); | ||
| 1277 | + goto err; | ||
| 1278 | + } | ||
| 1279 | + | ||
| 1280 | + /* Get the order of the subgroup of private keys */ | ||
| 1281 | + if (spcf_bn2bin((BIGNUM*)order, &r, &r_len)) { | ||
| 1282 | + ECDSAerr(ECDSA_F_ECDSA_DO_VERIFY, ERR_R_MALLOC_FAILURE); | ||
| 1283 | + goto err; | ||
| 1284 | + } | ||
| 1285 | + | ||
| 1286 | + /* Get the irreducible polynomial that creates the field */ | ||
| 1287 | + if (spcf_bn2bin(p, &q, &q_len)) { | ||
| 1288 | + ECDSAerr(ECDSA_F_ECDSA_DO_VERIFY, ERR_R_MALLOC_FAILURE); | ||
| 1289 | + goto err; | ||
| 1290 | + } | ||
| 1291 | + | ||
| 1292 | + /* Get the public key into a flat buffer with appropriate padding */ | ||
| 1293 | + pub_key_len = 2 * q_len; | ||
| 1294 | + | ||
| 1295 | + w_xy = eng_copy_curve_points (w_x, w_y, pub_key_len, q_len); | ||
| 1296 | + if (!w_xy) { | ||
| 1297 | + ECDSAerr(ECDSA_F_ECDSA_DO_VERIFY, ERR_R_MALLOC_FAILURE); | ||
| 1298 | + goto err; | ||
| 1299 | + } | ||
| 1300 | + | ||
| 1301 | + /* Generation of ECC curve parameters */ | ||
| 1302 | + ab_len = 2*q_len; | ||
| 1303 | + | ||
| 1304 | + ab = eng_copy_curve_points (a, b, ab_len, q_len); | ||
| 1305 | + if (!ab) { | ||
| 1306 | + ECDSAerr(ECDSA_F_ECDSA_DO_VERIFY, ERR_R_MALLOC_FAILURE); | ||
| 1307 | + goto err; | ||
| 1308 | + } | ||
| 1309 | + | ||
| 1310 | + if (ec_crv == EC_BINARY) { | ||
| 1311 | + /* copy b' i.e c(b), instead of only b */ | ||
| 1312 | + eng_ec_get_cparam (EC_GROUP_get_curve_name(group), | ||
| 1313 | + ab+q_len, q_len); | ||
| 1314 | + kop->curve_type = ECC_BINARY; | ||
| 1315 | + } | ||
| 1316 | + | ||
| 1317 | + /* Calculation of Generator point */ | ||
| 1318 | + g_len = 2 * q_len; | ||
| 1319 | + | ||
| 1320 | + g_xy = eng_copy_curve_points (x, y, g_len, q_len); | ||
| 1321 | + if (!g_xy) { | ||
| 1322 | + ECDSAerr(ECDSA_F_ECDSA_DO_VERIFY, ERR_R_MALLOC_FAILURE); | ||
| 1323 | + goto err; | ||
| 1324 | + } | ||
| 1325 | + | ||
| 1326 | + /** | ||
| 1327 | + * Get the 1st part of signature into a flat buffer with | ||
| 1328 | + * appropriate padding | ||
| 1329 | + */ | ||
| 1330 | + if (BN_num_bytes(sig->r) < r_len) | ||
| 1331 | + c_len = r_len; | ||
| 1332 | + | ||
| 1333 | + if (spcf_bn2bin_ex(sig->r, &c, &c_len)) { | ||
| 1334 | + ECDSAerr(ECDSA_F_ECDSA_DO_VERIFY, ERR_R_MALLOC_FAILURE); | ||
| 1335 | + goto err; | ||
| 1336 | + } | ||
| 1337 | + | ||
| 1338 | + /** | ||
| 1339 | + * Get the 2nd part of signature into a flat buffer with | ||
| 1340 | + * appropriate padding | ||
| 1341 | + */ | ||
| 1342 | + if (BN_num_bytes(sig->s) < r_len) | ||
| 1343 | + d_len = r_len; | ||
| 1344 | + | ||
| 1345 | + if (spcf_bn2bin_ex(sig->s, &d, &d_len)) { | ||
| 1346 | + ECDSAerr(ECDSA_F_ECDSA_DO_VERIFY, ERR_R_MALLOC_FAILURE); | ||
| 1347 | + goto err; | ||
| 1348 | + } | ||
| 1349 | + | ||
| 1350 | + /* memory for message representative */ | ||
| 1351 | + f = malloc(r_len); | ||
| 1352 | + if (!f) { | ||
| 1353 | + ECDSAerr(ECDSA_F_ECDSA_DO_VERIFY, ERR_R_MALLOC_FAILURE); | ||
| 1354 | + goto err; | ||
| 1355 | + } | ||
| 1356 | + | ||
| 1357 | + /* Add padding, since SEC expects hash to of size r_len */ | ||
| 1358 | + memset(f, 0, r_len-dgst_len); | ||
| 1359 | + | ||
| 1360 | + /* Skip leading bytes if dgst_len < r_len */ | ||
| 1361 | + memcpy(f + r_len-dgst_len, tmp_dgst, dgst_len); | ||
| 1362 | + | ||
| 1363 | + dgst_len += r_len-dgst_len; | ||
| 1364 | + | ||
| 1365 | + kop->crk_op = CRK_DSA_VERIFY; | ||
| 1366 | + /* inputs: dgst dsa->p dsa->q dsa->g dsa->priv_key */ | ||
| 1367 | + kop->crk_param[0].crp_p = f; | ||
| 1368 | + kop->crk_param[0].crp_nbits = dgst_len * 8; | ||
| 1369 | + kop->crk_param[1].crp_p = q; | ||
| 1370 | + kop->crk_param[1].crp_nbits = q_len * 8; | ||
| 1371 | + kop->crk_param[2].crp_p = r; | ||
| 1372 | + kop->crk_param[2].crp_nbits = r_len * 8; | ||
| 1373 | + kop->crk_param[3].crp_p = g_xy; | ||
| 1374 | + kop->crk_param[3].crp_nbits = g_len * 8; | ||
| 1375 | + kop->crk_param[4].crp_p = w_xy; | ||
| 1376 | + kop->crk_param[4].crp_nbits = pub_key_len * 8; | ||
| 1377 | + kop->crk_param[5].crp_p = ab; | ||
| 1378 | + kop->crk_param[5].crp_nbits = ab_len * 8; | ||
| 1379 | + kop->crk_param[6].crp_p = c; | ||
| 1380 | + kop->crk_param[6].crp_nbits = d_len * 8; | ||
| 1381 | + kop->crk_param[7].crp_p = d; | ||
| 1382 | + kop->crk_param[7].crp_nbits = d_len * 8; | ||
| 1383 | + kop->crk_iparams = 8; | ||
| 1384 | + kop->cookie = cookie; | ||
| 1385 | + | ||
| 1386 | + if (cryptodev_asym_async(kop, 0, NULL, 0, NULL)) | ||
| 1387 | + goto err; | ||
| 1388 | + | ||
| 1389 | + return ret; | ||
| 1390 | +err: | ||
| 1391 | + { | ||
| 1392 | + const ECDSA_METHOD *meth = ECDSA_OpenSSL(); | ||
| 1393 | + | ||
| 1394 | + if (kop) | ||
| 1395 | + free(kop); | ||
| 1396 | + ret = (meth->ecdsa_do_verify)(dgst, dgst_len, sig, eckey); | ||
| 1397 | + cookie->pkc_callback(cookie, 0); | ||
| 1398 | + } | ||
| 1399 | + | ||
| 1400 | + return ret; | ||
| 1401 | +} | ||
| 1402 | + | ||
| 1403 | +/* Cryptodev DH Key Gen routine */ | ||
| 1404 | +static int cryptodev_dh_keygen_async(DH *dh, struct pkc_cookie_s *cookie) | ||
| 1405 | +{ | ||
| 1406 | + struct crypt_kop *kop = malloc(sizeof(struct crypt_kop)); | ||
| 1407 | + int ret = 1, g_len; | ||
| 1408 | + unsigned char *g = NULL; | ||
| 1409 | + | ||
| 1410 | + if (!kop) | ||
| 1411 | + goto sw_try; | ||
| 1412 | + | ||
| 1413 | + if (dh->priv_key == NULL) { | ||
| 1414 | + if ((dh->priv_key=BN_new()) == NULL) | ||
| 1415 | + goto sw_try; | ||
| 1416 | + } | ||
| 1417 | + | ||
| 1418 | + if (dh->pub_key == NULL) { | ||
| 1419 | + if ((dh->pub_key=BN_new()) == NULL) | ||
| 1420 | + goto sw_try; | ||
| 1421 | + } | ||
| 1422 | + | ||
| 1423 | + g_len = BN_num_bytes(dh->p); | ||
| 1424 | + /** | ||
| 1425 | + * Get generator into a plain buffer. If length is less than | ||
| 1426 | + * q_len then add leading padding bytes. | ||
| 1427 | */ | ||
| 1428 | - if (BN_num_bytes(sig->s) < r_len) | ||
| 1429 | - d_len = r_len; | ||
| 1430 | - | ||
| 1431 | - if (spcf_bn2bin_ex(sig->s, &d, &d_len)) { | ||
| 1432 | - ECDSAerr(ECDSA_F_ECDSA_DO_VERIFY, ERR_R_MALLOC_FAILURE); | ||
| 1433 | - goto err; | ||
| 1434 | - } | ||
| 1435 | - | ||
| 1436 | - /* memory for message representative */ | ||
| 1437 | - f = malloc(r_len); | ||
| 1438 | - if (!f) { | ||
| 1439 | - ECDSAerr(ECDSA_F_ECDSA_DO_VERIFY, ERR_R_MALLOC_FAILURE); | ||
| 1440 | - goto err; | ||
| 1441 | + if (spcf_bn2bin_ex(dh->g, &g, &g_len)) { | ||
| 1442 | + DSAerr(DH_F_DH_GENERATE_KEY, ERR_R_MALLOC_FAILURE); | ||
| 1443 | + goto sw_try; | ||
| 1444 | } | ||
| 1445 | |||
| 1446 | - /* Add padding, since SEC expects hash to of size r_len */ | ||
| 1447 | - memset(f, 0, r_len-dgst_len); | ||
| 1448 | + memset(kop, 0, sizeof(struct crypt_kop)); | ||
| 1449 | + kop->crk_op = CRK_DH_GENERATE_KEY; | ||
| 1450 | + if (bn2crparam(dh->p, &kop->crk_param[0])) | ||
| 1451 | + goto sw_try; | ||
| 1452 | + if (bn2crparam(dh->q, &kop->crk_param[1])) | ||
| 1453 | + goto sw_try; | ||
| 1454 | + kop->crk_param[2].crp_p = g; | ||
| 1455 | + kop->crk_param[2].crp_nbits = g_len * 8; | ||
| 1456 | + kop->crk_iparams = 3; | ||
| 1457 | + kop->cookie = cookie; | ||
| 1458 | |||
| 1459 | - /* Skip leading bytes if dgst_len < r_len */ | ||
| 1460 | - memcpy(f + r_len-dgst_len, tmp_dgst, dgst_len); | ||
| 1461 | - dgst_len += r_len-dgst_len; | ||
| 1462 | - kop.crk_op = CRK_DSA_VERIFY; | ||
| 1463 | - /* inputs: dgst dsa->p dsa->q dsa->g dsa->priv_key */ | ||
| 1464 | - kop.crk_param[0].crp_p = f; | ||
| 1465 | - kop.crk_param[0].crp_nbits = dgst_len * 8; | ||
| 1466 | - kop.crk_param[1].crp_p = q; | ||
| 1467 | - kop.crk_param[1].crp_nbits = q_len * 8; | ||
| 1468 | - kop.crk_param[2].crp_p = r; | ||
| 1469 | - kop.crk_param[2].crp_nbits = r_len * 8; | ||
| 1470 | - kop.crk_param[3].crp_p = g_xy; | ||
| 1471 | - kop.crk_param[3].crp_nbits = g_len * 8; | ||
| 1472 | - kop.crk_param[4].crp_p = w_xy; | ||
| 1473 | - kop.crk_param[4].crp_nbits = pub_key_len * 8; | ||
| 1474 | - kop.crk_param[5].crp_p = ab; | ||
| 1475 | - kop.crk_param[5].crp_nbits = ab_len * 8; | ||
| 1476 | - kop.crk_param[6].crp_p = c; | ||
| 1477 | - kop.crk_param[6].crp_nbits = d_len * 8; | ||
| 1478 | - kop.crk_param[7].crp_p = d; | ||
| 1479 | - kop.crk_param[7].crp_nbits = d_len * 8; | ||
| 1480 | - kop.crk_iparams = 8; | ||
| 1481 | + /* pub_key is or prime length while priv key is of length of order */ | ||
| 1482 | + if (cryptodev_asym_async(kop, BN_num_bytes(dh->p), dh->pub_key, | ||
| 1483 | + BN_num_bytes(dh->q), dh->priv_key)) | ||
| 1484 | + goto sw_try; | ||
| 1485 | |||
| 1486 | - if (cryptodev_asym(&kop, 0, NULL, 0, NULL) == 0) { | ||
| 1487 | - /*OCF success value is 0, if not zero, change ret to fail*/ | ||
| 1488 | - if(0 == kop.crk_status) | ||
| 1489 | - ret = 1; | ||
| 1490 | - } else { | ||
| 1491 | - const ECDSA_METHOD *meth = ECDSA_OpenSSL(); | ||
| 1492 | + return ret; | ||
| 1493 | +sw_try: | ||
| 1494 | + { | ||
| 1495 | + const DH_METHOD *meth = DH_OpenSSL(); | ||
| 1496 | |||
| 1497 | - ret = (meth->ecdsa_do_verify)(dgst, dgst_len, sig, eckey); | ||
| 1498 | + if (kop) | ||
| 1499 | + free(kop); | ||
| 1500 | + ret = (meth->generate_key)(dh); | ||
| 1501 | + cookie->pkc_callback(cookie, 0); | ||
| 1502 | } | ||
| 1503 | - kop.crk_param[0].crp_p = NULL; | ||
| 1504 | - zapparams(&kop); | ||
| 1505 | - | ||
| 1506 | -err: | ||
| 1507 | return ret; | ||
| 1508 | } | ||
| 1509 | |||
| 1510 | @@ -2360,6 +3383,54 @@ sw_try: | ||
| 1511 | return (dhret); | ||
| 1512 | } | ||
| 1513 | |||
| 1514 | +/* Return Length if successful and 0 on failure */ | ||
| 1515 | +static int | ||
| 1516 | +cryptodev_dh_compute_key_async(unsigned char *key, const BIGNUM *pub_key, | ||
| 1517 | + DH *dh, struct pkc_cookie_s *cookie) | ||
| 1518 | +{ | ||
| 1519 | + struct crypt_kop *kop = malloc(sizeof(struct crypt_kop)); | ||
| 1520 | + int ret = 1; | ||
| 1521 | + int fd, p_len; | ||
| 1522 | + unsigned char *padded_pub_key = NULL, *p = NULL; | ||
| 1523 | + | ||
| 1524 | + fd = *(int *)cookie->eng_handle; | ||
| 1525 | + | ||
| 1526 | + memset(kop, 0, sizeof(struct crypt_kop)); | ||
| 1527 | + kop->crk_op = CRK_DH_COMPUTE_KEY; | ||
| 1528 | + /* inputs: dh->priv_key pub_key dh->p key */ | ||
| 1529 | + spcf_bn2bin(dh->p, &p, &p_len); | ||
| 1530 | + spcf_bn2bin_ex(pub_key, &padded_pub_key, &p_len); | ||
| 1531 | + | ||
| 1532 | + if (bn2crparam(dh->priv_key, &kop->crk_param[0])) | ||
| 1533 | + goto err; | ||
| 1534 | + kop->crk_param[1].crp_p = padded_pub_key; | ||
| 1535 | + kop->crk_param[1].crp_nbits = p_len * 8; | ||
| 1536 | + kop->crk_param[2].crp_p = p; | ||
| 1537 | + kop->crk_param[2].crp_nbits = p_len * 8; | ||
| 1538 | + kop->crk_iparams = 3; | ||
| 1539 | + | ||
| 1540 | + kop->cookie = cookie; | ||
| 1541 | + kop->crk_param[3].crp_p = (void*) key; | ||
| 1542 | + kop->crk_param[3].crp_nbits = p_len * 8; | ||
| 1543 | + kop->crk_oparams = 1; | ||
| 1544 | + | ||
| 1545 | + if (cryptodev_asym_async(kop, 0, NULL, 0, NULL)) | ||
| 1546 | + goto err; | ||
| 1547 | + | ||
| 1548 | + return p_len; | ||
| 1549 | +err: | ||
| 1550 | + { | ||
| 1551 | + const DH_METHOD *meth = DH_OpenSSL(); | ||
| 1552 | + | ||
| 1553 | + if (kop) | ||
| 1554 | + free(kop); | ||
| 1555 | + ret = (meth->compute_key)(key, pub_key, dh); | ||
| 1556 | + /* Call user cookie handler */ | ||
| 1557 | + cookie->pkc_callback(cookie, 0); | ||
| 1558 | + } | ||
| 1559 | + return (ret); | ||
| 1560 | +} | ||
| 1561 | + | ||
| 1562 | int cryptodev_ecdh_compute_key(void *out, size_t outlen, | ||
| 1563 | const EC_POINT *pub_key, EC_KEY *ecdh, void *(*KDF)(const void *in, size_t inlen, | ||
| 1564 | void *out, size_t *outlen)) | ||
| 1565 | @@ -2537,6 +3608,190 @@ err: | ||
| 1566 | return ret; | ||
| 1567 | } | ||
| 1568 | |||
| 1569 | +int cryptodev_ecdh_compute_key_async(void *out, size_t outlen, | ||
| 1570 | + const EC_POINT *pub_key, EC_KEY *ecdh, void *(*KDF)(const void *in, size_t inlen, | ||
| 1571 | + void *out, size_t *outlen), struct pkc_cookie_s *cookie) | ||
| 1572 | +{ | ||
| 1573 | + ec_curve_t ec_crv = EC_PRIME; | ||
| 1574 | + unsigned char * q = NULL, *w_xy = NULL, *ab = NULL, *s = NULL, *r = NULL; | ||
| 1575 | + BIGNUM * w_x = NULL, *w_y = NULL; | ||
| 1576 | + int q_len = 0, ab_len = 0, pub_key_len = 0, r_len = 0, priv_key_len = 0; | ||
| 1577 | + BIGNUM * p = NULL, *a = NULL, *b = NULL; | ||
| 1578 | + BN_CTX *ctx; | ||
| 1579 | + EC_POINT *tmp=NULL; | ||
| 1580 | + BIGNUM *x=NULL, *y=NULL; | ||
| 1581 | + const BIGNUM *priv_key; | ||
| 1582 | + const EC_GROUP* group = NULL; | ||
| 1583 | + int ret = 1; | ||
| 1584 | + size_t buflen, len; | ||
| 1585 | + struct crypt_kop *kop = malloc(sizeof(struct crypt_kop)); | ||
| 1586 | + | ||
| 1587 | + if (!(ctx = BN_CTX_new()) || !kop) | ||
| 1588 | + goto err; | ||
| 1589 | + | ||
| 1590 | + memset(kop, 0, sizeof(struct crypt_kop)); | ||
| 1591 | + | ||
| 1592 | + BN_CTX_start(ctx); | ||
| 1593 | + x = BN_CTX_get(ctx); | ||
| 1594 | + y = BN_CTX_get(ctx); | ||
| 1595 | + p = BN_CTX_get(ctx); | ||
| 1596 | + a = BN_CTX_get(ctx); | ||
| 1597 | + b = BN_CTX_get(ctx); | ||
| 1598 | + w_x = BN_CTX_get(ctx); | ||
| 1599 | + w_y = BN_CTX_get(ctx); | ||
| 1600 | + | ||
| 1601 | + if (!x || !y || !p || !a || !b || !w_x || !w_y) { | ||
| 1602 | + ECDHerr(ECDH_F_ECDH_COMPUTE_KEY,ERR_R_MALLOC_FAILURE); | ||
| 1603 | + goto err; | ||
| 1604 | + } | ||
| 1605 | + | ||
| 1606 | + priv_key = EC_KEY_get0_private_key(ecdh); | ||
| 1607 | + if (priv_key == NULL) { | ||
| 1608 | + ECDHerr(ECDH_F_ECDH_COMPUTE_KEY,ECDH_R_NO_PRIVATE_VALUE); | ||
| 1609 | + goto err; | ||
| 1610 | + } | ||
| 1611 | + | ||
| 1612 | + group = EC_KEY_get0_group(ecdh); | ||
| 1613 | + if ((tmp=EC_POINT_new(group)) == NULL) { | ||
| 1614 | + ECDHerr(ECDH_F_ECDH_COMPUTE_KEY,ERR_R_MALLOC_FAILURE); | ||
| 1615 | + goto err; | ||
| 1616 | + } | ||
| 1617 | + | ||
| 1618 | + if (EC_METHOD_get_field_type(EC_GROUP_method_of(group)) == | ||
| 1619 | + NID_X9_62_prime_field) { | ||
| 1620 | + ec_crv = EC_PRIME; | ||
| 1621 | + | ||
| 1622 | + if (!EC_POINT_get_affine_coordinates_GFp(group, | ||
| 1623 | + EC_GROUP_get0_generator(group), x, y, ctx)) { | ||
| 1624 | + ECDHerr(ECDH_F_ECDH_COMPUTE_KEY,ECDH_R_POINT_ARITHMETIC_FAILURE); | ||
| 1625 | + goto err; | ||
| 1626 | + } | ||
| 1627 | + | ||
| 1628 | + /* get the ECC curve parameters */ | ||
| 1629 | + if (!EC_GROUP_get_curve_GFp(group, p, a, b, ctx)) { | ||
| 1630 | + ECDHerr(ECDH_F_ECDH_COMPUTE_KEY,ERR_R_BN_LIB); | ||
| 1631 | + goto err; | ||
| 1632 | + } | ||
| 1633 | + | ||
| 1634 | + /* get the public key pair for prime curve */ | ||
| 1635 | + if (!EC_POINT_get_affine_coordinates_GFp (group, pub_key, w_x, w_y,ctx)) { | ||
| 1636 | + ECDHerr(ECDH_F_ECDH_COMPUTE_KEY,ERR_R_BN_LIB); | ||
| 1637 | + goto err; | ||
| 1638 | + } | ||
| 1639 | + } else { | ||
| 1640 | + ec_crv = EC_BINARY; | ||
| 1641 | + | ||
| 1642 | + if (!EC_POINT_get_affine_coordinates_GF2m(group, | ||
| 1643 | + EC_GROUP_get0_generator(group), x, y, ctx)) { | ||
| 1644 | + ECDHerr(ECDH_F_ECDH_COMPUTE_KEY,ECDH_R_POINT_ARITHMETIC_FAILURE); | ||
| 1645 | + goto err; | ||
| 1646 | + } | ||
| 1647 | + | ||
| 1648 | + /* get the ECC curve parameters */ | ||
| 1649 | + if (!EC_GROUP_get_curve_GF2m(group, p, a, b , ctx)) { | ||
| 1650 | + ECDHerr(ECDH_F_ECDH_COMPUTE_KEY,ERR_R_BN_LIB); | ||
| 1651 | + goto err; | ||
| 1652 | + } | ||
| 1653 | + | ||
| 1654 | + /* get the public key pair for binary curve */ | ||
| 1655 | + if (!EC_POINT_get_affine_coordinates_GF2m(group, | ||
| 1656 | + pub_key, w_x, w_y,ctx)) { | ||
| 1657 | + ECDSAerr(ECDSA_F_ECDSA_DO_SIGN, ERR_R_EC_LIB); | ||
| 1658 | + goto err; | ||
| 1659 | + } | ||
| 1660 | + } | ||
| 1661 | + | ||
| 1662 | + /* irreducible polynomial that creates the field */ | ||
| 1663 | + if (spcf_bn2bin((BIGNUM*)&group->order, &r, &r_len)) { | ||
| 1664 | + ECDSAerr(ECDSA_F_ECDSA_DO_SIGN, ERR_R_MALLOC_FAILURE); | ||
| 1665 | + goto err; | ||
| 1666 | + } | ||
| 1667 | + | ||
| 1668 | + /* Get the irreducible polynomial that creates the field */ | ||
| 1669 | + if (spcf_bn2bin(p, &q, &q_len)) { | ||
| 1670 | + ECDHerr(ECDH_F_ECDH_COMPUTE_KEY,ERR_R_BN_LIB); | ||
| 1671 | + goto err; | ||
| 1672 | + } | ||
| 1673 | + | ||
| 1674 | + /* Get the public key into a flat buffer with appropriate padding */ | ||
| 1675 | + pub_key_len = 2 * q_len; | ||
| 1676 | + w_xy = eng_copy_curve_points (w_x, w_y, pub_key_len, q_len); | ||
| 1677 | + if (!w_xy) { | ||
| 1678 | + ECDSAerr(ECDSA_F_ECDSA_DO_SIGN, ERR_R_MALLOC_FAILURE); | ||
| 1679 | + goto err; | ||
| 1680 | + } | ||
| 1681 | + | ||
| 1682 | + /* Generation of ECC curve parameters */ | ||
| 1683 | + ab_len = 2*q_len; | ||
| 1684 | + ab = eng_copy_curve_points (a, b, ab_len, q_len); | ||
| 1685 | + if (!ab) { | ||
| 1686 | + ECDHerr(ECDH_F_ECDH_COMPUTE_KEY,ERR_R_BN_LIB); | ||
| 1687 | + goto err; | ||
| 1688 | + } | ||
| 1689 | + | ||
| 1690 | + if (ec_crv == EC_BINARY) { | ||
| 1691 | + /* copy b' i.e c(b), instead of only b */ | ||
| 1692 | + if (eng_ec_get_cparam(EC_GROUP_get_curve_name(group), ab+q_len, q_len)) | ||
| 1693 | + { | ||
| 1694 | + unsigned char *c_temp = NULL; | ||
| 1695 | + int c_temp_len = q_len; | ||
| 1696 | + if (eng_ec_compute_cparam(b, p, &c_temp, &c_temp_len)) | ||
| 1697 | + memcpy(ab+q_len, c_temp, q_len); | ||
| 1698 | + else | ||
| 1699 | + goto err; | ||
| 1700 | + } | ||
| 1701 | + kop->curve_type = ECC_BINARY; | ||
| 1702 | + } else | ||
| 1703 | + kop->curve_type = ECC_PRIME; | ||
| 1704 | + | ||
| 1705 | + priv_key_len = r_len; | ||
| 1706 | + | ||
| 1707 | + /* | ||
| 1708 | + * If BN_num_bytes of priv_key returns less then r_len then | ||
| 1709 | + * add padding bytes before the key | ||
| 1710 | + */ | ||
| 1711 | + if (spcf_bn2bin_ex((BIGNUM *)priv_key, &s, &priv_key_len)) { | ||
| 1712 | + ECDSAerr(ECDSA_F_ECDSA_DO_SIGN, ERR_R_MALLOC_FAILURE); | ||
| 1713 | + goto err; | ||
| 1714 | + } | ||
| 1715 | + | ||
| 1716 | + buflen = (EC_GROUP_get_degree(group) + 7)/8; | ||
| 1717 | + len = BN_num_bytes(x); | ||
| 1718 | + if (len > buflen || q_len < buflen) { | ||
| 1719 | + ECDHerr(ECDH_F_ECDH_COMPUTE_KEY, ERR_R_INTERNAL_ERROR); | ||
| 1720 | + goto err; | ||
| 1721 | + } | ||
| 1722 | + | ||
| 1723 | + kop->crk_op = CRK_DH_COMPUTE_KEY; | ||
| 1724 | + kop->crk_param[0].crp_p = (void *) s; | ||
| 1725 | + kop->crk_param[0].crp_nbits = priv_key_len*8; | ||
| 1726 | + kop->crk_param[1].crp_p = (void *) w_xy; | ||
| 1727 | + kop->crk_param[1].crp_nbits = pub_key_len*8; | ||
| 1728 | + kop->crk_param[2].crp_p = (void *) q; | ||
| 1729 | + kop->crk_param[2].crp_nbits = q_len*8; | ||
| 1730 | + kop->crk_param[3].crp_p = (void *) ab; | ||
| 1731 | + kop->crk_param[3].crp_nbits = ab_len*8; | ||
| 1732 | + kop->crk_iparams = 4; | ||
| 1733 | + kop->crk_param[4].crp_p = (void *) out; | ||
| 1734 | + kop->crk_param[4].crp_nbits = q_len*8; | ||
| 1735 | + kop->crk_oparams = 1; | ||
| 1736 | + kop->cookie = cookie; | ||
| 1737 | + if (cryptodev_asym_async(kop, 0, NULL, 0, NULL)) | ||
| 1738 | + goto err; | ||
| 1739 | + | ||
| 1740 | + return q_len; | ||
| 1741 | +err: | ||
| 1742 | + { | ||
| 1743 | + const ECDH_METHOD *meth = ECDH_OpenSSL(); | ||
| 1744 | + | ||
| 1745 | + if (kop) | ||
| 1746 | + free(kop); | ||
| 1747 | + ret = (meth->compute_key)(out, outlen, pub_key, ecdh, KDF); | ||
| 1748 | + /* Call user cookie handler */ | ||
| 1749 | + cookie->pkc_callback(cookie, 0); | ||
| 1750 | + } | ||
| 1751 | + return ret; | ||
| 1752 | +} | ||
| 1753 | |||
| 1754 | static DH_METHOD cryptodev_dh = { | ||
| 1755 | "cryptodev DH method", | ||
| 1756 | @@ -2545,6 +3800,8 @@ static DH_METHOD cryptodev_dh = { | ||
| 1757 | NULL, | ||
| 1758 | NULL, | ||
| 1759 | NULL, | ||
| 1760 | + NULL, | ||
| 1761 | + NULL, | ||
| 1762 | 0, /* flags */ | ||
| 1763 | NULL /* app_data */ | ||
| 1764 | }; | ||
| 1765 | @@ -2553,6 +3810,7 @@ static ECDH_METHOD cryptodev_ecdh = { | ||
| 1766 | "cryptodev ECDH method", | ||
| 1767 | NULL, /* cryptodev_ecdh_compute_key */ | ||
| 1768 | NULL, | ||
| 1769 | + NULL, | ||
| 1770 | 0, /* flags */ | ||
| 1771 | NULL /* app_data */ | ||
| 1772 | }; | ||
| 1773 | @@ -2625,12 +3883,19 @@ ENGINE_load_cryptodev(void) | ||
| 1774 | cryptodev_rsa.rsa_priv_dec = rsa_meth->rsa_priv_dec; | ||
| 1775 | if (cryptodev_asymfeat & CRF_MOD_EXP) { | ||
| 1776 | cryptodev_rsa.bn_mod_exp = cryptodev_bn_mod_exp; | ||
| 1777 | - if (cryptodev_asymfeat & CRF_MOD_EXP_CRT) | ||
| 1778 | + cryptodev_rsa.bn_mod_exp_async = | ||
| 1779 | + cryptodev_bn_mod_exp_async; | ||
| 1780 | + if (cryptodev_asymfeat & CRF_MOD_EXP_CRT) { | ||
| 1781 | cryptodev_rsa.rsa_mod_exp = | ||
| 1782 | cryptodev_rsa_mod_exp; | ||
| 1783 | - else | ||
| 1784 | + cryptodev_rsa.rsa_mod_exp_async = | ||
| 1785 | + cryptodev_rsa_mod_exp_async; | ||
| 1786 | + } else { | ||
| 1787 | cryptodev_rsa.rsa_mod_exp = | ||
| 1788 | cryptodev_rsa_nocrt_mod_exp; | ||
| 1789 | + cryptodev_rsa.rsa_mod_exp_async = | ||
| 1790 | + cryptodev_rsa_nocrt_mod_exp_async; | ||
| 1791 | + } | ||
| 1792 | } | ||
| 1793 | } | ||
| 1794 | |||
| 1795 | @@ -2638,12 +3903,21 @@ ENGINE_load_cryptodev(void) | ||
| 1796 | const DSA_METHOD *meth = DSA_OpenSSL(); | ||
| 1797 | |||
| 1798 | memcpy(&cryptodev_dsa, meth, sizeof(DSA_METHOD)); | ||
| 1799 | - if (cryptodev_asymfeat & CRF_DSA_SIGN) | ||
| 1800 | + if (cryptodev_asymfeat & CRF_DSA_SIGN) { | ||
| 1801 | cryptodev_dsa.dsa_do_sign = cryptodev_dsa_do_sign; | ||
| 1802 | - if (cryptodev_asymfeat & CRF_DSA_VERIFY) | ||
| 1803 | + cryptodev_dsa.dsa_do_sign_async = | ||
| 1804 | + cryptodev_dsa_do_sign_async; | ||
| 1805 | + } | ||
| 1806 | + if (cryptodev_asymfeat & CRF_DSA_VERIFY) { | ||
| 1807 | cryptodev_dsa.dsa_do_verify = cryptodev_dsa_verify; | ||
| 1808 | - if (cryptodev_asymfeat & CRF_DSA_GENERATE_KEY) | ||
| 1809 | + cryptodev_dsa.dsa_do_verify_async = | ||
| 1810 | + cryptodev_dsa_verify_async; | ||
| 1811 | + } | ||
| 1812 | + if (cryptodev_asymfeat & CRF_DSA_GENERATE_KEY) { | ||
| 1813 | cryptodev_dsa.dsa_keygen = cryptodev_dsa_keygen; | ||
| 1814 | + cryptodev_dsa.dsa_keygen_async = | ||
| 1815 | + cryptodev_dsa_keygen_async; | ||
| 1816 | + } | ||
| 1817 | } | ||
| 1818 | |||
| 1819 | if (ENGINE_set_DH(engine, &cryptodev_dh)){ | ||
| 1820 | @@ -2652,10 +3926,15 @@ ENGINE_load_cryptodev(void) | ||
| 1821 | if (cryptodev_asymfeat & CRF_DH_COMPUTE_KEY) { | ||
| 1822 | cryptodev_dh.compute_key = | ||
| 1823 | cryptodev_dh_compute_key; | ||
| 1824 | + cryptodev_dh.compute_key_async = | ||
| 1825 | + cryptodev_dh_compute_key_async; | ||
| 1826 | } | ||
| 1827 | if (cryptodev_asymfeat & CRF_DH_GENERATE_KEY) { | ||
| 1828 | cryptodev_dh.generate_key = | ||
| 1829 | cryptodev_dh_keygen; | ||
| 1830 | + cryptodev_dh.generate_key_async = | ||
| 1831 | + cryptodev_dh_keygen_async; | ||
| 1832 | + | ||
| 1833 | } | ||
| 1834 | } | ||
| 1835 | |||
| 1836 | @@ -2664,10 +3943,14 @@ ENGINE_load_cryptodev(void) | ||
| 1837 | memcpy(&cryptodev_ecdsa, meth, sizeof(ECDSA_METHOD)); | ||
| 1838 | if (cryptodev_asymfeat & CRF_DSA_SIGN) { | ||
| 1839 | cryptodev_ecdsa.ecdsa_do_sign = cryptodev_ecdsa_do_sign; | ||
| 1840 | + cryptodev_ecdsa.ecdsa_do_sign_async = | ||
| 1841 | + cryptodev_ecdsa_do_sign_async; | ||
| 1842 | } | ||
| 1843 | if (cryptodev_asymfeat & CRF_DSA_VERIFY) { | ||
| 1844 | cryptodev_ecdsa.ecdsa_do_verify = | ||
| 1845 | cryptodev_ecdsa_verify; | ||
| 1846 | + cryptodev_ecdsa.ecdsa_do_verify_async = | ||
| 1847 | + cryptodev_ecdsa_verify_async; | ||
| 1848 | } | ||
| 1849 | } | ||
| 1850 | |||
| 1851 | @@ -2676,9 +3959,16 @@ ENGINE_load_cryptodev(void) | ||
| 1852 | memcpy(&cryptodev_ecdh, ecdh_meth, sizeof(ECDH_METHOD)); | ||
| 1853 | if (cryptodev_asymfeat & CRF_DH_COMPUTE_KEY) { | ||
| 1854 | cryptodev_ecdh.compute_key = cryptodev_ecdh_compute_key; | ||
| 1855 | + cryptodev_ecdh.compute_key_async = | ||
| 1856 | + cryptodev_ecdh_compute_key_async; | ||
| 1857 | } | ||
| 1858 | } | ||
| 1859 | |||
| 1860 | + ENGINE_set_check_pkc_availability(engine, cryptodev_check_availability); | ||
| 1861 | + ENGINE_set_close_instance(engine, cryptodev_close_instance); | ||
| 1862 | + ENGINE_set_init_instance(engine, cryptodev_init_instance); | ||
| 1863 | + ENGINE_set_async_map(engine, ENGINE_ALLPKC_ASYNC); | ||
| 1864 | + | ||
| 1865 | ENGINE_add(engine); | ||
| 1866 | ENGINE_free(engine); | ||
| 1867 | ERR_clear_error(); | ||
| 1868 | diff --git a/crypto/engine/eng_int.h b/crypto/engine/eng_int.h | ||
| 1869 | index 451ef8f..8fc3077 100644 | ||
| 1870 | --- a/crypto/engine/eng_int.h | ||
| 1871 | +++ b/crypto/engine/eng_int.h | ||
| 1872 | @@ -181,7 +181,29 @@ struct engine_st | ||
| 1873 | ENGINE_LOAD_KEY_PTR load_pubkey; | ||
| 1874 | |||
| 1875 | ENGINE_SSL_CLIENT_CERT_PTR load_ssl_client_cert; | ||
| 1876 | - | ||
| 1877 | + /* | ||
| 1878 | + * Instantiate Engine handle to be passed in check_pkc_availability | ||
| 1879 | + * Ensure that Engine is instantiated before any pkc asynchronous call. | ||
| 1880 | + */ | ||
| 1881 | + void *(*engine_init_instance)(void); | ||
| 1882 | + /* | ||
| 1883 | + * Instantiated Engine handle will be closed with this call. | ||
| 1884 | + * Ensure that no pkc asynchronous call is made after this call | ||
| 1885 | + */ | ||
| 1886 | + void (*engine_close_instance)(void *handle); | ||
| 1887 | + /* | ||
| 1888 | + * Check availability will extract the data from kernel. | ||
| 1889 | + * eng_handle: This is the Engine handle corresponds to which | ||
| 1890 | + * the cookies needs to be polled. | ||
| 1891 | + * return 0 if cookie available else 1 | ||
| 1892 | + */ | ||
| 1893 | + int (*check_pkc_availability)(void *eng_handle); | ||
| 1894 | + /* | ||
| 1895 | + * The following map is used to check if the engine supports asynchronous implementation | ||
| 1896 | + * ENGINE_ASYNC_FLAG* for available bitmap. Any application checking for asynchronous | ||
| 1897 | + * implementation need to check this features using "int ENGINE_get_async_map(engine *)"; | ||
| 1898 | + */ | ||
| 1899 | + int async_map; | ||
| 1900 | const ENGINE_CMD_DEFN *cmd_defns; | ||
| 1901 | int flags; | ||
| 1902 | /* reference count on the structure itself */ | ||
| 1903 | diff --git a/crypto/engine/eng_lib.c b/crypto/engine/eng_lib.c | ||
| 1904 | index 18a6664..6fa621c 100644 | ||
| 1905 | --- a/crypto/engine/eng_lib.c | ||
| 1906 | +++ b/crypto/engine/eng_lib.c | ||
| 1907 | @@ -98,7 +98,11 @@ void engine_set_all_null(ENGINE *e) | ||
| 1908 | e->ctrl = NULL; | ||
| 1909 | e->load_privkey = NULL; | ||
| 1910 | e->load_pubkey = NULL; | ||
| 1911 | + e->check_pkc_availability = NULL; | ||
| 1912 | + e->engine_init_instance = NULL; | ||
| 1913 | + e->engine_close_instance = NULL; | ||
| 1914 | e->cmd_defns = NULL; | ||
| 1915 | + e->async_map = 0; | ||
| 1916 | e->flags = 0; | ||
| 1917 | } | ||
| 1918 | |||
| 1919 | @@ -233,6 +237,48 @@ int ENGINE_set_id(ENGINE *e, const char *id) | ||
| 1920 | return 1; | ||
| 1921 | } | ||
| 1922 | |||
| 1923 | +void ENGINE_set_init_instance(ENGINE *e, void *(*engine_init_instance)(void)) | ||
| 1924 | + { | ||
| 1925 | + e->engine_init_instance = engine_init_instance; | ||
| 1926 | + } | ||
| 1927 | + | ||
| 1928 | +void ENGINE_set_close_instance(ENGINE *e, | ||
| 1929 | + void (*engine_close_instance)(void *)) | ||
| 1930 | + { | ||
| 1931 | + e->engine_close_instance = engine_close_instance; | ||
| 1932 | + } | ||
| 1933 | + | ||
| 1934 | +void ENGINE_set_async_map(ENGINE *e, int async_map) | ||
| 1935 | + { | ||
| 1936 | + e->async_map = async_map; | ||
| 1937 | + } | ||
| 1938 | + | ||
| 1939 | +void *ENGINE_init_instance(ENGINE *e) | ||
| 1940 | + { | ||
| 1941 | + return e->engine_init_instance(); | ||
| 1942 | + } | ||
| 1943 | + | ||
| 1944 | +void ENGINE_close_instance(ENGINE *e, void *eng_handle) | ||
| 1945 | + { | ||
| 1946 | + e->engine_close_instance(eng_handle); | ||
| 1947 | + } | ||
| 1948 | + | ||
| 1949 | +int ENGINE_get_async_map(ENGINE *e) | ||
| 1950 | + { | ||
| 1951 | + return e->async_map; | ||
| 1952 | + } | ||
| 1953 | + | ||
| 1954 | +void ENGINE_set_check_pkc_availability(ENGINE *e, | ||
| 1955 | + int (*check_pkc_availability)(void *eng_handle)) | ||
| 1956 | + { | ||
| 1957 | + e->check_pkc_availability = check_pkc_availability; | ||
| 1958 | + } | ||
| 1959 | + | ||
| 1960 | +int ENGINE_check_pkc_availability(ENGINE *e, void *eng_handle) | ||
| 1961 | + { | ||
| 1962 | + return e->check_pkc_availability(eng_handle); | ||
| 1963 | + } | ||
| 1964 | + | ||
| 1965 | int ENGINE_set_name(ENGINE *e, const char *name) | ||
| 1966 | { | ||
| 1967 | if(name == NULL) | ||
| 1968 | diff --git a/crypto/engine/engine.h b/crypto/engine/engine.h | ||
| 1969 | index 237a6c9..ccff86a 100644 | ||
| 1970 | --- a/crypto/engine/engine.h | ||
| 1971 | +++ b/crypto/engine/engine.h | ||
| 1972 | @@ -473,6 +473,30 @@ ENGINE *ENGINE_new(void); | ||
| 1973 | int ENGINE_free(ENGINE *e); | ||
| 1974 | int ENGINE_up_ref(ENGINE *e); | ||
| 1975 | int ENGINE_set_id(ENGINE *e, const char *id); | ||
| 1976 | +void ENGINE_set_init_instance(ENGINE *e, void *(*engine_init_instance)(void)); | ||
| 1977 | +void ENGINE_set_close_instance(ENGINE *e, | ||
| 1978 | + void (*engine_free_instance)(void *)); | ||
| 1979 | +/* | ||
| 1980 | + * Following FLAGS are bitmap store in async_map to set asynchronous interface capability | ||
| 1981 | + *of the engine | ||
| 1982 | + */ | ||
| 1983 | +#define ENGINE_RSA_ASYNC 0x0001 | ||
| 1984 | +#define ENGINE_DSA_ASYNC 0x0002 | ||
| 1985 | +#define ENGINE_DH_ASYNC 0x0004 | ||
| 1986 | +#define ENGINE_ECDSA_ASYNC 0x0008 | ||
| 1987 | +#define ENGINE_ECDH_ASYNC 0x0010 | ||
| 1988 | +#define ENGINE_ALLPKC_ASYNC 0x001F | ||
| 1989 | +/* Engine implementation will set the bitmap based on above flags using following API */ | ||
| 1990 | +void ENGINE_set_async_map(ENGINE *e, int async_map); | ||
| 1991 | + /* Application need to check the bitmap based on above flags using following API | ||
| 1992 | + * to confirm asynchronous methods supported | ||
| 1993 | + */ | ||
| 1994 | +int ENGINE_get_async_map(ENGINE *e); | ||
| 1995 | +void *ENGINE_init_instance(ENGINE *e); | ||
| 1996 | +void ENGINE_close_instance(ENGINE *e, void *eng_handle); | ||
| 1997 | +void ENGINE_set_check_pkc_availability(ENGINE *e, | ||
| 1998 | + int (*check_pkc_availability)(void *eng_handle)); | ||
| 1999 | +int ENGINE_check_pkc_availability(ENGINE *e, void *eng_handle); | ||
| 2000 | int ENGINE_set_name(ENGINE *e, const char *name); | ||
| 2001 | int ENGINE_set_RSA(ENGINE *e, const RSA_METHOD *rsa_meth); | ||
| 2002 | int ENGINE_set_DSA(ENGINE *e, const DSA_METHOD *dsa_meth); | ||
| 2003 | diff --git a/crypto/rsa/rsa.h b/crypto/rsa/rsa.h | ||
| 2004 | index 5f269e5..6ef1b15 100644 | ||
| 2005 | --- a/crypto/rsa/rsa.h | ||
| 2006 | +++ b/crypto/rsa/rsa.h | ||
| 2007 | @@ -101,6 +101,29 @@ struct rsa_meth_st | ||
| 2008 | int (*bn_mod_exp)(BIGNUM *r, const BIGNUM *a, const BIGNUM *p, | ||
| 2009 | const BIGNUM *m, BN_CTX *ctx, | ||
| 2010 | BN_MONT_CTX *m_ctx); /* Can be null */ | ||
| 2011 | + /* | ||
| 2012 | + * Cookie in the following _async variant must be allocated before | ||
| 2013 | + * submission and can be freed once its corresponding callback | ||
| 2014 | + * handler is called | ||
| 2015 | + */ | ||
| 2016 | + int (*rsa_pub_enc_asyn)(int flen,const unsigned char *from, | ||
| 2017 | + unsigned char *to, RSA *rsa, int padding, | ||
| 2018 | + struct pkc_cookie_s *cookie); | ||
| 2019 | + int (*rsa_pub_dec_async)(int flen,const unsigned char *from, | ||
| 2020 | + unsigned char *to, RSA *rsa, int padding, | ||
| 2021 | + struct pkc_cookie_s *cookie); | ||
| 2022 | + int (*rsa_priv_enc_async)(int flen,const unsigned char *from, | ||
| 2023 | + unsigned char *to, RSA *rsa, int padding, | ||
| 2024 | + struct pkc_cookie_s *cookie); | ||
| 2025 | + int (*rsa_priv_dec_async)(int flen,const unsigned char *from, | ||
| 2026 | + unsigned char *to, RSA *rsa, int padding, | ||
| 2027 | + struct pkc_cookie_s *cookie); | ||
| 2028 | + int (*rsa_mod_exp_async)(BIGNUM *r0, const BIGNUM *I, RSA *rsa, | ||
| 2029 | + BN_CTX *ctx, struct pkc_cookie_s *cookie); | ||
| 2030 | + int (*bn_mod_exp_async)(BIGNUM *r, const BIGNUM *a, const BIGNUM *p, | ||
| 2031 | + const BIGNUM *m, BN_CTX *ctx, | ||
| 2032 | + BN_MONT_CTX *m_ctx, struct pkc_cookie_s *cookie); | ||
| 2033 | + | ||
| 2034 | int (*init)(RSA *rsa); /* called at new */ | ||
| 2035 | int (*finish)(RSA *rsa); /* called at free */ | ||
| 2036 | int flags; /* RSA_METHOD_FLAG_* things */ | ||
| 2037 | -- | ||
| 2038 | 2.3.5 | ||
| 2039 | |||
diff --git a/recipes-connectivity/openssl/openssl-qoriq/qoriq/0010-Removed-local-copy-of-curve_t-type.patch b/recipes-connectivity/openssl/openssl-qoriq/qoriq/0010-Removed-local-copy-of-curve_t-type.patch new file mode 100644 index 000000000..8908d5482 --- /dev/null +++ b/recipes-connectivity/openssl/openssl-qoriq/qoriq/0010-Removed-local-copy-of-curve_t-type.patch | |||
| @@ -0,0 +1,163 @@ | |||
| 1 | From cd80be25a3da28d23dfcb2762252b413879eaa74 Mon Sep 17 00:00:00 2001 | ||
| 2 | From: Yashpal Dutta <yashpal.dutta@freescale.com> | ||
| 3 | Date: Thu, 17 Apr 2014 06:57:59 +0545 | ||
| 4 | Subject: [PATCH 10/48] Removed local copy of curve_t type | ||
| 5 | |||
| 6 | Upstream-status: Pending | ||
| 7 | |||
| 8 | Signed-off-by: Yashpal Dutta <yashpal.dutta@freescale.com> | ||
| 9 | Tested-by: Cristian Stoica <cristian.stoica@freescale.com> | ||
| 10 | --- | ||
| 11 | crypto/engine/eng_cryptodev.c | 33 ++++++++++++++------------------- | ||
| 12 | crypto/engine/eng_cryptodev_ec.h | 7 ------- | ||
| 13 | 2 files changed, 14 insertions(+), 26 deletions(-) | ||
| 14 | |||
| 15 | diff --git a/crypto/engine/eng_cryptodev.c b/crypto/engine/eng_cryptodev.c | ||
| 16 | index eac5fb6..151774c 100644 | ||
| 17 | --- a/crypto/engine/eng_cryptodev.c | ||
| 18 | +++ b/crypto/engine/eng_cryptodev.c | ||
| 19 | @@ -2504,11 +2504,6 @@ static ECDSA_METHOD cryptodev_ecdsa = { | ||
| 20 | NULL /* app_data */ | ||
| 21 | }; | ||
| 22 | |||
| 23 | -typedef enum ec_curve_s { | ||
| 24 | - EC_PRIME, | ||
| 25 | - EC_BINARY | ||
| 26 | -} ec_curve_t; | ||
| 27 | - | ||
| 28 | /* ENGINE handler for ECDSA Sign */ | ||
| 29 | static ECDSA_SIG *cryptodev_ecdsa_do_sign(const unsigned char *dgst, | ||
| 30 | int dgst_len, const BIGNUM *in_kinv, | ||
| 31 | @@ -2527,7 +2522,7 @@ static ECDSA_SIG *cryptodev_ecdsa_do_sign(const unsigned char *dgst, | ||
| 32 | const BIGNUM *order = NULL, *priv_key = NULL; | ||
| 33 | const EC_GROUP *group = NULL; | ||
| 34 | struct crypt_kop kop; | ||
| 35 | - ec_curve_t ec_crv = EC_PRIME; | ||
| 36 | + enum ec_curve_t ec_crv = EC_PRIME; | ||
| 37 | |||
| 38 | memset(&kop, 0, sizeof(kop)); | ||
| 39 | ecdsa = ecdsa_check(eckey); | ||
| 40 | @@ -2665,7 +2660,7 @@ static ECDSA_SIG *cryptodev_ecdsa_do_sign(const unsigned char *dgst, | ||
| 41 | else | ||
| 42 | goto err; | ||
| 43 | } | ||
| 44 | - kop.curve_type = ECC_BINARY; | ||
| 45 | + kop.curve_type = EC_BINARY; | ||
| 46 | } | ||
| 47 | |||
| 48 | /* Calculation of Generator point */ | ||
| 49 | @@ -2760,7 +2755,7 @@ static int cryptodev_ecdsa_verify(const unsigned char *dgst, int dgst_len, | ||
| 50 | const EC_POINT *pub_key = NULL; | ||
| 51 | const BIGNUM *order = NULL; | ||
| 52 | const EC_GROUP *group = NULL; | ||
| 53 | - ec_curve_t ec_crv = EC_PRIME; | ||
| 54 | + enum ec_curve_t ec_crv = EC_PRIME; | ||
| 55 | struct crypt_kop kop; | ||
| 56 | |||
| 57 | memset(&kop, 0, sizeof kop); | ||
| 58 | @@ -2911,7 +2906,7 @@ static int cryptodev_ecdsa_verify(const unsigned char *dgst, int dgst_len, | ||
| 59 | else | ||
| 60 | goto err; | ||
| 61 | } | ||
| 62 | - kop.curve_type = ECC_BINARY; | ||
| 63 | + kop.curve_type = EC_BINARY; | ||
| 64 | } | ||
| 65 | |||
| 66 | /* Calculation of Generator point */ | ||
| 67 | @@ -3016,7 +3011,7 @@ static int cryptodev_ecdsa_do_sign_async(const unsigned char *dgst, | ||
| 68 | const BIGNUM *order = NULL, *priv_key = NULL; | ||
| 69 | const EC_GROUP *group = NULL; | ||
| 70 | struct crypt_kop *kop = malloc(sizeof(struct crypt_kop)); | ||
| 71 | - ec_curve_t ec_crv = EC_PRIME; | ||
| 72 | + enum ec_curve_t ec_crv = EC_PRIME; | ||
| 73 | |||
| 74 | if (!(sig->r = BN_new()) || !kop) | ||
| 75 | goto err; | ||
| 76 | @@ -3157,7 +3152,7 @@ static int cryptodev_ecdsa_do_sign_async(const unsigned char *dgst, | ||
| 77 | else | ||
| 78 | goto err; | ||
| 79 | } | ||
| 80 | - kop->curve_type = ECC_BINARY; | ||
| 81 | + kop->curve_type = EC_BINARY; | ||
| 82 | } | ||
| 83 | |||
| 84 | /* Calculation of Generator point */ | ||
| 85 | @@ -3237,7 +3232,7 @@ static int cryptodev_ecdsa_verify_async(const unsigned char *dgst, | ||
| 86 | const EC_POINT *pub_key = NULL; | ||
| 87 | const BIGNUM *order = NULL; | ||
| 88 | const EC_GROUP *group = NULL; | ||
| 89 | - ec_curve_t ec_crv = EC_PRIME; | ||
| 90 | + enum ec_curve_t ec_crv = EC_PRIME; | ||
| 91 | struct crypt_kop *kop = malloc(sizeof(struct crypt_kop)); | ||
| 92 | |||
| 93 | if (!kop) | ||
| 94 | @@ -3384,7 +3379,7 @@ static int cryptodev_ecdsa_verify_async(const unsigned char *dgst, | ||
| 95 | if (ec_crv == EC_BINARY) { | ||
| 96 | /* copy b' i.e c(b), instead of only b */ | ||
| 97 | eng_ec_get_cparam(EC_GROUP_get_curve_name(group), ab + q_len, q_len); | ||
| 98 | - kop->curve_type = ECC_BINARY; | ||
| 99 | + kop->curve_type = EC_BINARY; | ||
| 100 | } | ||
| 101 | |||
| 102 | /* Calculation of Generator point */ | ||
| 103 | @@ -3690,7 +3685,7 @@ int cryptodev_ecdh_compute_key(void *out, size_t outlen, | ||
| 104 | void *(*KDF) (const void *in, size_t inlen, | ||
| 105 | void *out, size_t *outlen)) | ||
| 106 | { | ||
| 107 | - ec_curve_t ec_crv = EC_PRIME; | ||
| 108 | + enum ec_curve_t ec_crv = EC_PRIME; | ||
| 109 | unsigned char *q = NULL, *w_xy = NULL, *ab = NULL, *s = NULL, *r = NULL; | ||
| 110 | BIGNUM *w_x = NULL, *w_y = NULL; | ||
| 111 | int q_len = 0, ab_len = 0, pub_key_len = 0, r_len = 0, priv_key_len = 0; | ||
| 112 | @@ -3820,9 +3815,9 @@ int cryptodev_ecdh_compute_key(void *out, size_t outlen, | ||
| 113 | else | ||
| 114 | goto err; | ||
| 115 | } | ||
| 116 | - kop.curve_type = ECC_BINARY; | ||
| 117 | + kop.curve_type = EC_BINARY; | ||
| 118 | } else | ||
| 119 | - kop.curve_type = ECC_PRIME; | ||
| 120 | + kop.curve_type = EC_PRIME; | ||
| 121 | |||
| 122 | priv_key_len = r_len; | ||
| 123 | |||
| 124 | @@ -3874,7 +3869,7 @@ int cryptodev_ecdh_compute_key_async(void *out, size_t outlen, | ||
| 125 | size_t *outlen), | ||
| 126 | struct pkc_cookie_s *cookie) | ||
| 127 | { | ||
| 128 | - ec_curve_t ec_crv = EC_PRIME; | ||
| 129 | + enum ec_curve_t ec_crv = EC_PRIME; | ||
| 130 | unsigned char *q = NULL, *w_xy = NULL, *ab = NULL, *s = NULL, *r = NULL; | ||
| 131 | BIGNUM *w_x = NULL, *w_y = NULL; | ||
| 132 | int q_len = 0, ab_len = 0, pub_key_len = 0, r_len = 0, priv_key_len = 0; | ||
| 133 | @@ -4005,9 +4000,9 @@ int cryptodev_ecdh_compute_key_async(void *out, size_t outlen, | ||
| 134 | else | ||
| 135 | goto err; | ||
| 136 | } | ||
| 137 | - kop->curve_type = ECC_BINARY; | ||
| 138 | + kop->curve_type = EC_BINARY; | ||
| 139 | } else | ||
| 140 | - kop->curve_type = ECC_PRIME; | ||
| 141 | + kop->curve_type = EC_PRIME; | ||
| 142 | |||
| 143 | priv_key_len = r_len; | ||
| 144 | |||
| 145 | diff --git a/crypto/engine/eng_cryptodev_ec.h b/crypto/engine/eng_cryptodev_ec.h | ||
| 146 | index af54c51..41a8702 100644 | ||
| 147 | --- a/crypto/engine/eng_cryptodev_ec.h | ||
| 148 | +++ b/crypto/engine/eng_cryptodev_ec.h | ||
| 149 | @@ -287,11 +287,4 @@ static inline unsigned char *eng_copy_curve_points(BIGNUM * x, BIGNUM * y, | ||
| 150 | |||
| 151 | return xy; | ||
| 152 | } | ||
| 153 | - | ||
| 154 | -enum curve_t { | ||
| 155 | - DISCRETE_LOG, | ||
| 156 | - ECC_PRIME, | ||
| 157 | - ECC_BINARY, | ||
| 158 | - MAX_ECC_TYPE | ||
| 159 | -}; | ||
| 160 | #endif | ||
| 161 | -- | ||
| 162 | 2.7.0 | ||
| 163 | |||
diff --git a/recipes-connectivity/openssl/openssl-qoriq/qoriq/0011-Add-RSA-keygen-operation-and-support-gendsa-command-.patch b/recipes-connectivity/openssl/openssl-qoriq/qoriq/0011-Add-RSA-keygen-operation-and-support-gendsa-command-.patch deleted file mode 100644 index 244d230ec..000000000 --- a/recipes-connectivity/openssl/openssl-qoriq/qoriq/0011-Add-RSA-keygen-operation-and-support-gendsa-command-.patch +++ /dev/null | |||
| @@ -1,153 +0,0 @@ | |||
| 1 | From e4fc051f8ae1c093b25ca346c2ec351ff3b700d1 Mon Sep 17 00:00:00 2001 | ||
| 2 | From: Hou Zhiqiang <B48286@freescale.com> | ||
| 3 | Date: Wed, 2 Apr 2014 16:10:43 +0800 | ||
| 4 | Subject: [PATCH 11/26] Add RSA keygen operation and support gendsa command | ||
| 5 | with hardware engine | ||
| 6 | |||
| 7 | Upstream-status: Pending | ||
| 8 | |||
| 9 | Signed-off-by: Hou Zhiqiang <B48286@freescale.com> | ||
| 10 | Tested-by: Cristian Stoica <cristian.stoica@freescale.com> | ||
| 11 | --- | ||
| 12 | crypto/engine/eng_cryptodev.c | 118 ++++++++++++++++++++++++++++++++++++++++++ | ||
| 13 | 1 file changed, 118 insertions(+) | ||
| 14 | |||
| 15 | diff --git a/crypto/engine/eng_cryptodev.c b/crypto/engine/eng_cryptodev.c | ||
| 16 | index 9f2416e..b2919a8 100644 | ||
| 17 | --- a/crypto/engine/eng_cryptodev.c | ||
| 18 | +++ b/crypto/engine/eng_cryptodev.c | ||
| 19 | @@ -1906,6 +1906,121 @@ err: | ||
| 20 | return dsaret; | ||
| 21 | } | ||
| 22 | |||
| 23 | +/* Cryptodev RSA Key Gen routine */ | ||
| 24 | +static int cryptodev_rsa_keygen(RSA *rsa, int bits, BIGNUM *e, BN_GENCB *cb) | ||
| 25 | +{ | ||
| 26 | + struct crypt_kop kop; | ||
| 27 | + int ret, fd; | ||
| 28 | + int p_len, q_len; | ||
| 29 | + int i; | ||
| 30 | + | ||
| 31 | + if ((fd = get_asym_dev_crypto()) < 0) | ||
| 32 | + return fd; | ||
| 33 | + | ||
| 34 | + if(!rsa->n && ((rsa->n=BN_new()) == NULL)) goto err; | ||
| 35 | + if(!rsa->d && ((rsa->d=BN_new()) == NULL)) goto err; | ||
| 36 | + if(!rsa->e && ((rsa->e=BN_new()) == NULL)) goto err; | ||
| 37 | + if(!rsa->p && ((rsa->p=BN_new()) == NULL)) goto err; | ||
| 38 | + if(!rsa->q && ((rsa->q=BN_new()) == NULL)) goto err; | ||
| 39 | + if(!rsa->dmp1 && ((rsa->dmp1=BN_new()) == NULL)) goto err; | ||
| 40 | + if(!rsa->dmq1 && ((rsa->dmq1=BN_new()) == NULL)) goto err; | ||
| 41 | + if(!rsa->iqmp && ((rsa->iqmp=BN_new()) == NULL)) goto err; | ||
| 42 | + | ||
| 43 | + BN_copy(rsa->e, e); | ||
| 44 | + | ||
| 45 | + p_len = (bits+1) / (2 * 8); | ||
| 46 | + q_len = (bits - p_len * 8) / 8; | ||
| 47 | + memset(&kop, 0, sizeof kop); | ||
| 48 | + kop.crk_op = CRK_RSA_GENERATE_KEY; | ||
| 49 | + | ||
| 50 | + /* p length */ | ||
| 51 | + kop.crk_param[kop.crk_iparams].crp_p = calloc(p_len + 1, sizeof(char)); | ||
| 52 | + if (!kop.crk_param[kop.crk_iparams].crp_p) | ||
| 53 | + goto err; | ||
| 54 | + kop.crk_param[kop.crk_iparams].crp_nbits = p_len * 8; | ||
| 55 | + memset(kop.crk_param[kop.crk_iparams].crp_p, 0xff, p_len + 1); | ||
| 56 | + kop.crk_iparams++; | ||
| 57 | + kop.crk_oparams++; | ||
| 58 | + /* q length */ | ||
| 59 | + kop.crk_param[kop.crk_iparams].crp_p = calloc(q_len + 1, sizeof(char)); | ||
| 60 | + if (!kop.crk_param[kop.crk_iparams].crp_p) | ||
| 61 | + goto err; | ||
| 62 | + kop.crk_param[kop.crk_iparams].crp_nbits = q_len * 8; | ||
| 63 | + memset(kop.crk_param[kop.crk_iparams].crp_p, 0xff, q_len + 1); | ||
| 64 | + kop.crk_iparams++; | ||
| 65 | + kop.crk_oparams++; | ||
| 66 | + /* n length */ | ||
| 67 | + kop.crk_param[kop.crk_iparams].crp_p = calloc(p_len + q_len + 1, sizeof(char)); | ||
| 68 | + if (!kop.crk_param[kop.crk_iparams].crp_p) | ||
| 69 | + goto err; | ||
| 70 | + kop.crk_param[kop.crk_iparams].crp_nbits = bits; | ||
| 71 | + memset(kop.crk_param[kop.crk_iparams].crp_p, 0x00, p_len + q_len + 1); | ||
| 72 | + kop.crk_iparams++; | ||
| 73 | + kop.crk_oparams++; | ||
| 74 | + /* d length */ | ||
| 75 | + kop.crk_param[kop.crk_iparams].crp_p = calloc(p_len + q_len + 1, sizeof(char)); | ||
| 76 | + if (!kop.crk_param[kop.crk_iparams].crp_p) | ||
| 77 | + goto err; | ||
| 78 | + kop.crk_param[kop.crk_iparams].crp_nbits = bits; | ||
| 79 | + memset(kop.crk_param[kop.crk_iparams].crp_p, 0xff, p_len + q_len + 1); | ||
| 80 | + kop.crk_iparams++; | ||
| 81 | + kop.crk_oparams++; | ||
| 82 | + /* dp1 length */ | ||
| 83 | + kop.crk_param[kop.crk_iparams].crp_p = calloc(p_len + 1, sizeof(char)); | ||
| 84 | + if (!kop.crk_param[kop.crk_iparams].crp_p) | ||
| 85 | + goto err; | ||
| 86 | + kop.crk_param[kop.crk_iparams].crp_nbits = p_len * 8; | ||
| 87 | + memset(kop.crk_param[kop.crk_iparams].crp_p, 0xff, p_len + 1); | ||
| 88 | + kop.crk_iparams++; | ||
| 89 | + kop.crk_oparams++; | ||
| 90 | + /* dq1 length */ | ||
| 91 | + kop.crk_param[kop.crk_iparams].crp_p = calloc(q_len + 1, sizeof(char)); | ||
| 92 | + if (!kop.crk_param[kop.crk_iparams].crp_p) | ||
| 93 | + goto err; | ||
| 94 | + kop.crk_param[kop.crk_iparams].crp_nbits = q_len * 8; | ||
| 95 | + memset(kop.crk_param[kop.crk_iparams].crp_p, 0xff, q_len + 1); | ||
| 96 | + kop.crk_iparams++; | ||
| 97 | + kop.crk_oparams++; | ||
| 98 | + /* i length */ | ||
| 99 | + kop.crk_param[kop.crk_iparams].crp_p = calloc(p_len + 1, sizeof(char)); | ||
| 100 | + if (!kop.crk_param[kop.crk_iparams].crp_p) | ||
| 101 | + goto err; | ||
| 102 | + kop.crk_param[kop.crk_iparams].crp_nbits = p_len * 8; | ||
| 103 | + memset(kop.crk_param[kop.crk_iparams].crp_p, 0xff, p_len + 1); | ||
| 104 | + kop.crk_iparams++; | ||
| 105 | + kop.crk_oparams++; | ||
| 106 | + | ||
| 107 | + if (ioctl(fd, CIOCKEY, &kop) == 0) { | ||
| 108 | + BN_bin2bn(kop.crk_param[0].crp_p, | ||
| 109 | + p_len, rsa->p); | ||
| 110 | + BN_bin2bn(kop.crk_param[1].crp_p, | ||
| 111 | + q_len, rsa->q); | ||
| 112 | + BN_bin2bn(kop.crk_param[2].crp_p, | ||
| 113 | + bits / 8, rsa->n); | ||
| 114 | + BN_bin2bn(kop.crk_param[3].crp_p, | ||
| 115 | + bits / 8, rsa->d); | ||
| 116 | + BN_bin2bn(kop.crk_param[4].crp_p, | ||
| 117 | + p_len, rsa->dmp1); | ||
| 118 | + BN_bin2bn(kop.crk_param[5].crp_p, | ||
| 119 | + q_len, rsa->dmq1); | ||
| 120 | + BN_bin2bn(kop.crk_param[6].crp_p, | ||
| 121 | + p_len, rsa->iqmp); | ||
| 122 | + return 1; | ||
| 123 | + } | ||
| 124 | +sw_try: | ||
| 125 | + { | ||
| 126 | + const RSA_METHOD *meth = RSA_PKCS1_SSLeay(); | ||
| 127 | + ret = (meth->rsa_keygen)(rsa, bits, e, cb); | ||
| 128 | + } | ||
| 129 | + return ret; | ||
| 130 | + | ||
| 131 | +err: | ||
| 132 | + for (i = 0; i < CRK_MAXPARAM; i++) | ||
| 133 | + free(kop.crk_param[i].crp_p); | ||
| 134 | + return 0; | ||
| 135 | + | ||
| 136 | +} | ||
| 137 | + | ||
| 138 | /* Cryptodev DSA Key Gen routine */ | ||
| 139 | static int cryptodev_dsa_keygen(DSA *dsa) | ||
| 140 | { | ||
| 141 | @@ -3896,6 +4011,9 @@ ENGINE_load_cryptodev(void) | ||
| 142 | cryptodev_rsa.rsa_mod_exp_async = | ||
| 143 | cryptodev_rsa_nocrt_mod_exp_async; | ||
| 144 | } | ||
| 145 | + if (cryptodev_asymfeat & CRF_RSA_GENERATE_KEY) | ||
| 146 | + cryptodev_rsa.rsa_keygen = | ||
| 147 | + cryptodev_rsa_keygen; | ||
| 148 | } | ||
| 149 | } | ||
| 150 | |||
| 151 | -- | ||
| 152 | 2.3.5 | ||
| 153 | |||
diff --git a/recipes-connectivity/openssl/openssl-qoriq/qoriq/0011-Modulus-parameter-is-not-populated-by-dhparams.patch b/recipes-connectivity/openssl/openssl-qoriq/qoriq/0011-Modulus-parameter-is-not-populated-by-dhparams.patch new file mode 100644 index 000000000..13aea0156 --- /dev/null +++ b/recipes-connectivity/openssl/openssl-qoriq/qoriq/0011-Modulus-parameter-is-not-populated-by-dhparams.patch | |||
| @@ -0,0 +1,43 @@ | |||
| 1 | From f9d9da58818740334ef356d0384d4e88da865dca Mon Sep 17 00:00:00 2001 | ||
| 2 | From: Yashpal Dutta <yashpal.dutta@freescale.com> | ||
| 3 | Date: Tue, 22 Apr 2014 22:58:33 +0545 | ||
| 4 | Subject: [PATCH 11/48] Modulus parameter is not populated by dhparams | ||
| 5 | |||
| 6 | Upstream-status: Pending | ||
| 7 | |||
| 8 | When dhparams are created, modulus parameter required for | ||
| 9 | private key generation is not populated. So, falling back | ||
| 10 | to software for proper population of modulus parameters followed | ||
| 11 | by private key generation | ||
| 12 | |||
| 13 | Signed-off-by: Yashpal Dutta <yashpal.dutta@freescale.com> | ||
| 14 | Tested-by: Cristian Stoica <cristian.stoica@freescale.com> | ||
| 15 | --- | ||
| 16 | crypto/engine/eng_cryptodev.c | 4 ++-- | ||
| 17 | 1 file changed, 2 insertions(+), 2 deletions(-) | ||
| 18 | |||
| 19 | diff --git a/crypto/engine/eng_cryptodev.c b/crypto/engine/eng_cryptodev.c | ||
| 20 | index 151774c..1f1f307 100644 | ||
| 21 | --- a/crypto/engine/eng_cryptodev.c | ||
| 22 | +++ b/crypto/engine/eng_cryptodev.c | ||
| 23 | @@ -3502,7 +3502,7 @@ static int cryptodev_dh_keygen_async(DH *dh, struct pkc_cookie_s *cookie) | ||
| 24 | kop->crk_op = CRK_DH_GENERATE_KEY; | ||
| 25 | if (bn2crparam(dh->p, &kop->crk_param[0])) | ||
| 26 | goto sw_try; | ||
| 27 | - if (bn2crparam(dh->q, &kop->crk_param[1])) | ||
| 28 | + if (!dh->q || bn2crparam(dh->q, &kop->crk_param[1])) | ||
| 29 | goto sw_try; | ||
| 30 | kop->crk_param[2].crp_p = g; | ||
| 31 | kop->crk_param[2].crp_nbits = g_len * 8; | ||
| 32 | @@ -3557,7 +3557,7 @@ static int cryptodev_dh_keygen(DH *dh) | ||
| 33 | kop.crk_op = CRK_DH_GENERATE_KEY; | ||
| 34 | if (bn2crparam(dh->p, &kop.crk_param[0])) | ||
| 35 | goto sw_try; | ||
| 36 | - if (bn2crparam(dh->q, &kop.crk_param[1])) | ||
| 37 | + if (!dh->q || bn2crparam(dh->q, &kop.crk_param[1])) | ||
| 38 | goto sw_try; | ||
| 39 | kop.crk_param[2].crp_p = g; | ||
| 40 | kop.crk_param[2].crp_nbits = g_len * 8; | ||
| 41 | -- | ||
| 42 | 2.7.0 | ||
| 43 | |||
diff --git a/recipes-connectivity/openssl/openssl-qoriq/qoriq/0012-RSA-Keygen-Fix.patch b/recipes-connectivity/openssl/openssl-qoriq/qoriq/0012-RSA-Keygen-Fix.patch deleted file mode 100644 index 7f907da4a..000000000 --- a/recipes-connectivity/openssl/openssl-qoriq/qoriq/0012-RSA-Keygen-Fix.patch +++ /dev/null | |||
| @@ -1,64 +0,0 @@ | |||
| 1 | From ac777f046da7151386d667391362ecb553ceee90 Mon Sep 17 00:00:00 2001 | ||
| 2 | From: Yashpal Dutta <yashpal.dutta@freescale.com> | ||
| 3 | Date: Wed, 16 Apr 2014 22:53:04 +0545 | ||
| 4 | Subject: [PATCH 12/26] RSA Keygen Fix | ||
| 5 | |||
| 6 | Upstream-status: Pending | ||
| 7 | |||
| 8 | If Kernel driver doesn't support RSA Keygen or same returns | ||
| 9 | error handling the keygen operation, the keygen is gracefully | ||
| 10 | handled by software supported rsa_keygen handler | ||
| 11 | |||
| 12 | Signed-off-by: Yashpal Dutta <yashpal.dutta@freescale.com> | ||
| 13 | Tested-by: Cristian Stoica <cristian.stoica@freescale.com> | ||
| 14 | --- | ||
| 15 | crypto/engine/eng_cryptodev.c | 12 +++++++----- | ||
| 16 | 1 file changed, 7 insertions(+), 5 deletions(-) | ||
| 17 | |||
| 18 | diff --git a/crypto/engine/eng_cryptodev.c b/crypto/engine/eng_cryptodev.c | ||
| 19 | index b2919a8..ed5f20f 100644 | ||
| 20 | --- a/crypto/engine/eng_cryptodev.c | ||
| 21 | +++ b/crypto/engine/eng_cryptodev.c | ||
| 22 | @@ -1915,7 +1915,7 @@ static int cryptodev_rsa_keygen(RSA *rsa, int bits, BIGNUM *e, BN_GENCB *cb) | ||
| 23 | int i; | ||
| 24 | |||
| 25 | if ((fd = get_asym_dev_crypto()) < 0) | ||
| 26 | - return fd; | ||
| 27 | + goto sw_try; | ||
| 28 | |||
| 29 | if(!rsa->n && ((rsa->n=BN_new()) == NULL)) goto err; | ||
| 30 | if(!rsa->d && ((rsa->d=BN_new()) == NULL)) goto err; | ||
| 31 | @@ -1936,7 +1936,7 @@ static int cryptodev_rsa_keygen(RSA *rsa, int bits, BIGNUM *e, BN_GENCB *cb) | ||
| 32 | /* p length */ | ||
| 33 | kop.crk_param[kop.crk_iparams].crp_p = calloc(p_len + 1, sizeof(char)); | ||
| 34 | if (!kop.crk_param[kop.crk_iparams].crp_p) | ||
| 35 | - goto err; | ||
| 36 | + goto sw_try; | ||
| 37 | kop.crk_param[kop.crk_iparams].crp_nbits = p_len * 8; | ||
| 38 | memset(kop.crk_param[kop.crk_iparams].crp_p, 0xff, p_len + 1); | ||
| 39 | kop.crk_iparams++; | ||
| 40 | @@ -1944,7 +1944,7 @@ static int cryptodev_rsa_keygen(RSA *rsa, int bits, BIGNUM *e, BN_GENCB *cb) | ||
| 41 | /* q length */ | ||
| 42 | kop.crk_param[kop.crk_iparams].crp_p = calloc(q_len + 1, sizeof(char)); | ||
| 43 | if (!kop.crk_param[kop.crk_iparams].crp_p) | ||
| 44 | - goto err; | ||
| 45 | + goto sw_try; | ||
| 46 | kop.crk_param[kop.crk_iparams].crp_nbits = q_len * 8; | ||
| 47 | memset(kop.crk_param[kop.crk_iparams].crp_p, 0xff, q_len + 1); | ||
| 48 | kop.crk_iparams++; | ||
| 49 | @@ -2009,8 +2009,10 @@ static int cryptodev_rsa_keygen(RSA *rsa, int bits, BIGNUM *e, BN_GENCB *cb) | ||
| 50 | } | ||
| 51 | sw_try: | ||
| 52 | { | ||
| 53 | - const RSA_METHOD *meth = RSA_PKCS1_SSLeay(); | ||
| 54 | - ret = (meth->rsa_keygen)(rsa, bits, e, cb); | ||
| 55 | + const RSA_METHOD *meth = rsa->meth; | ||
| 56 | + rsa->meth = RSA_PKCS1_SSLeay(); | ||
| 57 | + ret = RSA_generate_key_ex(rsa, bits, e, cb); | ||
| 58 | + rsa->meth = meth; | ||
| 59 | } | ||
| 60 | return ret; | ||
| 61 | |||
| 62 | -- | ||
| 63 | 2.3.5 | ||
| 64 | |||
diff --git a/recipes-connectivity/openssl/openssl-qoriq/qoriq/0012-SW-Backoff-mechanism-for-dsa-keygen.patch b/recipes-connectivity/openssl/openssl-qoriq/qoriq/0012-SW-Backoff-mechanism-for-dsa-keygen.patch new file mode 100644 index 000000000..bf36a3226 --- /dev/null +++ b/recipes-connectivity/openssl/openssl-qoriq/qoriq/0012-SW-Backoff-mechanism-for-dsa-keygen.patch | |||
| @@ -0,0 +1,53 @@ | |||
| 1 | From 18f4dbbba2c0142792b394bec35531cefe277712 Mon Sep 17 00:00:00 2001 | ||
| 2 | From: Yashpal Dutta <yashpal.dutta@freescale.com> | ||
| 3 | Date: Thu, 24 Apr 2014 00:35:34 +0545 | ||
| 4 | Subject: [PATCH 12/48] SW Backoff mechanism for dsa keygen | ||
| 5 | |||
| 6 | Upstream-status: Pending | ||
| 7 | |||
| 8 | DSA Keygen is not handled in default openssl dsa method. Due to | ||
| 9 | same null function pointer in SW DSA method, the backoff for dsa | ||
| 10 | keygen gives segmentation fault. | ||
| 11 | |||
| 12 | Signed-off-by: Yashpal Dutta <yashpal.dutta@freescale.com> | ||
| 13 | Tested-by: Cristian Stoica <cristian.stoica@freescale.com> | ||
| 14 | --- | ||
| 15 | crypto/engine/eng_cryptodev.c | 12 ++++++++---- | ||
| 16 | 1 file changed, 8 insertions(+), 4 deletions(-) | ||
| 17 | |||
| 18 | diff --git a/crypto/engine/eng_cryptodev.c b/crypto/engine/eng_cryptodev.c | ||
| 19 | index 1f1f307..db8e02d 100644 | ||
| 20 | --- a/crypto/engine/eng_cryptodev.c | ||
| 21 | +++ b/crypto/engine/eng_cryptodev.c | ||
| 22 | @@ -2175,8 +2175,10 @@ static int cryptodev_dsa_keygen(DSA *dsa) | ||
| 23 | return ret; | ||
| 24 | sw_try: | ||
| 25 | { | ||
| 26 | - const DSA_METHOD *meth = DSA_OpenSSL(); | ||
| 27 | - ret = (meth->dsa_keygen) (dsa); | ||
| 28 | + const DSA_METHOD *meth = dsa->meth; | ||
| 29 | + dsa->meth = DSA_OpenSSL(); | ||
| 30 | + ret = DSA_generate_key(dsa); | ||
| 31 | + dsa->meth = meth; | ||
| 32 | } | ||
| 33 | return ret; | ||
| 34 | } | ||
| 35 | @@ -2230,11 +2232,13 @@ static int cryptodev_dsa_keygen_async(DSA *dsa, struct pkc_cookie_s *cookie) | ||
| 36 | return ret; | ||
| 37 | sw_try: | ||
| 38 | { | ||
| 39 | - const DSA_METHOD *meth = DSA_OpenSSL(); | ||
| 40 | + const DSA_METHOD *meth = dsa->meth; | ||
| 41 | |||
| 42 | + dsa->meth = DSA_OpenSSL(); | ||
| 43 | if (kop) | ||
| 44 | free(kop); | ||
| 45 | - ret = (meth->dsa_keygen) (dsa); | ||
| 46 | + ret = DSA_generate_key(dsa); | ||
| 47 | + dsa->meth = meth; | ||
| 48 | cookie->pkc_callback(cookie, 0); | ||
| 49 | } | ||
| 50 | return ret; | ||
| 51 | -- | ||
| 52 | 2.7.0 | ||
| 53 | |||
diff --git a/recipes-connectivity/openssl/openssl-qoriq/qoriq/0013-Fixed-DH-keygen-pair-generator.patch b/recipes-connectivity/openssl/openssl-qoriq/qoriq/0013-Fixed-DH-keygen-pair-generator.patch new file mode 100644 index 000000000..12465d7ef --- /dev/null +++ b/recipes-connectivity/openssl/openssl-qoriq/qoriq/0013-Fixed-DH-keygen-pair-generator.patch | |||
| @@ -0,0 +1,100 @@ | |||
| 1 | From 4d5ffd41f423309fc9aaf3621598ca51c5838e31 Mon Sep 17 00:00:00 2001 | ||
| 2 | From: Yashpal Dutta <yashpal.dutta@freescale.com> | ||
| 3 | Date: Thu, 1 May 2014 06:35:45 +0545 | ||
| 4 | Subject: [PATCH 13/48] Fixed DH keygen pair generator | ||
| 5 | |||
| 6 | Upstream-status: Pending | ||
| 7 | |||
| 8 | Wrong Padding results into keygen length error | ||
| 9 | |||
| 10 | Signed-off-by: Yashpal Dutta <yashpal.dutta@freescale.com> | ||
| 11 | Tested-by: Cristian Stoica <cristian.stoica@freescale.com> | ||
| 12 | --- | ||
| 13 | crypto/engine/eng_cryptodev.c | 50 ++++++++++++++++++++++++++++--------------- | ||
| 14 | 1 file changed, 33 insertions(+), 17 deletions(-) | ||
| 15 | |||
| 16 | diff --git a/crypto/engine/eng_cryptodev.c b/crypto/engine/eng_cryptodev.c | ||
| 17 | index db8e02d..4929ae6 100644 | ||
| 18 | --- a/crypto/engine/eng_cryptodev.c | ||
| 19 | +++ b/crypto/engine/eng_cryptodev.c | ||
| 20 | @@ -3534,44 +3534,60 @@ static int cryptodev_dh_keygen_async(DH *dh, struct pkc_cookie_s *cookie) | ||
| 21 | static int cryptodev_dh_keygen(DH *dh) | ||
| 22 | { | ||
| 23 | struct crypt_kop kop; | ||
| 24 | - int ret = 1, g_len; | ||
| 25 | - unsigned char *g = NULL; | ||
| 26 | + int ret = 1, q_len = 0; | ||
| 27 | + unsigned char *q = NULL, *g = NULL, *s = NULL, *w = NULL; | ||
| 28 | + BIGNUM *pub_key = NULL, *priv_key = NULL; | ||
| 29 | + int generate_new_key = 1; | ||
| 30 | |||
| 31 | - if (dh->priv_key == NULL) { | ||
| 32 | - if ((dh->priv_key = BN_new()) == NULL) | ||
| 33 | - goto sw_try; | ||
| 34 | - } | ||
| 35 | + if (dh->priv_key) | ||
| 36 | + priv_key = dh->priv_key; | ||
| 37 | |||
| 38 | - if (dh->pub_key == NULL) { | ||
| 39 | - if ((dh->pub_key = BN_new()) == NULL) | ||
| 40 | - goto sw_try; | ||
| 41 | - } | ||
| 42 | + if (dh->pub_key) | ||
| 43 | + pub_key = dh->pub_key; | ||
| 44 | |||
| 45 | - g_len = BN_num_bytes(dh->p); | ||
| 46 | + q_len = BN_num_bytes(dh->p); | ||
| 47 | /** | ||
| 48 | * Get generator into a plain buffer. If length is less than | ||
| 49 | * q_len then add leading padding bytes. | ||
| 50 | */ | ||
| 51 | - if (spcf_bn2bin_ex(dh->g, &g, &g_len)) { | ||
| 52 | + if (spcf_bn2bin_ex(dh->g, &g, &q_len)) { | ||
| 53 | + DSAerr(DH_F_DH_GENERATE_KEY, ERR_R_MALLOC_FAILURE); | ||
| 54 | + goto sw_try; | ||
| 55 | + } | ||
| 56 | + | ||
| 57 | + if (spcf_bn2bin_ex(dh->p, &q, &q_len)) { | ||
| 58 | DSAerr(DH_F_DH_GENERATE_KEY, ERR_R_MALLOC_FAILURE); | ||
| 59 | goto sw_try; | ||
| 60 | } | ||
| 61 | |||
| 62 | memset(&kop, 0, sizeof kop); | ||
| 63 | kop.crk_op = CRK_DH_GENERATE_KEY; | ||
| 64 | - if (bn2crparam(dh->p, &kop.crk_param[0])) | ||
| 65 | - goto sw_try; | ||
| 66 | + kop.crk_param[0].crp_p = q; | ||
| 67 | + kop.crk_param[0].crp_nbits = q_len * 8; | ||
| 68 | if (!dh->q || bn2crparam(dh->q, &kop.crk_param[1])) | ||
| 69 | goto sw_try; | ||
| 70 | kop.crk_param[2].crp_p = g; | ||
| 71 | - kop.crk_param[2].crp_nbits = g_len * 8; | ||
| 72 | + kop.crk_param[2].crp_nbits = q_len * 8; | ||
| 73 | kop.crk_iparams = 3; | ||
| 74 | |||
| 75 | + s = OPENSSL_malloc(q_len); | ||
| 76 | + if (!s) { | ||
| 77 | + DSAerr(DH_F_DH_GENERATE_KEY, ERR_R_MALLOC_FAILURE); | ||
| 78 | + goto sw_try; | ||
| 79 | + } | ||
| 80 | + | ||
| 81 | + w = OPENSSL_malloc(q_len); | ||
| 82 | + if (!w) { | ||
| 83 | + DSAerr(DH_F_DH_GENERATE_KEY, ERR_R_MALLOC_FAILURE); | ||
| 84 | + goto sw_try; | ||
| 85 | + } | ||
| 86 | + | ||
| 87 | /* pub_key is or prime length while priv key is of length of order */ | ||
| 88 | - if (cryptodev_asym(&kop, BN_num_bytes(dh->p), dh->pub_key, | ||
| 89 | - BN_num_bytes(dh->q), dh->priv_key)) | ||
| 90 | + if (cryptodev_asym(&kop, q_len, w, q_len, s)) | ||
| 91 | goto sw_try; | ||
| 92 | |||
| 93 | + dh->pub_key = BN_bin2bn(w, q_len, pub_key); | ||
| 94 | + dh->pub_key = BN_bin2bn(s, q_len, priv_key); | ||
| 95 | return ret; | ||
| 96 | sw_try: | ||
| 97 | { | ||
| 98 | -- | ||
| 99 | 2.7.0 | ||
| 100 | |||
diff --git a/recipes-connectivity/openssl/openssl-qoriq/qoriq/0013-Removed-local-copy-of-curve_t-type.patch b/recipes-connectivity/openssl/openssl-qoriq/qoriq/0013-Removed-local-copy-of-curve_t-type.patch deleted file mode 100644 index c9d8ace86..000000000 --- a/recipes-connectivity/openssl/openssl-qoriq/qoriq/0013-Removed-local-copy-of-curve_t-type.patch +++ /dev/null | |||
| @@ -1,164 +0,0 @@ | |||
| 1 | From 6aaa306cdf878250d7b6eaf30978de313653886b Mon Sep 17 00:00:00 2001 | ||
| 2 | From: Yashpal Dutta <yashpal.dutta@freescale.com> | ||
| 3 | Date: Thu, 17 Apr 2014 06:57:59 +0545 | ||
| 4 | Subject: [PATCH 13/26] Removed local copy of curve_t type | ||
| 5 | |||
| 6 | Upstream-status: Pending | ||
| 7 | |||
| 8 | Signed-off-by: Yashpal Dutta <yashpal.dutta@freescale.com> | ||
| 9 | Tested-by: Cristian Stoica <cristian.stoica@freescale.com> | ||
| 10 | --- | ||
| 11 | crypto/engine/eng_cryptodev.c | 34 ++++++++++++++-------------------- | ||
| 12 | crypto/engine/eng_cryptodev_ec.h | 7 ------- | ||
| 13 | 2 files changed, 14 insertions(+), 27 deletions(-) | ||
| 14 | |||
| 15 | diff --git a/crypto/engine/eng_cryptodev.c b/crypto/engine/eng_cryptodev.c | ||
| 16 | index ed5f20f..5d883fa 100644 | ||
| 17 | --- a/crypto/engine/eng_cryptodev.c | ||
| 18 | +++ b/crypto/engine/eng_cryptodev.c | ||
| 19 | @@ -2398,12 +2398,6 @@ static ECDSA_METHOD cryptodev_ecdsa = { | ||
| 20 | NULL /* app_data */ | ||
| 21 | }; | ||
| 22 | |||
| 23 | -typedef enum ec_curve_s | ||
| 24 | -{ | ||
| 25 | - EC_PRIME, | ||
| 26 | - EC_BINARY | ||
| 27 | -} ec_curve_t; | ||
| 28 | - | ||
| 29 | /* ENGINE handler for ECDSA Sign */ | ||
| 30 | static ECDSA_SIG *cryptodev_ecdsa_do_sign( const unsigned char *dgst, | ||
| 31 | int dgst_len, const BIGNUM *in_kinv, const BIGNUM *in_r, EC_KEY *eckey) | ||
| 32 | @@ -2420,7 +2414,7 @@ static ECDSA_SIG *cryptodev_ecdsa_do_sign( const unsigned char *dgst, | ||
| 33 | const BIGNUM *order = NULL, *priv_key=NULL; | ||
| 34 | const EC_GROUP *group = NULL; | ||
| 35 | struct crypt_kop kop; | ||
| 36 | - ec_curve_t ec_crv = EC_PRIME; | ||
| 37 | + enum ec_curve_t ec_crv = EC_PRIME; | ||
| 38 | |||
| 39 | memset(&kop, 0, sizeof(kop)); | ||
| 40 | ecdsa = ecdsa_check(eckey); | ||
| 41 | @@ -2553,7 +2547,7 @@ static ECDSA_SIG *cryptodev_ecdsa_do_sign( const unsigned char *dgst, | ||
| 42 | else | ||
| 43 | goto err; | ||
| 44 | } | ||
| 45 | - kop.curve_type = ECC_BINARY; | ||
| 46 | + kop.curve_type = EC_BINARY; | ||
| 47 | } | ||
| 48 | |||
| 49 | /* Calculation of Generator point */ | ||
| 50 | @@ -2647,7 +2641,7 @@ static int cryptodev_ecdsa_verify(const unsigned char *dgst, int dgst_len, | ||
| 51 | const EC_POINT *pub_key = NULL; | ||
| 52 | const BIGNUM *order = NULL; | ||
| 53 | const EC_GROUP *group=NULL; | ||
| 54 | - ec_curve_t ec_crv = EC_PRIME; | ||
| 55 | + enum ec_curve_t ec_crv = EC_PRIME; | ||
| 56 | struct crypt_kop kop; | ||
| 57 | |||
| 58 | memset(&kop, 0, sizeof kop); | ||
| 59 | @@ -2792,7 +2786,7 @@ static int cryptodev_ecdsa_verify(const unsigned char *dgst, int dgst_len, | ||
| 60 | else | ||
| 61 | goto err; | ||
| 62 | } | ||
| 63 | - kop.curve_type = ECC_BINARY; | ||
| 64 | + kop.curve_type = EC_BINARY; | ||
| 65 | } | ||
| 66 | |||
| 67 | /* Calculation of Generator point */ | ||
| 68 | @@ -2893,7 +2887,7 @@ static int cryptodev_ecdsa_do_sign_async( const unsigned char *dgst, | ||
| 69 | const BIGNUM *order = NULL, *priv_key=NULL; | ||
| 70 | const EC_GROUP *group = NULL; | ||
| 71 | struct crypt_kop *kop = malloc(sizeof(struct crypt_kop)); | ||
| 72 | - ec_curve_t ec_crv = EC_PRIME; | ||
| 73 | + enum ec_curve_t ec_crv = EC_PRIME; | ||
| 74 | |||
| 75 | if (!(sig->r = BN_new()) || !kop) | ||
| 76 | goto err; | ||
| 77 | @@ -3029,7 +3023,7 @@ static int cryptodev_ecdsa_do_sign_async( const unsigned char *dgst, | ||
| 78 | else | ||
| 79 | goto err; | ||
| 80 | } | ||
| 81 | - kop->curve_type = ECC_BINARY; | ||
| 82 | + kop->curve_type = EC_BINARY; | ||
| 83 | } | ||
| 84 | |||
| 85 | /* Calculation of Generator point */ | ||
| 86 | @@ -3105,7 +3099,7 @@ static int cryptodev_ecdsa_verify_async(const unsigned char *dgst, int dgst_len, | ||
| 87 | const EC_POINT *pub_key = NULL; | ||
| 88 | const BIGNUM *order = NULL; | ||
| 89 | const EC_GROUP *group=NULL; | ||
| 90 | - ec_curve_t ec_crv = EC_PRIME; | ||
| 91 | + enum ec_curve_t ec_crv = EC_PRIME; | ||
| 92 | struct crypt_kop *kop = malloc(sizeof(struct crypt_kop)); | ||
| 93 | |||
| 94 | if (!kop) | ||
| 95 | @@ -3247,7 +3241,7 @@ static int cryptodev_ecdsa_verify_async(const unsigned char *dgst, int dgst_len, | ||
| 96 | /* copy b' i.e c(b), instead of only b */ | ||
| 97 | eng_ec_get_cparam (EC_GROUP_get_curve_name(group), | ||
| 98 | ab+q_len, q_len); | ||
| 99 | - kop->curve_type = ECC_BINARY; | ||
| 100 | + kop->curve_type = EC_BINARY; | ||
| 101 | } | ||
| 102 | |||
| 103 | /* Calculation of Generator point */ | ||
| 104 | @@ -3552,7 +3546,7 @@ int cryptodev_ecdh_compute_key(void *out, size_t outlen, | ||
| 105 | const EC_POINT *pub_key, EC_KEY *ecdh, void *(*KDF)(const void *in, size_t inlen, | ||
| 106 | void *out, size_t *outlen)) | ||
| 107 | { | ||
| 108 | - ec_curve_t ec_crv = EC_PRIME; | ||
| 109 | + enum ec_curve_t ec_crv = EC_PRIME; | ||
| 110 | unsigned char * q = NULL, *w_xy = NULL, *ab = NULL, *s = NULL, *r = NULL; | ||
| 111 | BIGNUM * w_x = NULL, *w_y = NULL; | ||
| 112 | int q_len = 0, ab_len = 0, pub_key_len = 0, r_len = 0, priv_key_len = 0; | ||
| 113 | @@ -3678,9 +3672,9 @@ int cryptodev_ecdh_compute_key(void *out, size_t outlen, | ||
| 114 | else | ||
| 115 | goto err; | ||
| 116 | } | ||
| 117 | - kop.curve_type = ECC_BINARY; | ||
| 118 | + kop.curve_type = EC_BINARY; | ||
| 119 | } else | ||
| 120 | - kop.curve_type = ECC_PRIME; | ||
| 121 | + kop.curve_type = EC_PRIME; | ||
| 122 | |||
| 123 | priv_key_len = r_len; | ||
| 124 | |||
| 125 | @@ -3729,7 +3723,7 @@ int cryptodev_ecdh_compute_key_async(void *out, size_t outlen, | ||
| 126 | const EC_POINT *pub_key, EC_KEY *ecdh, void *(*KDF)(const void *in, size_t inlen, | ||
| 127 | void *out, size_t *outlen), struct pkc_cookie_s *cookie) | ||
| 128 | { | ||
| 129 | - ec_curve_t ec_crv = EC_PRIME; | ||
| 130 | + enum ec_curve_t ec_crv = EC_PRIME; | ||
| 131 | unsigned char * q = NULL, *w_xy = NULL, *ab = NULL, *s = NULL, *r = NULL; | ||
| 132 | BIGNUM * w_x = NULL, *w_y = NULL; | ||
| 133 | int q_len = 0, ab_len = 0, pub_key_len = 0, r_len = 0, priv_key_len = 0; | ||
| 134 | @@ -3857,9 +3851,9 @@ int cryptodev_ecdh_compute_key_async(void *out, size_t outlen, | ||
| 135 | else | ||
| 136 | goto err; | ||
| 137 | } | ||
| 138 | - kop->curve_type = ECC_BINARY; | ||
| 139 | + kop->curve_type = EC_BINARY; | ||
| 140 | } else | ||
| 141 | - kop->curve_type = ECC_PRIME; | ||
| 142 | + kop->curve_type = EC_PRIME; | ||
| 143 | |||
| 144 | priv_key_len = r_len; | ||
| 145 | |||
| 146 | diff --git a/crypto/engine/eng_cryptodev_ec.h b/crypto/engine/eng_cryptodev_ec.h | ||
| 147 | index 77aee71..a4b8da5 100644 | ||
| 148 | --- a/crypto/engine/eng_cryptodev_ec.h | ||
| 149 | +++ b/crypto/engine/eng_cryptodev_ec.h | ||
| 150 | @@ -286,11 +286,4 @@ static inline unsigned char *eng_copy_curve_points(BIGNUM * x, BIGNUM * y, | ||
| 151 | |||
| 152 | return xy; | ||
| 153 | } | ||
| 154 | - | ||
| 155 | -enum curve_t { | ||
| 156 | - DISCRETE_LOG, | ||
| 157 | - ECC_PRIME, | ||
| 158 | - ECC_BINARY, | ||
| 159 | - MAX_ECC_TYPE | ||
| 160 | -}; | ||
| 161 | #endif | ||
| 162 | -- | ||
| 163 | 2.3.5 | ||
| 164 | |||
diff --git a/recipes-connectivity/openssl/openssl-qoriq/qoriq/0014-Modulus-parameter-is-not-populated-by-dhparams.patch b/recipes-connectivity/openssl/openssl-qoriq/qoriq/0014-Modulus-parameter-is-not-populated-by-dhparams.patch deleted file mode 100644 index 198bed702..000000000 --- a/recipes-connectivity/openssl/openssl-qoriq/qoriq/0014-Modulus-parameter-is-not-populated-by-dhparams.patch +++ /dev/null | |||
| @@ -1,43 +0,0 @@ | |||
| 1 | From 14623ca9e417ccef1ad3f4138acfac0ebe682f1f Mon Sep 17 00:00:00 2001 | ||
| 2 | From: Yashpal Dutta <yashpal.dutta@freescale.com> | ||
| 3 | Date: Tue, 22 Apr 2014 22:58:33 +0545 | ||
| 4 | Subject: [PATCH 14/26] Modulus parameter is not populated by dhparams | ||
| 5 | |||
| 6 | Upstream-status: Pending | ||
| 7 | |||
| 8 | When dhparams are created, modulus parameter required for | ||
| 9 | private key generation is not populated. So, falling back | ||
| 10 | to software for proper population of modulus parameters followed | ||
| 11 | by private key generation | ||
| 12 | |||
| 13 | Signed-off-by: Yashpal Dutta <yashpal.dutta@freescale.com> | ||
| 14 | Tested-by: Cristian Stoica <cristian.stoica@freescale.com> | ||
| 15 | --- | ||
| 16 | crypto/engine/eng_cryptodev.c | 4 ++-- | ||
| 17 | 1 file changed, 2 insertions(+), 2 deletions(-) | ||
| 18 | |||
| 19 | diff --git a/crypto/engine/eng_cryptodev.c b/crypto/engine/eng_cryptodev.c | ||
| 20 | index 5d883fa..6d69336 100644 | ||
| 21 | --- a/crypto/engine/eng_cryptodev.c | ||
| 22 | +++ b/crypto/engine/eng_cryptodev.c | ||
| 23 | @@ -3364,7 +3364,7 @@ static int cryptodev_dh_keygen_async(DH *dh, struct pkc_cookie_s *cookie) | ||
| 24 | kop->crk_op = CRK_DH_GENERATE_KEY; | ||
| 25 | if (bn2crparam(dh->p, &kop->crk_param[0])) | ||
| 26 | goto sw_try; | ||
| 27 | - if (bn2crparam(dh->q, &kop->crk_param[1])) | ||
| 28 | + if (!dh->q || bn2crparam(dh->q, &kop->crk_param[1])) | ||
| 29 | goto sw_try; | ||
| 30 | kop->crk_param[2].crp_p = g; | ||
| 31 | kop->crk_param[2].crp_nbits = g_len * 8; | ||
| 32 | @@ -3419,7 +3419,7 @@ static int cryptodev_dh_keygen(DH *dh) | ||
| 33 | kop.crk_op = CRK_DH_GENERATE_KEY; | ||
| 34 | if (bn2crparam(dh->p, &kop.crk_param[0])) | ||
| 35 | goto sw_try; | ||
| 36 | - if (bn2crparam(dh->q, &kop.crk_param[1])) | ||
| 37 | + if (!dh->q || bn2crparam(dh->q, &kop.crk_param[1])) | ||
| 38 | goto sw_try; | ||
| 39 | kop.crk_param[2].crp_p = g; | ||
| 40 | kop.crk_param[2].crp_nbits = g_len * 8; | ||
| 41 | -- | ||
| 42 | 2.3.5 | ||
| 43 | |||
diff --git a/recipes-connectivity/openssl/openssl-qoriq/qoriq/0014-cryptodev-add-support-for-aes-gcm-algorithm-offloadi.patch b/recipes-connectivity/openssl/openssl-qoriq/qoriq/0014-cryptodev-add-support-for-aes-gcm-algorithm-offloadi.patch new file mode 100644 index 000000000..5a8c2d290 --- /dev/null +++ b/recipes-connectivity/openssl/openssl-qoriq/qoriq/0014-cryptodev-add-support-for-aes-gcm-algorithm-offloadi.patch | |||
| @@ -0,0 +1,321 @@ | |||
| 1 | From 317e3d9870097e6b115dd8c9a13ccb5e5ca76f2e Mon Sep 17 00:00:00 2001 | ||
| 2 | From: Cristian Stoica <cristian.stoica@freescale.com> | ||
| 3 | Date: Mon, 16 Jun 2014 14:06:21 +0300 | ||
| 4 | Subject: [PATCH 14/48] cryptodev: add support for aes-gcm algorithm offloading | ||
| 5 | |||
| 6 | Signed-off-by: Cristian Stoica <cristian.stoica@freescale.com> | ||
| 7 | --- | ||
| 8 | apps/speed.c | 6 +- | ||
| 9 | crypto/engine/eng_cryptodev.c | 236 +++++++++++++++++++++++++++++++++++++++++- | ||
| 10 | 2 files changed, 240 insertions(+), 2 deletions(-) | ||
| 11 | |||
| 12 | diff --git a/apps/speed.c b/apps/speed.c | ||
| 13 | index 95adcc1..e5e609b 100644 | ||
| 14 | --- a/apps/speed.c | ||
| 15 | +++ b/apps/speed.c | ||
| 16 | @@ -226,7 +226,11 @@ | ||
| 17 | # endif | ||
| 18 | |||
| 19 | # undef BUFSIZE | ||
| 20 | -# define BUFSIZE ((long)1024*8+1) | ||
| 21 | +/* The buffer overhead allows GCM tag at the end of the encrypted data. This | ||
| 22 | + avoids buffer overflows from cryptodev since Linux kernel GCM | ||
| 23 | + implementation allways adds the tag - unlike e_aes.c:aes_gcm_cipher() | ||
| 24 | + which doesn't */ | ||
| 25 | +#define BUFSIZE ((long)1024*8 + EVP_GCM_TLS_TAG_LEN) | ||
| 26 | static volatile int run = 0; | ||
| 27 | |||
| 28 | static int mr = 0; | ||
| 29 | diff --git a/crypto/engine/eng_cryptodev.c b/crypto/engine/eng_cryptodev.c | ||
| 30 | index 4929ae6..d2cdca0 100644 | ||
| 31 | --- a/crypto/engine/eng_cryptodev.c | ||
| 32 | +++ b/crypto/engine/eng_cryptodev.c | ||
| 33 | @@ -2,6 +2,7 @@ | ||
| 34 | * Copyright (c) 2002 Bob Beck <beck@openbsd.org> | ||
| 35 | * Copyright (c) 2002 Theo de Raadt | ||
| 36 | * Copyright (c) 2002 Markus Friedl | ||
| 37 | + * Copyright (c) 2013-2014 Freescale Semiconductor, Inc. | ||
| 38 | * All rights reserved. | ||
| 39 | * | ||
| 40 | * Redistribution and use in source and binary forms, with or without | ||
| 41 | @@ -77,8 +78,10 @@ struct dev_crypto_state { | ||
| 42 | struct session_op d_sess; | ||
| 43 | int d_fd; | ||
| 44 | unsigned char *aad; | ||
| 45 | - unsigned int aad_len; | ||
| 46 | + int aad_len; | ||
| 47 | unsigned int len; | ||
| 48 | + unsigned char *iv; | ||
| 49 | + int ivlen; | ||
| 50 | # ifdef USE_CRYPTODEV_DIGESTS | ||
| 51 | char dummy_mac_key[HASH_MAX_LEN]; | ||
| 52 | unsigned char digest_res[HASH_MAX_LEN]; | ||
| 53 | @@ -287,6 +290,9 @@ static struct { | ||
| 54 | CRYPTO_TLS10_AES_CBC_HMAC_SHA1, NID_aes_256_cbc_hmac_sha1, 16, 32, 20 | ||
| 55 | }, | ||
| 56 | { | ||
| 57 | + CRYPTO_AES_GCM, NID_aes_128_gcm, 16, 16, 0 | ||
| 58 | + }, | ||
| 59 | + { | ||
| 60 | 0, NID_undef, 0, 0, 0 | ||
| 61 | }, | ||
| 62 | }; | ||
| 63 | @@ -325,6 +331,22 @@ static struct { | ||
| 64 | }; | ||
| 65 | # endif | ||
| 66 | |||
| 67 | +/* increment counter (64-bit int) by 1 */ | ||
| 68 | +static void ctr64_inc(unsigned char *counter) | ||
| 69 | +{ | ||
| 70 | + int n = 8; | ||
| 71 | + unsigned char c; | ||
| 72 | + | ||
| 73 | + do { | ||
| 74 | + --n; | ||
| 75 | + c = counter[n]; | ||
| 76 | + ++c; | ||
| 77 | + counter[n] = c; | ||
| 78 | + if (c) | ||
| 79 | + return; | ||
| 80 | + } while (n); | ||
| 81 | +} | ||
| 82 | + | ||
| 83 | /* | ||
| 84 | * Return a fd if /dev/crypto seems usable, 0 otherwise. | ||
| 85 | */ | ||
| 86 | @@ -807,6 +829,199 @@ static int cryptodev_cbc_hmac_sha1_ctrl(EVP_CIPHER_CTX *ctx, int type, | ||
| 87 | } | ||
| 88 | } | ||
| 89 | |||
| 90 | +static int cryptodev_init_gcm_key(EVP_CIPHER_CTX *ctx, | ||
| 91 | + const unsigned char *key, | ||
| 92 | + const unsigned char *iv, int enc) | ||
| 93 | +{ | ||
| 94 | + struct dev_crypto_state *state = ctx->cipher_data; | ||
| 95 | + struct session_op *sess = &state->d_sess; | ||
| 96 | + int cipher = -1, i; | ||
| 97 | + if (!iv && !key) | ||
| 98 | + return 1; | ||
| 99 | + | ||
| 100 | + if (iv) | ||
| 101 | + memcpy(ctx->iv, iv, ctx->cipher->iv_len); | ||
| 102 | + | ||
| 103 | + for (i = 0; ciphers[i].id; i++) | ||
| 104 | + if (ctx->cipher->nid == ciphers[i].nid && | ||
| 105 | + ctx->cipher->iv_len <= ciphers[i].ivmax && | ||
| 106 | + ctx->key_len == ciphers[i].keylen) { | ||
| 107 | + cipher = ciphers[i].id; | ||
| 108 | + break; | ||
| 109 | + } | ||
| 110 | + | ||
| 111 | + if (!ciphers[i].id) { | ||
| 112 | + state->d_fd = -1; | ||
| 113 | + return 0; | ||
| 114 | + } | ||
| 115 | + | ||
| 116 | + memset(sess, 0, sizeof(struct session_op)); | ||
| 117 | + | ||
| 118 | + if ((state->d_fd = get_dev_crypto()) < 0) | ||
| 119 | + return 0; | ||
| 120 | + | ||
| 121 | + sess->key = (unsigned char *)key; | ||
| 122 | + sess->keylen = ctx->key_len; | ||
| 123 | + sess->cipher = cipher; | ||
| 124 | + | ||
| 125 | + if (ioctl(state->d_fd, CIOCGSESSION, sess) == -1) { | ||
| 126 | + put_dev_crypto(state->d_fd); | ||
| 127 | + state->d_fd = -1; | ||
| 128 | + return 0; | ||
| 129 | + } | ||
| 130 | + return 1; | ||
| 131 | +} | ||
| 132 | + | ||
| 133 | +static int cryptodev_gcm_tls_cipher(EVP_CIPHER_CTX *ctx, unsigned char *out, | ||
| 134 | + const unsigned char *in, size_t len) | ||
| 135 | +{ | ||
| 136 | + struct crypt_auth_op cryp = { 0 }; | ||
| 137 | + struct dev_crypto_state *state = ctx->cipher_data; | ||
| 138 | + struct session_op *sess = &state->d_sess; | ||
| 139 | + int rv = len; | ||
| 140 | + | ||
| 141 | + if (EVP_CIPHER_CTX_ctrl(ctx, ctx->encrypt ? | ||
| 142 | + EVP_CTRL_GCM_IV_GEN : EVP_CTRL_GCM_SET_IV_INV, | ||
| 143 | + EVP_GCM_TLS_EXPLICIT_IV_LEN, out) <= 0) | ||
| 144 | + return 0; | ||
| 145 | + | ||
| 146 | + in += EVP_GCM_TLS_EXPLICIT_IV_LEN; | ||
| 147 | + out += EVP_GCM_TLS_EXPLICIT_IV_LEN; | ||
| 148 | + len -= EVP_GCM_TLS_EXPLICIT_IV_LEN; | ||
| 149 | + | ||
| 150 | + if (ctx->encrypt) { | ||
| 151 | + len -= EVP_GCM_TLS_TAG_LEN; | ||
| 152 | + } | ||
| 153 | + cryp.ses = sess->ses; | ||
| 154 | + cryp.len = len; | ||
| 155 | + cryp.src = (unsigned char *)in; | ||
| 156 | + cryp.dst = out; | ||
| 157 | + cryp.auth_src = state->aad; | ||
| 158 | + cryp.auth_len = state->aad_len; | ||
| 159 | + cryp.iv = ctx->iv; | ||
| 160 | + cryp.op = ctx->encrypt ? COP_ENCRYPT : COP_DECRYPT; | ||
| 161 | + | ||
| 162 | + if (ioctl(state->d_fd, CIOCAUTHCRYPT, &cryp) == -1) { | ||
| 163 | + return 0; | ||
| 164 | + } | ||
| 165 | + | ||
| 166 | + if (ctx->encrypt) | ||
| 167 | + ctr64_inc(state->iv + state->ivlen - 8); | ||
| 168 | + else | ||
| 169 | + rv = len - EVP_GCM_TLS_TAG_LEN; | ||
| 170 | + | ||
| 171 | + return rv; | ||
| 172 | +} | ||
| 173 | + | ||
| 174 | +static int cryptodev_gcm_cipher(EVP_CIPHER_CTX *ctx, unsigned char *out, | ||
| 175 | + const unsigned char *in, size_t len) | ||
| 176 | +{ | ||
| 177 | + struct crypt_auth_op cryp; | ||
| 178 | + struct dev_crypto_state *state = ctx->cipher_data; | ||
| 179 | + struct session_op *sess = &state->d_sess; | ||
| 180 | + | ||
| 181 | + if (state->d_fd < 0) | ||
| 182 | + return 0; | ||
| 183 | + | ||
| 184 | + if ((len % ctx->cipher->block_size) != 0) | ||
| 185 | + return 0; | ||
| 186 | + | ||
| 187 | + if (state->aad_len >= 0) | ||
| 188 | + return cryptodev_gcm_tls_cipher(ctx, out, in, len); | ||
| 189 | + | ||
| 190 | + memset(&cryp, 0, sizeof(cryp)); | ||
| 191 | + | ||
| 192 | + cryp.ses = sess->ses; | ||
| 193 | + cryp.len = len; | ||
| 194 | + cryp.src = (unsigned char *)in; | ||
| 195 | + cryp.dst = out; | ||
| 196 | + cryp.auth_src = NULL; | ||
| 197 | + cryp.auth_len = 0; | ||
| 198 | + cryp.iv = ctx->iv; | ||
| 199 | + cryp.op = ctx->encrypt ? COP_ENCRYPT : COP_DECRYPT; | ||
| 200 | + | ||
| 201 | + if (ioctl(state->d_fd, CIOCAUTHCRYPT, &cryp) == -1) { | ||
| 202 | + return 0; | ||
| 203 | + } | ||
| 204 | + | ||
| 205 | + return len; | ||
| 206 | +} | ||
| 207 | + | ||
| 208 | +static int cryptodev_gcm_ctrl(EVP_CIPHER_CTX *ctx, int type, int arg, | ||
| 209 | + void *ptr) | ||
| 210 | +{ | ||
| 211 | + struct dev_crypto_state *state = ctx->cipher_data; | ||
| 212 | + switch (type) { | ||
| 213 | + case EVP_CTRL_INIT: | ||
| 214 | + { | ||
| 215 | + state->ivlen = ctx->cipher->iv_len; | ||
| 216 | + state->iv = ctx->iv; | ||
| 217 | + state->aad_len = -1; | ||
| 218 | + return 1; | ||
| 219 | + } | ||
| 220 | + case EVP_CTRL_GCM_SET_IV_FIXED: | ||
| 221 | + { | ||
| 222 | + /* Special case: -1 length restores whole IV */ | ||
| 223 | + if (arg == -1) { | ||
| 224 | + memcpy(state->iv, ptr, state->ivlen); | ||
| 225 | + return 1; | ||
| 226 | + } | ||
| 227 | + /* | ||
| 228 | + * Fixed field must be at least 4 bytes and invocation field at | ||
| 229 | + * least 8. | ||
| 230 | + */ | ||
| 231 | + if ((arg < 4) || (state->ivlen - arg) < 8) | ||
| 232 | + return 0; | ||
| 233 | + if (arg) | ||
| 234 | + memcpy(state->iv, ptr, arg); | ||
| 235 | + if (ctx->encrypt && | ||
| 236 | + RAND_bytes(state->iv + arg, state->ivlen - arg) <= 0) | ||
| 237 | + return 0; | ||
| 238 | + return 1; | ||
| 239 | + } | ||
| 240 | + case EVP_CTRL_AEAD_TLS1_AAD: | ||
| 241 | + { | ||
| 242 | + unsigned int len; | ||
| 243 | + if (arg != 13) | ||
| 244 | + return 0; | ||
| 245 | + | ||
| 246 | + memcpy(ctx->buf, ptr, arg); | ||
| 247 | + len = ctx->buf[arg - 2] << 8 | ctx->buf[arg - 1]; | ||
| 248 | + | ||
| 249 | + /* Correct length for explicit IV */ | ||
| 250 | + len -= EVP_GCM_TLS_EXPLICIT_IV_LEN; | ||
| 251 | + | ||
| 252 | + /* If decrypting correct for tag too */ | ||
| 253 | + if (!ctx->encrypt) | ||
| 254 | + len -= EVP_GCM_TLS_TAG_LEN; | ||
| 255 | + | ||
| 256 | + ctx->buf[arg - 2] = len >> 8; | ||
| 257 | + ctx->buf[arg - 1] = len & 0xff; | ||
| 258 | + | ||
| 259 | + state->aad = ctx->buf; | ||
| 260 | + state->aad_len = arg; | ||
| 261 | + state->len = len; | ||
| 262 | + | ||
| 263 | + /* Extra padding: tag appended to record */ | ||
| 264 | + return EVP_GCM_TLS_TAG_LEN; | ||
| 265 | + } | ||
| 266 | + case EVP_CTRL_GCM_SET_IV_INV: | ||
| 267 | + { | ||
| 268 | + if (ctx->encrypt) | ||
| 269 | + return 0; | ||
| 270 | + memcpy(state->iv + state->ivlen - arg, ptr, arg); | ||
| 271 | + return 1; | ||
| 272 | + } | ||
| 273 | + case EVP_CTRL_GCM_IV_GEN: | ||
| 274 | + if (arg <= 0 || arg > state->ivlen) | ||
| 275 | + arg = state->ivlen; | ||
| 276 | + memcpy(ptr, state->iv + state->ivlen - arg, arg); | ||
| 277 | + return 1; | ||
| 278 | + default: | ||
| 279 | + return -1; | ||
| 280 | + } | ||
| 281 | +} | ||
| 282 | + | ||
| 283 | /* | ||
| 284 | * libcrypto EVP stuff - this is how we get wired to EVP so the engine | ||
| 285 | * gets called when libcrypto requests a cipher NID. | ||
| 286 | @@ -947,6 +1162,22 @@ const EVP_CIPHER cryptodev_aes_256_cbc_hmac_sha1 = { | ||
| 287 | NULL | ||
| 288 | }; | ||
| 289 | |||
| 290 | +const EVP_CIPHER cryptodev_aes_128_gcm = { | ||
| 291 | + NID_aes_128_gcm, | ||
| 292 | + 1, 16, 12, | ||
| 293 | + EVP_CIPH_GCM_MODE | EVP_CIPH_FLAG_AEAD_CIPHER | EVP_CIPH_FLAG_DEFAULT_ASN1 | ||
| 294 | + | EVP_CIPH_CUSTOM_IV | EVP_CIPH_FLAG_CUSTOM_CIPHER | ||
| 295 | + | EVP_CIPH_ALWAYS_CALL_INIT | EVP_CIPH_CTRL_INIT, | ||
| 296 | + cryptodev_init_gcm_key, | ||
| 297 | + cryptodev_gcm_cipher, | ||
| 298 | + cryptodev_cleanup, | ||
| 299 | + sizeof(struct dev_crypto_state), | ||
| 300 | + EVP_CIPHER_set_asn1_iv, | ||
| 301 | + EVP_CIPHER_get_asn1_iv, | ||
| 302 | + cryptodev_gcm_ctrl, | ||
| 303 | + NULL | ||
| 304 | +}; | ||
| 305 | + | ||
| 306 | # ifdef CRYPTO_AES_CTR | ||
| 307 | const EVP_CIPHER cryptodev_aes_ctr = { | ||
| 308 | NID_aes_128_ctr, | ||
| 309 | @@ -1041,6 +1272,9 @@ cryptodev_engine_ciphers(ENGINE *e, const EVP_CIPHER **cipher, | ||
| 310 | case NID_aes_256_cbc_hmac_sha1: | ||
| 311 | *cipher = &cryptodev_aes_256_cbc_hmac_sha1; | ||
| 312 | break; | ||
| 313 | + case NID_aes_128_gcm: | ||
| 314 | + *cipher = &cryptodev_aes_128_gcm; | ||
| 315 | + break; | ||
| 316 | default: | ||
| 317 | *cipher = NULL; | ||
| 318 | break; | ||
| 319 | -- | ||
| 320 | 2.7.0 | ||
| 321 | |||
diff --git a/recipes-connectivity/openssl/openssl-qoriq/qoriq/0015-SW-Backoff-mechanism-for-dsa-keygen.patch b/recipes-connectivity/openssl/openssl-qoriq/qoriq/0015-SW-Backoff-mechanism-for-dsa-keygen.patch deleted file mode 100644 index 59330a1e0..000000000 --- a/recipes-connectivity/openssl/openssl-qoriq/qoriq/0015-SW-Backoff-mechanism-for-dsa-keygen.patch +++ /dev/null | |||
| @@ -1,53 +0,0 @@ | |||
| 1 | From 10be401a33e6ebcc325d6747914c70595cd53d0a Mon Sep 17 00:00:00 2001 | ||
| 2 | From: Yashpal Dutta <yashpal.dutta@freescale.com> | ||
| 3 | Date: Thu, 24 Apr 2014 00:35:34 +0545 | ||
| 4 | Subject: [PATCH 15/26] SW Backoff mechanism for dsa keygen | ||
| 5 | |||
| 6 | Upstream-status: Pending | ||
| 7 | |||
| 8 | DSA Keygen is not handled in default openssl dsa method. Due to | ||
| 9 | same null function pointer in SW DSA method, the backoff for dsa | ||
| 10 | keygen gives segmentation fault. | ||
| 11 | |||
| 12 | Signed-off-by: Yashpal Dutta <yashpal.dutta@freescale.com> | ||
| 13 | Tested-by: Cristian Stoica <cristian.stoica@freescale.com> | ||
| 14 | --- | ||
| 15 | crypto/engine/eng_cryptodev.c | 12 ++++++++---- | ||
| 16 | 1 file changed, 8 insertions(+), 4 deletions(-) | ||
| 17 | |||
| 18 | diff --git a/crypto/engine/eng_cryptodev.c b/crypto/engine/eng_cryptodev.c | ||
| 19 | index 6d69336..dab8fea 100644 | ||
| 20 | --- a/crypto/engine/eng_cryptodev.c | ||
| 21 | +++ b/crypto/engine/eng_cryptodev.c | ||
| 22 | @@ -2069,8 +2069,10 @@ static int cryptodev_dsa_keygen(DSA *dsa) | ||
| 23 | return ret; | ||
| 24 | sw_try: | ||
| 25 | { | ||
| 26 | - const DSA_METHOD *meth = DSA_OpenSSL(); | ||
| 27 | - ret = (meth->dsa_keygen)(dsa); | ||
| 28 | + const DSA_METHOD *meth = dsa->meth; | ||
| 29 | + dsa->meth = DSA_OpenSSL(); | ||
| 30 | + ret = DSA_generate_key(dsa); | ||
| 31 | + dsa->meth = meth; | ||
| 32 | } | ||
| 33 | return ret; | ||
| 34 | } | ||
| 35 | @@ -2124,11 +2126,13 @@ static int cryptodev_dsa_keygen_async(DSA *dsa, struct pkc_cookie_s *cookie) | ||
| 36 | return ret; | ||
| 37 | sw_try: | ||
| 38 | { | ||
| 39 | - const DSA_METHOD *meth = DSA_OpenSSL(); | ||
| 40 | + const DSA_METHOD *meth = dsa->meth; | ||
| 41 | |||
| 42 | + dsa->meth = DSA_OpenSSL(); | ||
| 43 | if (kop) | ||
| 44 | free(kop); | ||
| 45 | - ret = (meth->dsa_keygen)(dsa); | ||
| 46 | + ret = DSA_generate_key(dsa); | ||
| 47 | + dsa->meth = meth; | ||
| 48 | cookie->pkc_callback(cookie, 0); | ||
| 49 | } | ||
| 50 | return ret; | ||
| 51 | -- | ||
| 52 | 2.3.5 | ||
| 53 | |||
diff --git a/recipes-connectivity/openssl/openssl-qoriq/qoriq/0015-eng_cryptodev-extend-TLS-offload-with-3des_cbc_hmac_.patch b/recipes-connectivity/openssl/openssl-qoriq/qoriq/0015-eng_cryptodev-extend-TLS-offload-with-3des_cbc_hmac_.patch new file mode 100644 index 000000000..623c58b98 --- /dev/null +++ b/recipes-connectivity/openssl/openssl-qoriq/qoriq/0015-eng_cryptodev-extend-TLS-offload-with-3des_cbc_hmac_.patch | |||
| @@ -0,0 +1,199 @@ | |||
| 1 | From 7dd6b35c35b027be8ef0ef2e29a949bc4ce96bbd Mon Sep 17 00:00:00 2001 | ||
| 2 | From: Tudor Ambarus <tudor.ambarus@freescale.com> | ||
| 3 | Date: Fri, 9 May 2014 17:54:06 +0300 | ||
| 4 | Subject: [PATCH 15/48] eng_cryptodev: extend TLS offload with | ||
| 5 | 3des_cbc_hmac_sha1 | ||
| 6 | |||
| 7 | Both obj_mac.h and obj_dat.h were generated using the scripts | ||
| 8 | from crypto/objects: | ||
| 9 | |||
| 10 | $ cd crypto/objects | ||
| 11 | $ perl objects.pl objects.txt obj_mac.num obj_mac.h | ||
| 12 | $ perl obj_dat.pl obj_mac.h obj_dat.h | ||
| 13 | |||
| 14 | Signed-off-by: Tudor Ambarus <tudor.ambarus@freescale.com> | ||
| 15 | Signed-off-by: Cristian Stoica <cristian.stoica@freescale.com> | ||
| 16 | --- | ||
| 17 | crypto/engine/eng_cryptodev.c | 26 ++++++++++++++++++++++++++ | ||
| 18 | crypto/objects/obj_dat.h | 10 +++++++--- | ||
| 19 | crypto/objects/obj_mac.h | 4 ++++ | ||
| 20 | crypto/objects/obj_mac.num | 1 + | ||
| 21 | crypto/objects/objects.txt | 1 + | ||
| 22 | ssl/ssl_ciph.c | 4 ++++ | ||
| 23 | 6 files changed, 43 insertions(+), 3 deletions(-) | ||
| 24 | |||
| 25 | diff --git a/crypto/engine/eng_cryptodev.c b/crypto/engine/eng_cryptodev.c | ||
| 26 | index d2cdca0..8f73a18 100644 | ||
| 27 | --- a/crypto/engine/eng_cryptodev.c | ||
| 28 | +++ b/crypto/engine/eng_cryptodev.c | ||
| 29 | @@ -132,6 +132,7 @@ static int cryptodev_dh_compute_key(unsigned char *key, const BIGNUM *pub_key, | ||
| 30 | static int cryptodev_ctrl(ENGINE *e, int cmd, long i, void *p, | ||
| 31 | void (*f) (void)); | ||
| 32 | void ENGINE_load_cryptodev(void); | ||
| 33 | +const EVP_CIPHER cryptodev_3des_cbc_hmac_sha1; | ||
| 34 | const EVP_CIPHER cryptodev_aes_128_cbc_hmac_sha1; | ||
| 35 | const EVP_CIPHER cryptodev_aes_256_cbc_hmac_sha1; | ||
| 36 | |||
| 37 | @@ -284,6 +285,9 @@ static struct { | ||
| 38 | CRYPTO_SKIPJACK_CBC, NID_undef, 0, 0, 0 | ||
| 39 | }, | ||
| 40 | { | ||
| 41 | + CRYPTO_TLS10_3DES_CBC_HMAC_SHA1, NID_des_ede3_cbc_hmac_sha1, 8, 24, 20 | ||
| 42 | + }, | ||
| 43 | + { | ||
| 44 | CRYPTO_TLS10_AES_CBC_HMAC_SHA1, NID_aes_128_cbc_hmac_sha1, 16, 16, 20 | ||
| 45 | }, | ||
| 46 | { | ||
| 47 | @@ -519,6 +523,9 @@ static int cryptodev_usable_ciphers(const int **nids) | ||
| 48 | case NID_aes_256_cbc_hmac_sha1: | ||
| 49 | EVP_add_cipher(&cryptodev_aes_256_cbc_hmac_sha1); | ||
| 50 | break; | ||
| 51 | + case NID_des_ede3_cbc_hmac_sha1: | ||
| 52 | + EVP_add_cipher(&cryptodev_3des_cbc_hmac_sha1); | ||
| 53 | + break; | ||
| 54 | } | ||
| 55 | } | ||
| 56 | return count; | ||
| 57 | @@ -623,6 +630,7 @@ static int cryptodev_aead_cipher(EVP_CIPHER_CTX *ctx, unsigned char *out, | ||
| 58 | switch (ctx->cipher->nid) { | ||
| 59 | case NID_aes_128_cbc_hmac_sha1: | ||
| 60 | case NID_aes_256_cbc_hmac_sha1: | ||
| 61 | + case NID_des_ede3_cbc_hmac_sha1: | ||
| 62 | cryp.flags = COP_FLAG_AEAD_TLS_TYPE; | ||
| 63 | } | ||
| 64 | cryp.ses = sess->ses; | ||
| 65 | @@ -813,6 +821,7 @@ static int cryptodev_cbc_hmac_sha1_ctrl(EVP_CIPHER_CTX *ctx, int type, | ||
| 66 | switch (ctx->cipher->nid) { | ||
| 67 | case NID_aes_128_cbc_hmac_sha1: | ||
| 68 | case NID_aes_256_cbc_hmac_sha1: | ||
| 69 | + case NID_des_ede3_cbc_hmac_sha1: | ||
| 70 | maclen = SHA_DIGEST_LENGTH; | ||
| 71 | } | ||
| 72 | |||
| 73 | @@ -1134,6 +1143,20 @@ const EVP_CIPHER cryptodev_aes_256_cbc = { | ||
| 74 | NULL | ||
| 75 | }; | ||
| 76 | |||
| 77 | +const EVP_CIPHER cryptodev_3des_cbc_hmac_sha1 = { | ||
| 78 | + NID_des_ede3_cbc_hmac_sha1, | ||
| 79 | + 8, 24, 8, | ||
| 80 | + EVP_CIPH_CBC_MODE | EVP_CIPH_FLAG_AEAD_CIPHER, | ||
| 81 | + cryptodev_init_aead_key, | ||
| 82 | + cryptodev_aead_cipher, | ||
| 83 | + cryptodev_cleanup, | ||
| 84 | + sizeof(struct dev_crypto_state), | ||
| 85 | + EVP_CIPHER_set_asn1_iv, | ||
| 86 | + EVP_CIPHER_get_asn1_iv, | ||
| 87 | + cryptodev_cbc_hmac_sha1_ctrl, | ||
| 88 | + NULL | ||
| 89 | +}; | ||
| 90 | + | ||
| 91 | const EVP_CIPHER cryptodev_aes_128_cbc_hmac_sha1 = { | ||
| 92 | NID_aes_128_cbc_hmac_sha1, | ||
| 93 | 16, 16, 16, | ||
| 94 | @@ -1255,6 +1278,9 @@ cryptodev_engine_ciphers(ENGINE *e, const EVP_CIPHER **cipher, | ||
| 95 | case NID_aes_256_cbc: | ||
| 96 | *cipher = &cryptodev_aes_256_cbc; | ||
| 97 | break; | ||
| 98 | + case NID_des_ede3_cbc_hmac_sha1: | ||
| 99 | + *cipher = &cryptodev_3des_cbc_hmac_sha1; | ||
| 100 | + break; | ||
| 101 | # ifdef CRYPTO_AES_CTR | ||
| 102 | case NID_aes_128_ctr: | ||
| 103 | *cipher = &cryptodev_aes_ctr; | ||
| 104 | diff --git a/crypto/objects/obj_dat.h b/crypto/objects/obj_dat.h | ||
| 105 | index b7e3cf2..35d1abc 100644 | ||
| 106 | --- a/crypto/objects/obj_dat.h | ||
| 107 | +++ b/crypto/objects/obj_dat.h | ||
| 108 | @@ -62,9 +62,9 @@ | ||
| 109 | * [including the GNU Public Licence.] | ||
| 110 | */ | ||
| 111 | |||
| 112 | -#define NUM_NID 958 | ||
| 113 | -#define NUM_SN 951 | ||
| 114 | -#define NUM_LN 951 | ||
| 115 | +#define NUM_NID 959 | ||
| 116 | +#define NUM_SN 952 | ||
| 117 | +#define NUM_LN 952 | ||
| 118 | #define NUM_OBJ 890 | ||
| 119 | |||
| 120 | static const unsigned char lvalues[6255]={ | ||
| 121 | @@ -2514,6 +2514,8 @@ static const ASN1_OBJECT nid_objs[NUM_NID]={ | ||
| 122 | NID_jurisdictionStateOrProvinceName,11,&(lvalues[6232]),0}, | ||
| 123 | {"jurisdictionC","jurisdictionCountryName", | ||
| 124 | NID_jurisdictionCountryName,11,&(lvalues[6243]),0}, | ||
| 125 | +{"DES-EDE3-CBC-HMAC-SHA1","des-ede3-cbc-hmac-sha1", | ||
| 126 | + NID_des_ede3_cbc_hmac_sha1,0,NULL,0}, | ||
| 127 | }; | ||
| 128 | |||
| 129 | static const unsigned int sn_objs[NUM_SN]={ | ||
| 130 | @@ -2592,6 +2594,7 @@ static const unsigned int sn_objs[NUM_SN]={ | ||
| 131 | 62, /* "DES-EDE-OFB" */ | ||
| 132 | 33, /* "DES-EDE3" */ | ||
| 133 | 44, /* "DES-EDE3-CBC" */ | ||
| 134 | +958, /* "DES-EDE3-CBC-HMAC-SHA1" */ | ||
| 135 | 61, /* "DES-EDE3-CFB" */ | ||
| 136 | 658, /* "DES-EDE3-CFB1" */ | ||
| 137 | 659, /* "DES-EDE3-CFB8" */ | ||
| 138 | @@ -3760,6 +3763,7 @@ static const unsigned int ln_objs[NUM_LN]={ | ||
| 139 | 62, /* "des-ede-ofb" */ | ||
| 140 | 33, /* "des-ede3" */ | ||
| 141 | 44, /* "des-ede3-cbc" */ | ||
| 142 | +958, /* "des-ede3-cbc-hmac-sha1" */ | ||
| 143 | 61, /* "des-ede3-cfb" */ | ||
| 144 | 658, /* "des-ede3-cfb1" */ | ||
| 145 | 659, /* "des-ede3-cfb8" */ | ||
| 146 | diff --git a/crypto/objects/obj_mac.h b/crypto/objects/obj_mac.h | ||
| 147 | index 779c309..cb318bc 100644 | ||
| 148 | --- a/crypto/objects/obj_mac.h | ||
| 149 | +++ b/crypto/objects/obj_mac.h | ||
| 150 | @@ -4047,6 +4047,10 @@ | ||
| 151 | #define LN_aes_256_cbc_hmac_sha256 "aes-256-cbc-hmac-sha256" | ||
| 152 | #define NID_aes_256_cbc_hmac_sha256 950 | ||
| 153 | |||
| 154 | +#define SN_des_ede3_cbc_hmac_sha1 "DES-EDE3-CBC-HMAC-SHA1" | ||
| 155 | +#define LN_des_ede3_cbc_hmac_sha1 "des-ede3-cbc-hmac-sha1" | ||
| 156 | +#define NID_des_ede3_cbc_hmac_sha1 958 | ||
| 157 | + | ||
| 158 | #define SN_dhpublicnumber "dhpublicnumber" | ||
| 159 | #define LN_dhpublicnumber "X9.42 DH" | ||
| 160 | #define NID_dhpublicnumber 920 | ||
| 161 | diff --git a/crypto/objects/obj_mac.num b/crypto/objects/obj_mac.num | ||
| 162 | index 8e5ea83..02d1bb8 100644 | ||
| 163 | --- a/crypto/objects/obj_mac.num | ||
| 164 | +++ b/crypto/objects/obj_mac.num | ||
| 165 | @@ -955,3 +955,4 @@ ct_cert_scts 954 | ||
| 166 | jurisdictionLocalityName 955 | ||
| 167 | jurisdictionStateOrProvinceName 956 | ||
| 168 | jurisdictionCountryName 957 | ||
| 169 | +des_ede3_cbc_hmac_sha1 958 | ||
| 170 | diff --git a/crypto/objects/objects.txt b/crypto/objects/objects.txt | ||
| 171 | index b57aabb..4e1ff18 100644 | ||
| 172 | --- a/crypto/objects/objects.txt | ||
| 173 | +++ b/crypto/objects/objects.txt | ||
| 174 | @@ -1294,6 +1294,7 @@ kisa 1 6 : SEED-OFB : seed-ofb | ||
| 175 | : AES-128-CBC-HMAC-SHA256 : aes-128-cbc-hmac-sha256 | ||
| 176 | : AES-192-CBC-HMAC-SHA256 : aes-192-cbc-hmac-sha256 | ||
| 177 | : AES-256-CBC-HMAC-SHA256 : aes-256-cbc-hmac-sha256 | ||
| 178 | + : DES-EDE3-CBC-HMAC-SHA1 : des-ede3-cbc-hmac-sha1 | ||
| 179 | |||
| 180 | ISO-US 10046 2 1 : dhpublicnumber : X9.42 DH | ||
| 181 | |||
| 182 | diff --git a/ssl/ssl_ciph.c b/ssl/ssl_ciph.c | ||
| 183 | index 302464e..a379273 100644 | ||
| 184 | --- a/ssl/ssl_ciph.c | ||
| 185 | +++ b/ssl/ssl_ciph.c | ||
| 186 | @@ -668,6 +668,10 @@ int ssl_cipher_get_evp(const SSL_SESSION *s, const EVP_CIPHER **enc, | ||
| 187 | c->algorithm_mac == SSL_SHA256 && | ||
| 188 | (evp = EVP_get_cipherbyname("AES-256-CBC-HMAC-SHA256"))) | ||
| 189 | *enc = evp, *md = NULL; | ||
| 190 | + else if (c->algorithm_enc == SSL_3DES && | ||
| 191 | + c->algorithm_mac == SSL_SHA1 && | ||
| 192 | + (evp = EVP_get_cipherbyname("DES-EDE3-CBC-HMAC-SHA1"))) | ||
| 193 | + *enc = evp, *md = NULL; | ||
| 194 | return (1); | ||
| 195 | } else | ||
| 196 | return (0); | ||
| 197 | -- | ||
| 198 | 2.7.0 | ||
| 199 | |||
diff --git a/recipes-connectivity/openssl/openssl-qoriq/qoriq/0016-Fixed-DH-keygen-pair-generator.patch b/recipes-connectivity/openssl/openssl-qoriq/qoriq/0016-Fixed-DH-keygen-pair-generator.patch deleted file mode 100644 index 8923cb639..000000000 --- a/recipes-connectivity/openssl/openssl-qoriq/qoriq/0016-Fixed-DH-keygen-pair-generator.patch +++ /dev/null | |||
| @@ -1,100 +0,0 @@ | |||
| 1 | From d2c868c6370bcc0d0a254e641907da2cdf992d62 Mon Sep 17 00:00:00 2001 | ||
| 2 | From: Yashpal Dutta <yashpal.dutta@freescale.com> | ||
| 3 | Date: Thu, 1 May 2014 06:35:45 +0545 | ||
| 4 | Subject: [PATCH 16/26] Fixed DH keygen pair generator | ||
| 5 | |||
| 6 | Upstream-status: Pending | ||
| 7 | |||
| 8 | Wrong Padding results into keygen length error | ||
| 9 | |||
| 10 | Signed-off-by: Yashpal Dutta <yashpal.dutta@freescale.com> | ||
| 11 | Tested-by: Cristian Stoica <cristian.stoica@freescale.com> | ||
| 12 | --- | ||
| 13 | crypto/engine/eng_cryptodev.c | 50 ++++++++++++++++++++++++++++--------------- | ||
| 14 | 1 file changed, 33 insertions(+), 17 deletions(-) | ||
| 15 | |||
| 16 | diff --git a/crypto/engine/eng_cryptodev.c b/crypto/engine/eng_cryptodev.c | ||
| 17 | index dab8fea..13d924f 100644 | ||
| 18 | --- a/crypto/engine/eng_cryptodev.c | ||
| 19 | +++ b/crypto/engine/eng_cryptodev.c | ||
| 20 | @@ -3396,44 +3396,60 @@ sw_try: | ||
| 21 | static int cryptodev_dh_keygen(DH *dh) | ||
| 22 | { | ||
| 23 | struct crypt_kop kop; | ||
| 24 | - int ret = 1, g_len; | ||
| 25 | - unsigned char *g = NULL; | ||
| 26 | + int ret = 1, q_len = 0; | ||
| 27 | + unsigned char *q = NULL, *g = NULL, *s = NULL, *w = NULL; | ||
| 28 | + BIGNUM *pub_key = NULL, *priv_key = NULL; | ||
| 29 | + int generate_new_key = 1; | ||
| 30 | |||
| 31 | - if (dh->priv_key == NULL) { | ||
| 32 | - if ((dh->priv_key=BN_new()) == NULL) | ||
| 33 | - goto sw_try; | ||
| 34 | - } | ||
| 35 | + if (dh->priv_key) | ||
| 36 | + priv_key = dh->priv_key; | ||
| 37 | |||
| 38 | - if (dh->pub_key == NULL) { | ||
| 39 | - if ((dh->pub_key=BN_new()) == NULL) | ||
| 40 | - goto sw_try; | ||
| 41 | - } | ||
| 42 | + if (dh->pub_key) | ||
| 43 | + pub_key = dh->pub_key; | ||
| 44 | |||
| 45 | - g_len = BN_num_bytes(dh->p); | ||
| 46 | + q_len = BN_num_bytes(dh->p); | ||
| 47 | /** | ||
| 48 | * Get generator into a plain buffer. If length is less than | ||
| 49 | * q_len then add leading padding bytes. | ||
| 50 | */ | ||
| 51 | - if (spcf_bn2bin_ex(dh->g, &g, &g_len)) { | ||
| 52 | + if (spcf_bn2bin_ex(dh->g, &g, &q_len)) { | ||
| 53 | + DSAerr(DH_F_DH_GENERATE_KEY, ERR_R_MALLOC_FAILURE); | ||
| 54 | + goto sw_try; | ||
| 55 | + } | ||
| 56 | + | ||
| 57 | + if (spcf_bn2bin_ex(dh->p, &q, &q_len)) { | ||
| 58 | DSAerr(DH_F_DH_GENERATE_KEY, ERR_R_MALLOC_FAILURE); | ||
| 59 | goto sw_try; | ||
| 60 | } | ||
| 61 | |||
| 62 | memset(&kop, 0, sizeof kop); | ||
| 63 | kop.crk_op = CRK_DH_GENERATE_KEY; | ||
| 64 | - if (bn2crparam(dh->p, &kop.crk_param[0])) | ||
| 65 | - goto sw_try; | ||
| 66 | + kop.crk_param[0].crp_p = q; | ||
| 67 | + kop.crk_param[0].crp_nbits = q_len * 8; | ||
| 68 | if (!dh->q || bn2crparam(dh->q, &kop.crk_param[1])) | ||
| 69 | goto sw_try; | ||
| 70 | kop.crk_param[2].crp_p = g; | ||
| 71 | - kop.crk_param[2].crp_nbits = g_len * 8; | ||
| 72 | + kop.crk_param[2].crp_nbits = q_len * 8; | ||
| 73 | kop.crk_iparams = 3; | ||
| 74 | |||
| 75 | + s = OPENSSL_malloc (q_len); | ||
| 76 | + if (!s) { | ||
| 77 | + DSAerr(DH_F_DH_GENERATE_KEY, ERR_R_MALLOC_FAILURE); | ||
| 78 | + goto sw_try; | ||
| 79 | + } | ||
| 80 | + | ||
| 81 | + w = OPENSSL_malloc (q_len); | ||
| 82 | + if (!w) { | ||
| 83 | + DSAerr(DH_F_DH_GENERATE_KEY, ERR_R_MALLOC_FAILURE); | ||
| 84 | + goto sw_try; | ||
| 85 | + } | ||
| 86 | + | ||
| 87 | /* pub_key is or prime length while priv key is of length of order */ | ||
| 88 | - if (cryptodev_asym(&kop, BN_num_bytes(dh->p), dh->pub_key, | ||
| 89 | - BN_num_bytes(dh->q), dh->priv_key)) | ||
| 90 | + if (cryptodev_asym(&kop, q_len, w, q_len, s)) | ||
| 91 | goto sw_try; | ||
| 92 | |||
| 93 | + dh->pub_key = BN_bin2bn(w, q_len, pub_key); | ||
| 94 | + dh->pub_key = BN_bin2bn(s, q_len, priv_key); | ||
| 95 | return ret; | ||
| 96 | sw_try: | ||
| 97 | { | ||
| 98 | -- | ||
| 99 | 2.3.5 | ||
| 100 | |||
diff --git a/recipes-connectivity/openssl/openssl-qoriq/qoriq/0016-eng_cryptodev-add-support-for-TLSv1.1-record-offload.patch b/recipes-connectivity/openssl/openssl-qoriq/qoriq/0016-eng_cryptodev-add-support-for-TLSv1.1-record-offload.patch new file mode 100644 index 000000000..c5866212c --- /dev/null +++ b/recipes-connectivity/openssl/openssl-qoriq/qoriq/0016-eng_cryptodev-add-support-for-TLSv1.1-record-offload.patch | |||
| @@ -0,0 +1,338 @@ | |||
| 1 | From 3f34089ab0a3b31ec6b31a6cbf308ca20c6ef597 Mon Sep 17 00:00:00 2001 | ||
| 2 | From: Cristian Stoica <cristian.stoica@nxp.com> | ||
| 3 | Date: Fri, 22 Jan 2016 11:58:34 +0200 | ||
| 4 | Subject: [PATCH 16/48] eng_cryptodev: add support for TLSv1.1 record offload | ||
| 5 | |||
| 6 | Supported cipher suites: | ||
| 7 | - 3des-ede-cbc-sha | ||
| 8 | - aes-128-cbc-hmac-sha | ||
| 9 | - aes-256-cbc-hmac-sha | ||
| 10 | |||
| 11 | Requires TLS patches on cryptodev and TLS algorithm support in Linux | ||
| 12 | kernel driver. | ||
| 13 | |||
| 14 | Signed-off-by: Tudor Ambarus <tudor.ambarus@freescale.com> | ||
| 15 | Signed-off-by: Cristian Stoica <cristian.stoica@nxp.com> | ||
| 16 | --- | ||
| 17 | crypto/engine/eng_cryptodev.c | 96 ++++++++++++++++++++++++++++++++++++++++++- | ||
| 18 | crypto/objects/obj_dat.h | 18 ++++++-- | ||
| 19 | crypto/objects/obj_mac.h | 12 ++++++ | ||
| 20 | crypto/objects/obj_mac.num | 3 ++ | ||
| 21 | crypto/objects/objects.txt | 3 ++ | ||
| 22 | ssl/ssl_ciph.c | 28 ++++++++++--- | ||
| 23 | 6 files changed, 151 insertions(+), 9 deletions(-) | ||
| 24 | |||
| 25 | diff --git a/crypto/engine/eng_cryptodev.c b/crypto/engine/eng_cryptodev.c | ||
| 26 | index 8f73a18..e37a661 100644 | ||
| 27 | --- a/crypto/engine/eng_cryptodev.c | ||
| 28 | +++ b/crypto/engine/eng_cryptodev.c | ||
| 29 | @@ -66,6 +66,7 @@ void ENGINE_load_cryptodev(void) | ||
| 30 | # include <sys/ioctl.h> | ||
| 31 | # include <errno.h> | ||
| 32 | # include <stdio.h> | ||
| 33 | +# include <stdbool.h> | ||
| 34 | # include <unistd.h> | ||
| 35 | # include <fcntl.h> | ||
| 36 | # include <stdarg.h> | ||
| 37 | @@ -135,6 +136,9 @@ void ENGINE_load_cryptodev(void); | ||
| 38 | const EVP_CIPHER cryptodev_3des_cbc_hmac_sha1; | ||
| 39 | const EVP_CIPHER cryptodev_aes_128_cbc_hmac_sha1; | ||
| 40 | const EVP_CIPHER cryptodev_aes_256_cbc_hmac_sha1; | ||
| 41 | +const EVP_CIPHER cryptodev_tls11_3des_cbc_hmac_sha1; | ||
| 42 | +const EVP_CIPHER cryptodev_tls11_aes_128_cbc_hmac_sha1; | ||
| 43 | +const EVP_CIPHER cryptodev_tls11_aes_256_cbc_hmac_sha1; | ||
| 44 | |||
| 45 | inline int spcf_bn2bin(BIGNUM *bn, unsigned char **bin, int *bin_len) | ||
| 46 | { | ||
| 47 | @@ -294,6 +298,18 @@ static struct { | ||
| 48 | CRYPTO_TLS10_AES_CBC_HMAC_SHA1, NID_aes_256_cbc_hmac_sha1, 16, 32, 20 | ||
| 49 | }, | ||
| 50 | { | ||
| 51 | + CRYPTO_TLS11_3DES_CBC_HMAC_SHA1, NID_tls11_des_ede3_cbc_hmac_sha1, 8, | ||
| 52 | + 24, 20 | ||
| 53 | + }, | ||
| 54 | + { | ||
| 55 | + CRYPTO_TLS11_AES_CBC_HMAC_SHA1, NID_tls11_aes_128_cbc_hmac_sha1, 16, 16, | ||
| 56 | + 20 | ||
| 57 | + }, | ||
| 58 | + { | ||
| 59 | + CRYPTO_TLS11_AES_CBC_HMAC_SHA1, NID_tls11_aes_256_cbc_hmac_sha1, 16, 32, | ||
| 60 | + 20 | ||
| 61 | + }, | ||
| 62 | + { | ||
| 63 | CRYPTO_AES_GCM, NID_aes_128_gcm, 16, 16, 0 | ||
| 64 | }, | ||
| 65 | { | ||
| 66 | @@ -526,6 +542,15 @@ static int cryptodev_usable_ciphers(const int **nids) | ||
| 67 | case NID_des_ede3_cbc_hmac_sha1: | ||
| 68 | EVP_add_cipher(&cryptodev_3des_cbc_hmac_sha1); | ||
| 69 | break; | ||
| 70 | + case NID_tls11_des_ede3_cbc_hmac_sha1: | ||
| 71 | + EVP_add_cipher(&cryptodev_tls11_3des_cbc_hmac_sha1); | ||
| 72 | + break; | ||
| 73 | + case NID_tls11_aes_128_cbc_hmac_sha1: | ||
| 74 | + EVP_add_cipher(&cryptodev_tls11_aes_128_cbc_hmac_sha1); | ||
| 75 | + break; | ||
| 76 | + case NID_tls11_aes_256_cbc_hmac_sha1: | ||
| 77 | + EVP_add_cipher(&cryptodev_tls11_aes_256_cbc_hmac_sha1); | ||
| 78 | + break; | ||
| 79 | } | ||
| 80 | } | ||
| 81 | return count; | ||
| 82 | @@ -631,6 +656,9 @@ static int cryptodev_aead_cipher(EVP_CIPHER_CTX *ctx, unsigned char *out, | ||
| 83 | case NID_aes_128_cbc_hmac_sha1: | ||
| 84 | case NID_aes_256_cbc_hmac_sha1: | ||
| 85 | case NID_des_ede3_cbc_hmac_sha1: | ||
| 86 | + case NID_tls11_des_ede3_cbc_hmac_sha1: | ||
| 87 | + case NID_tls11_aes_128_cbc_hmac_sha1: | ||
| 88 | + case NID_tls11_aes_256_cbc_hmac_sha1: | ||
| 89 | cryp.flags = COP_FLAG_AEAD_TLS_TYPE; | ||
| 90 | } | ||
| 91 | cryp.ses = sess->ses; | ||
| 92 | @@ -810,8 +838,9 @@ static int cryptodev_cbc_hmac_sha1_ctrl(EVP_CIPHER_CTX *ctx, int type, | ||
| 93 | struct dev_crypto_state *state = ctx->cipher_data; | ||
| 94 | unsigned char *p = ptr; | ||
| 95 | unsigned int cryptlen = p[arg - 2] << 8 | p[arg - 1]; | ||
| 96 | - unsigned int maclen, padlen; | ||
| 97 | + unsigned int maclen, padlen, len; | ||
| 98 | unsigned int bs = ctx->cipher->block_size; | ||
| 99 | + bool aad_needs_fix = false; | ||
| 100 | |||
| 101 | state->aad = ptr; | ||
| 102 | state->aad_len = arg; | ||
| 103 | @@ -823,6 +852,20 @@ static int cryptodev_cbc_hmac_sha1_ctrl(EVP_CIPHER_CTX *ctx, int type, | ||
| 104 | case NID_aes_256_cbc_hmac_sha1: | ||
| 105 | case NID_des_ede3_cbc_hmac_sha1: | ||
| 106 | maclen = SHA_DIGEST_LENGTH; | ||
| 107 | + break; | ||
| 108 | + case NID_tls11_des_ede3_cbc_hmac_sha1: | ||
| 109 | + case NID_tls11_aes_128_cbc_hmac_sha1: | ||
| 110 | + case NID_tls11_aes_256_cbc_hmac_sha1: | ||
| 111 | + maclen = SHA_DIGEST_LENGTH; | ||
| 112 | + aad_needs_fix = true; | ||
| 113 | + break; | ||
| 114 | + } | ||
| 115 | + | ||
| 116 | + /* Correct length for AAD Length field */ | ||
| 117 | + if (ctx->encrypt && aad_needs_fix) { | ||
| 118 | + len = cryptlen - bs; | ||
| 119 | + p[arg - 2] = len >> 8; | ||
| 120 | + p[arg - 1] = len & 0xff; | ||
| 121 | } | ||
| 122 | |||
| 123 | /* space required for encryption (not only TLS padding) */ | ||
| 124 | @@ -1185,6 +1228,48 @@ const EVP_CIPHER cryptodev_aes_256_cbc_hmac_sha1 = { | ||
| 125 | NULL | ||
| 126 | }; | ||
| 127 | |||
| 128 | +const EVP_CIPHER cryptodev_tls11_3des_cbc_hmac_sha1 = { | ||
| 129 | + NID_tls11_des_ede3_cbc_hmac_sha1, | ||
| 130 | + 8, 24, 8, | ||
| 131 | + EVP_CIPH_CBC_MODE | EVP_CIPH_FLAG_AEAD_CIPHER, | ||
| 132 | + cryptodev_init_aead_key, | ||
| 133 | + cryptodev_aead_cipher, | ||
| 134 | + cryptodev_cleanup, | ||
| 135 | + sizeof(struct dev_crypto_state), | ||
| 136 | + EVP_CIPHER_set_asn1_iv, | ||
| 137 | + EVP_CIPHER_get_asn1_iv, | ||
| 138 | + cryptodev_cbc_hmac_sha1_ctrl, | ||
| 139 | + NULL | ||
| 140 | +}; | ||
| 141 | + | ||
| 142 | +const EVP_CIPHER cryptodev_tls11_aes_128_cbc_hmac_sha1 = { | ||
| 143 | + NID_tls11_aes_128_cbc_hmac_sha1, | ||
| 144 | + 16, 16, 16, | ||
| 145 | + EVP_CIPH_CBC_MODE | EVP_CIPH_FLAG_AEAD_CIPHER, | ||
| 146 | + cryptodev_init_aead_key, | ||
| 147 | + cryptodev_aead_cipher, | ||
| 148 | + cryptodev_cleanup, | ||
| 149 | + sizeof(struct dev_crypto_state), | ||
| 150 | + EVP_CIPHER_set_asn1_iv, | ||
| 151 | + EVP_CIPHER_get_asn1_iv, | ||
| 152 | + cryptodev_cbc_hmac_sha1_ctrl, | ||
| 153 | + NULL | ||
| 154 | +}; | ||
| 155 | + | ||
| 156 | +const EVP_CIPHER cryptodev_tls11_aes_256_cbc_hmac_sha1 = { | ||
| 157 | + NID_tls11_aes_256_cbc_hmac_sha1, | ||
| 158 | + 16, 32, 16, | ||
| 159 | + EVP_CIPH_CBC_MODE | EVP_CIPH_FLAG_AEAD_CIPHER, | ||
| 160 | + cryptodev_init_aead_key, | ||
| 161 | + cryptodev_aead_cipher, | ||
| 162 | + cryptodev_cleanup, | ||
| 163 | + sizeof(struct dev_crypto_state), | ||
| 164 | + EVP_CIPHER_set_asn1_iv, | ||
| 165 | + EVP_CIPHER_get_asn1_iv, | ||
| 166 | + cryptodev_cbc_hmac_sha1_ctrl, | ||
| 167 | + NULL | ||
| 168 | +}; | ||
| 169 | + | ||
| 170 | const EVP_CIPHER cryptodev_aes_128_gcm = { | ||
| 171 | NID_aes_128_gcm, | ||
| 172 | 1, 16, 12, | ||
| 173 | @@ -1298,6 +1383,15 @@ cryptodev_engine_ciphers(ENGINE *e, const EVP_CIPHER **cipher, | ||
| 174 | case NID_aes_256_cbc_hmac_sha1: | ||
| 175 | *cipher = &cryptodev_aes_256_cbc_hmac_sha1; | ||
| 176 | break; | ||
| 177 | + case NID_tls11_des_ede3_cbc_hmac_sha1: | ||
| 178 | + *cipher = &cryptodev_tls11_3des_cbc_hmac_sha1; | ||
| 179 | + break; | ||
| 180 | + case NID_tls11_aes_128_cbc_hmac_sha1: | ||
| 181 | + *cipher = &cryptodev_tls11_aes_128_cbc_hmac_sha1; | ||
| 182 | + break; | ||
| 183 | + case NID_tls11_aes_256_cbc_hmac_sha1: | ||
| 184 | + *cipher = &cryptodev_tls11_aes_256_cbc_hmac_sha1; | ||
| 185 | + break; | ||
| 186 | case NID_aes_128_gcm: | ||
| 187 | *cipher = &cryptodev_aes_128_gcm; | ||
| 188 | break; | ||
| 189 | diff --git a/crypto/objects/obj_dat.h b/crypto/objects/obj_dat.h | ||
| 190 | index 35d1abc..4dd32a1 100644 | ||
| 191 | --- a/crypto/objects/obj_dat.h | ||
| 192 | +++ b/crypto/objects/obj_dat.h | ||
| 193 | @@ -62,9 +62,9 @@ | ||
| 194 | * [including the GNU Public Licence.] | ||
| 195 | */ | ||
| 196 | |||
| 197 | -#define NUM_NID 959 | ||
| 198 | -#define NUM_SN 952 | ||
| 199 | -#define NUM_LN 952 | ||
| 200 | +#define NUM_NID 962 | ||
| 201 | +#define NUM_SN 955 | ||
| 202 | +#define NUM_LN 955 | ||
| 203 | #define NUM_OBJ 890 | ||
| 204 | |||
| 205 | static const unsigned char lvalues[6255]={ | ||
| 206 | @@ -2516,6 +2516,12 @@ static const ASN1_OBJECT nid_objs[NUM_NID]={ | ||
| 207 | NID_jurisdictionCountryName,11,&(lvalues[6243]),0}, | ||
| 208 | {"DES-EDE3-CBC-HMAC-SHA1","des-ede3-cbc-hmac-sha1", | ||
| 209 | NID_des_ede3_cbc_hmac_sha1,0,NULL,0}, | ||
| 210 | +{"TLS11-DES-EDE3-CBC-HMAC-SHA1","tls11-des-ede3-cbc-hmac-sha1", | ||
| 211 | + NID_tls11_des_ede3_cbc_hmac_sha1,0,NULL,0}, | ||
| 212 | +{"TLS11-AES-128-CBC-HMAC-SHA1","tls11-aes-128-cbc-hmac-sha1", | ||
| 213 | + NID_tls11_aes_128_cbc_hmac_sha1,0,NULL,0}, | ||
| 214 | +{"TLS11-AES-256-CBC-HMAC-SHA1","tls11-aes-256-cbc-hmac-sha1", | ||
| 215 | + NID_tls11_aes_256_cbc_hmac_sha1,0,NULL,0}, | ||
| 216 | }; | ||
| 217 | |||
| 218 | static const unsigned int sn_objs[NUM_SN]={ | ||
| 219 | @@ -2705,6 +2711,9 @@ static const unsigned int sn_objs[NUM_SN]={ | ||
| 220 | 100, /* "SN" */ | ||
| 221 | 16, /* "ST" */ | ||
| 222 | 143, /* "SXNetID" */ | ||
| 223 | +960, /* "TLS11-AES-128-CBC-HMAC-SHA1" */ | ||
| 224 | +961, /* "TLS11-AES-256-CBC-HMAC-SHA1" */ | ||
| 225 | +959, /* "TLS11-DES-EDE3-CBC-HMAC-SHA1" */ | ||
| 226 | 458, /* "UID" */ | ||
| 227 | 0, /* "UNDEF" */ | ||
| 228 | 11, /* "X500" */ | ||
| 229 | @@ -4396,6 +4405,9 @@ static const unsigned int ln_objs[NUM_LN]={ | ||
| 230 | 459, /* "textEncodedORAddress" */ | ||
| 231 | 293, /* "textNotice" */ | ||
| 232 | 106, /* "title" */ | ||
| 233 | +960, /* "tls11-aes-128-cbc-hmac-sha1" */ | ||
| 234 | +961, /* "tls11-aes-256-cbc-hmac-sha1" */ | ||
| 235 | +959, /* "tls11-des-ede3-cbc-hmac-sha1" */ | ||
| 236 | 682, /* "tpBasis" */ | ||
| 237 | 436, /* "ucl" */ | ||
| 238 | 0, /* "undefined" */ | ||
| 239 | diff --git a/crypto/objects/obj_mac.h b/crypto/objects/obj_mac.h | ||
| 240 | index cb318bc..5930563 100644 | ||
| 241 | --- a/crypto/objects/obj_mac.h | ||
| 242 | +++ b/crypto/objects/obj_mac.h | ||
| 243 | @@ -4051,6 +4051,18 @@ | ||
| 244 | #define LN_des_ede3_cbc_hmac_sha1 "des-ede3-cbc-hmac-sha1" | ||
| 245 | #define NID_des_ede3_cbc_hmac_sha1 958 | ||
| 246 | |||
| 247 | +#define SN_tls11_des_ede3_cbc_hmac_sha1 "TLS11-DES-EDE3-CBC-HMAC-SHA1" | ||
| 248 | +#define LN_tls11_des_ede3_cbc_hmac_sha1 "tls11-des-ede3-cbc-hmac-sha1" | ||
| 249 | +#define NID_tls11_des_ede3_cbc_hmac_sha1 959 | ||
| 250 | + | ||
| 251 | +#define SN_tls11_aes_128_cbc_hmac_sha1 "TLS11-AES-128-CBC-HMAC-SHA1" | ||
| 252 | +#define LN_tls11_aes_128_cbc_hmac_sha1 "tls11-aes-128-cbc-hmac-sha1" | ||
| 253 | +#define NID_tls11_aes_128_cbc_hmac_sha1 960 | ||
| 254 | + | ||
| 255 | +#define SN_tls11_aes_256_cbc_hmac_sha1 "TLS11-AES-256-CBC-HMAC-SHA1" | ||
| 256 | +#define LN_tls11_aes_256_cbc_hmac_sha1 "tls11-aes-256-cbc-hmac-sha1" | ||
| 257 | +#define NID_tls11_aes_256_cbc_hmac_sha1 961 | ||
| 258 | + | ||
| 259 | #define SN_dhpublicnumber "dhpublicnumber" | ||
| 260 | #define LN_dhpublicnumber "X9.42 DH" | ||
| 261 | #define NID_dhpublicnumber 920 | ||
| 262 | diff --git a/crypto/objects/obj_mac.num b/crypto/objects/obj_mac.num | ||
| 263 | index 02d1bb8..02f1728 100644 | ||
| 264 | --- a/crypto/objects/obj_mac.num | ||
| 265 | +++ b/crypto/objects/obj_mac.num | ||
| 266 | @@ -956,3 +956,6 @@ jurisdictionLocalityName 955 | ||
| 267 | jurisdictionStateOrProvinceName 956 | ||
| 268 | jurisdictionCountryName 957 | ||
| 269 | des_ede3_cbc_hmac_sha1 958 | ||
| 270 | +tls11_des_ede3_cbc_hmac_sha1 959 | ||
| 271 | +tls11_aes_128_cbc_hmac_sha1 960 | ||
| 272 | +tls11_aes_256_cbc_hmac_sha1 961 | ||
| 273 | diff --git a/crypto/objects/objects.txt b/crypto/objects/objects.txt | ||
| 274 | index 4e1ff18..cda81da 100644 | ||
| 275 | --- a/crypto/objects/objects.txt | ||
| 276 | +++ b/crypto/objects/objects.txt | ||
| 277 | @@ -1295,6 +1295,9 @@ kisa 1 6 : SEED-OFB : seed-ofb | ||
| 278 | : AES-192-CBC-HMAC-SHA256 : aes-192-cbc-hmac-sha256 | ||
| 279 | : AES-256-CBC-HMAC-SHA256 : aes-256-cbc-hmac-sha256 | ||
| 280 | : DES-EDE3-CBC-HMAC-SHA1 : des-ede3-cbc-hmac-sha1 | ||
| 281 | + : TLS11-DES-EDE3-CBC-HMAC-SHA1 : tls11-des-ede3-cbc-hmac-sha1 | ||
| 282 | + : TLS11-AES-128-CBC-HMAC-SHA1 : tls11-aes-128-cbc-hmac-sha1 | ||
| 283 | + : TLS11-AES-256-CBC-HMAC-SHA1 : tls11-aes-256-cbc-hmac-sha1 | ||
| 284 | |||
| 285 | ISO-US 10046 2 1 : dhpublicnumber : X9.42 DH | ||
| 286 | |||
| 287 | diff --git a/ssl/ssl_ciph.c b/ssl/ssl_ciph.c | ||
| 288 | index a379273..e3d73ac 100644 | ||
| 289 | --- a/ssl/ssl_ciph.c | ||
| 290 | +++ b/ssl/ssl_ciph.c | ||
| 291 | @@ -652,11 +652,13 @@ int ssl_cipher_get_evp(const SSL_SESSION *s, const EVP_CIPHER **enc, | ||
| 292 | c->algorithm_mac == SSL_MD5 && | ||
| 293 | (evp = EVP_get_cipherbyname("RC4-HMAC-MD5"))) | ||
| 294 | *enc = evp, *md = NULL; | ||
| 295 | - else if (c->algorithm_enc == SSL_AES128 && | ||
| 296 | + else if (s->ssl_version == TLS1_VERSION && | ||
| 297 | + c->algorithm_enc == SSL_AES128 && | ||
| 298 | c->algorithm_mac == SSL_SHA1 && | ||
| 299 | (evp = EVP_get_cipherbyname("AES-128-CBC-HMAC-SHA1"))) | ||
| 300 | *enc = evp, *md = NULL; | ||
| 301 | - else if (c->algorithm_enc == SSL_AES256 && | ||
| 302 | + else if (s->ssl_version == TLS1_VERSION && | ||
| 303 | + c->algorithm_enc == SSL_AES256 && | ||
| 304 | c->algorithm_mac == SSL_SHA1 && | ||
| 305 | (evp = EVP_get_cipherbyname("AES-256-CBC-HMAC-SHA1"))) | ||
| 306 | *enc = evp, *md = NULL; | ||
| 307 | @@ -668,9 +670,25 @@ int ssl_cipher_get_evp(const SSL_SESSION *s, const EVP_CIPHER **enc, | ||
| 308 | c->algorithm_mac == SSL_SHA256 && | ||
| 309 | (evp = EVP_get_cipherbyname("AES-256-CBC-HMAC-SHA256"))) | ||
| 310 | *enc = evp, *md = NULL; | ||
| 311 | - else if (c->algorithm_enc == SSL_3DES && | ||
| 312 | - c->algorithm_mac == SSL_SHA1 && | ||
| 313 | - (evp = EVP_get_cipherbyname("DES-EDE3-CBC-HMAC-SHA1"))) | ||
| 314 | + else if (s->ssl_version == TLS1_VERSION && | ||
| 315 | + c->algorithm_enc == SSL_3DES && | ||
| 316 | + c->algorithm_mac == SSL_SHA1 && | ||
| 317 | + (evp = EVP_get_cipherbyname("DES-EDE3-CBC-HMAC-SHA1"))) | ||
| 318 | + *enc = evp, *md = NULL; | ||
| 319 | + else if (s->ssl_version == TLS1_1_VERSION && | ||
| 320 | + c->algorithm_enc == SSL_3DES && | ||
| 321 | + c->algorithm_mac == SSL_SHA1 && | ||
| 322 | + (evp = EVP_get_cipherbyname("TLS11-DES-EDE3-CBC-HMAC-SHA1"))) | ||
| 323 | + *enc = evp, *md = NULL; | ||
| 324 | + else if (s->ssl_version == TLS1_1_VERSION && | ||
| 325 | + c->algorithm_enc == SSL_AES128 && | ||
| 326 | + c->algorithm_mac == SSL_SHA1 && | ||
| 327 | + (evp = EVP_get_cipherbyname("TLS11-AES-128-CBC-HMAC-SHA1"))) | ||
| 328 | + *enc = evp, *md = NULL; | ||
| 329 | + else if (s->ssl_version == TLS1_1_VERSION && | ||
| 330 | + c->algorithm_enc == SSL_AES256 && | ||
| 331 | + c->algorithm_mac == SSL_SHA1 && | ||
| 332 | + (evp = EVP_get_cipherbyname("TLS11-AES-256-CBC-HMAC-SHA1"))) | ||
| 333 | *enc = evp, *md = NULL; | ||
| 334 | return (1); | ||
| 335 | } else | ||
| 336 | -- | ||
| 337 | 2.7.0 | ||
| 338 | |||
diff --git a/recipes-connectivity/openssl/openssl-qoriq/qoriq/0017-cryptodev-add-support-for-aes-gcm-algorithm-offloadi.patch b/recipes-connectivity/openssl/openssl-qoriq/qoriq/0017-cryptodev-add-support-for-aes-gcm-algorithm-offloadi.patch deleted file mode 100644 index bd9e61ac0..000000000 --- a/recipes-connectivity/openssl/openssl-qoriq/qoriq/0017-cryptodev-add-support-for-aes-gcm-algorithm-offloadi.patch +++ /dev/null | |||
| @@ -1,309 +0,0 @@ | |||
| 1 | From 11b55103463bac614e00d74e9f196ec4ec6bade1 Mon Sep 17 00:00:00 2001 | ||
| 2 | From: Cristian Stoica <cristian.stoica@freescale.com> | ||
| 3 | Date: Mon, 16 Jun 2014 14:06:21 +0300 | ||
| 4 | Subject: [PATCH 17/26] cryptodev: add support for aes-gcm algorithm offloading | ||
| 5 | |||
| 6 | Change-Id: I3b77dc5ef8b8f707309549244a02852d95b36168 | ||
| 7 | Signed-off-by: Cristian Stoica <cristian.stoica@freescale.com> | ||
| 8 | Reviewed-on: http://git.am.freescale.net:8181/17226 | ||
| 9 | --- | ||
| 10 | apps/speed.c | 6 +- | ||
| 11 | crypto/engine/eng_cryptodev.c | 229 +++++++++++++++++++++++++++++++++++++++++- | ||
| 12 | 2 files changed, 233 insertions(+), 2 deletions(-) | ||
| 13 | |||
| 14 | diff --git a/apps/speed.c b/apps/speed.c | ||
| 15 | index 9886ca3..099dede 100644 | ||
| 16 | --- a/apps/speed.c | ||
| 17 | +++ b/apps/speed.c | ||
| 18 | @@ -224,7 +224,11 @@ | ||
| 19 | #endif | ||
| 20 | |||
| 21 | #undef BUFSIZE | ||
| 22 | -#define BUFSIZE ((long)1024*8+1) | ||
| 23 | +/* The buffer overhead allows GCM tag at the end of the encrypted data. This | ||
| 24 | + avoids buffer overflows from cryptodev since Linux kernel GCM | ||
| 25 | + implementation allways adds the tag - unlike e_aes.c:aes_gcm_cipher() | ||
| 26 | + which doesn't */ | ||
| 27 | +#define BUFSIZE ((long)1024*8 + EVP_GCM_TLS_TAG_LEN) | ||
| 28 | int run=0; | ||
| 29 | |||
| 30 | static int mr=0; | ||
| 31 | diff --git a/crypto/engine/eng_cryptodev.c b/crypto/engine/eng_cryptodev.c | ||
| 32 | index 13d924f..4493490 100644 | ||
| 33 | --- a/crypto/engine/eng_cryptodev.c | ||
| 34 | +++ b/crypto/engine/eng_cryptodev.c | ||
| 35 | @@ -78,8 +78,10 @@ struct dev_crypto_state { | ||
| 36 | struct session_op d_sess; | ||
| 37 | int d_fd; | ||
| 38 | unsigned char *aad; | ||
| 39 | - unsigned int aad_len; | ||
| 40 | + int aad_len; | ||
| 41 | unsigned int len; | ||
| 42 | + unsigned char *iv; | ||
| 43 | + int ivlen; | ||
| 44 | |||
| 45 | #ifdef USE_CRYPTODEV_DIGESTS | ||
| 46 | char dummy_mac_key[HASH_MAX_LEN]; | ||
| 47 | @@ -251,6 +253,7 @@ static struct { | ||
| 48 | { CRYPTO_SKIPJACK_CBC, NID_undef, 0, 0, 0}, | ||
| 49 | { CRYPTO_TLS10_AES_CBC_HMAC_SHA1, NID_aes_128_cbc_hmac_sha1, 16, 16, 20}, | ||
| 50 | { CRYPTO_TLS10_AES_CBC_HMAC_SHA1, NID_aes_256_cbc_hmac_sha1, 16, 32, 20}, | ||
| 51 | + { CRYPTO_AES_GCM, NID_aes_128_gcm, 16, 16, 0}, | ||
| 52 | { 0, NID_undef, 0, 0, 0}, | ||
| 53 | }; | ||
| 54 | |||
| 55 | @@ -271,6 +274,19 @@ static struct { | ||
| 56 | }; | ||
| 57 | #endif | ||
| 58 | |||
| 59 | +/* increment counter (64-bit int) by 1 */ | ||
| 60 | +static void ctr64_inc(unsigned char *counter) { | ||
| 61 | + int n=8; | ||
| 62 | + unsigned char c; | ||
| 63 | + | ||
| 64 | + do { | ||
| 65 | + --n; | ||
| 66 | + c = counter[n]; | ||
| 67 | + ++c; | ||
| 68 | + counter[n] = c; | ||
| 69 | + if (c) return; | ||
| 70 | + } while (n); | ||
| 71 | +} | ||
| 72 | /* | ||
| 73 | * Return a fd if /dev/crypto seems usable, 0 otherwise. | ||
| 74 | */ | ||
| 75 | @@ -762,6 +778,197 @@ static int cryptodev_cbc_hmac_sha1_ctrl(EVP_CIPHER_CTX *ctx, int type, int arg, | ||
| 76 | } | ||
| 77 | } | ||
| 78 | |||
| 79 | +static int cryptodev_init_gcm_key(EVP_CIPHER_CTX *ctx, | ||
| 80 | + const unsigned char *key, const unsigned char *iv, int enc) | ||
| 81 | +{ | ||
| 82 | + struct dev_crypto_state *state = ctx->cipher_data; | ||
| 83 | + struct session_op *sess = &state->d_sess; | ||
| 84 | + int cipher = -1, i; | ||
| 85 | + if (!iv && !key) | ||
| 86 | + return 1; | ||
| 87 | + | ||
| 88 | + if (iv) | ||
| 89 | + memcpy(ctx->iv, iv, ctx->cipher->iv_len); | ||
| 90 | + | ||
| 91 | + for (i = 0; ciphers[i].id; i++) | ||
| 92 | + if (ctx->cipher->nid == ciphers[i].nid && | ||
| 93 | + ctx->cipher->iv_len <= ciphers[i].ivmax && | ||
| 94 | + ctx->key_len == ciphers[i].keylen) { | ||
| 95 | + cipher = ciphers[i].id; | ||
| 96 | + break; | ||
| 97 | + } | ||
| 98 | + | ||
| 99 | + if (!ciphers[i].id) { | ||
| 100 | + state->d_fd = -1; | ||
| 101 | + return 0; | ||
| 102 | + } | ||
| 103 | + | ||
| 104 | + memset(sess, 0, sizeof(struct session_op)); | ||
| 105 | + | ||
| 106 | + if ((state->d_fd = get_dev_crypto()) < 0) | ||
| 107 | + return 0; | ||
| 108 | + | ||
| 109 | + sess->key = (unsigned char *) key; | ||
| 110 | + sess->keylen = ctx->key_len; | ||
| 111 | + sess->cipher = cipher; | ||
| 112 | + | ||
| 113 | + if (ioctl(state->d_fd, CIOCGSESSION, sess) == -1) { | ||
| 114 | + put_dev_crypto(state->d_fd); | ||
| 115 | + state->d_fd = -1; | ||
| 116 | + return 0; | ||
| 117 | + } | ||
| 118 | + return 1; | ||
| 119 | +} | ||
| 120 | + | ||
| 121 | +static int cryptodev_gcm_tls_cipher(EVP_CIPHER_CTX *ctx, unsigned char *out, | ||
| 122 | + const unsigned char *in, size_t len) | ||
| 123 | +{ | ||
| 124 | + struct crypt_auth_op cryp = {0}; | ||
| 125 | + struct dev_crypto_state *state = ctx->cipher_data; | ||
| 126 | + struct session_op *sess = &state->d_sess; | ||
| 127 | + int rv = len; | ||
| 128 | + | ||
| 129 | + if (EVP_CIPHER_CTX_ctrl(ctx, ctx->encrypt ? | ||
| 130 | + EVP_CTRL_GCM_IV_GEN : EVP_CTRL_GCM_SET_IV_INV, | ||
| 131 | + EVP_GCM_TLS_EXPLICIT_IV_LEN, out) <= 0) | ||
| 132 | + return 0; | ||
| 133 | + | ||
| 134 | + in += EVP_GCM_TLS_EXPLICIT_IV_LEN; | ||
| 135 | + out += EVP_GCM_TLS_EXPLICIT_IV_LEN; | ||
| 136 | + len -= EVP_GCM_TLS_EXPLICIT_IV_LEN; | ||
| 137 | + | ||
| 138 | + if (ctx->encrypt) { | ||
| 139 | + len -= EVP_GCM_TLS_TAG_LEN; | ||
| 140 | + } | ||
| 141 | + cryp.ses = sess->ses; | ||
| 142 | + cryp.len = len; | ||
| 143 | + cryp.src = (unsigned char*) in; | ||
| 144 | + cryp.dst = out; | ||
| 145 | + cryp.auth_src = state->aad; | ||
| 146 | + cryp.auth_len = state->aad_len; | ||
| 147 | + cryp.iv = ctx->iv; | ||
| 148 | + cryp.op = ctx->encrypt ? COP_ENCRYPT : COP_DECRYPT; | ||
| 149 | + | ||
| 150 | + if (ioctl(state->d_fd, CIOCAUTHCRYPT, &cryp) == -1) { | ||
| 151 | + return 0; | ||
| 152 | + } | ||
| 153 | + | ||
| 154 | + if (ctx->encrypt) | ||
| 155 | + ctr64_inc(state->iv + state->ivlen - 8); | ||
| 156 | + else | ||
| 157 | + rv = len - EVP_GCM_TLS_TAG_LEN; | ||
| 158 | + | ||
| 159 | + return rv; | ||
| 160 | +} | ||
| 161 | + | ||
| 162 | +static int cryptodev_gcm_cipher(EVP_CIPHER_CTX *ctx, unsigned char *out, | ||
| 163 | + const unsigned char *in, size_t len) | ||
| 164 | +{ | ||
| 165 | + struct crypt_auth_op cryp; | ||
| 166 | + struct dev_crypto_state *state = ctx->cipher_data; | ||
| 167 | + struct session_op *sess = &state->d_sess; | ||
| 168 | + | ||
| 169 | + if (state->d_fd < 0) | ||
| 170 | + return 0; | ||
| 171 | + | ||
| 172 | + if ((len % ctx->cipher->block_size) != 0) | ||
| 173 | + return 0; | ||
| 174 | + | ||
| 175 | + if (state->aad_len >= 0) | ||
| 176 | + return cryptodev_gcm_tls_cipher(ctx, out, in, len); | ||
| 177 | + | ||
| 178 | + memset(&cryp, 0, sizeof(cryp)); | ||
| 179 | + | ||
| 180 | + cryp.ses = sess->ses; | ||
| 181 | + cryp.len = len; | ||
| 182 | + cryp.src = (unsigned char*) in; | ||
| 183 | + cryp.dst = out; | ||
| 184 | + cryp.auth_src = NULL; | ||
| 185 | + cryp.auth_len = 0; | ||
| 186 | + cryp.iv = ctx->iv; | ||
| 187 | + cryp.op = ctx->encrypt ? COP_ENCRYPT : COP_DECRYPT; | ||
| 188 | + | ||
| 189 | + if (ioctl(state->d_fd, CIOCAUTHCRYPT, &cryp) == -1) { | ||
| 190 | + return 0; | ||
| 191 | + } | ||
| 192 | + | ||
| 193 | + return len; | ||
| 194 | +} | ||
| 195 | + | ||
| 196 | +static int cryptodev_gcm_ctrl(EVP_CIPHER_CTX *ctx, int type, int arg, | ||
| 197 | + void *ptr) | ||
| 198 | +{ | ||
| 199 | + struct dev_crypto_state *state = ctx->cipher_data; | ||
| 200 | + switch (type) { | ||
| 201 | + case EVP_CTRL_INIT: | ||
| 202 | + { | ||
| 203 | + state->ivlen = ctx->cipher->iv_len; | ||
| 204 | + state->iv = ctx->iv; | ||
| 205 | + state->aad_len = -1; | ||
| 206 | + return 1; | ||
| 207 | + } | ||
| 208 | + case EVP_CTRL_GCM_SET_IV_FIXED: | ||
| 209 | + { | ||
| 210 | + /* Special case: -1 length restores whole IV */ | ||
| 211 | + if (arg == -1) | ||
| 212 | + { | ||
| 213 | + memcpy(state->iv, ptr, state->ivlen); | ||
| 214 | + return 1; | ||
| 215 | + } | ||
| 216 | + /* Fixed field must be at least 4 bytes and invocation field | ||
| 217 | + * at least 8. | ||
| 218 | + */ | ||
| 219 | + if ((arg < 4) || (state->ivlen - arg) < 8) | ||
| 220 | + return 0; | ||
| 221 | + if (arg) | ||
| 222 | + memcpy(state->iv, ptr, arg); | ||
| 223 | + if (ctx->encrypt && | ||
| 224 | + RAND_bytes(state->iv + arg, state->ivlen - arg) <= 0) | ||
| 225 | + return 0; | ||
| 226 | + return 1; | ||
| 227 | + } | ||
| 228 | + case EVP_CTRL_AEAD_TLS1_AAD: | ||
| 229 | + { | ||
| 230 | + unsigned int len; | ||
| 231 | + if (arg != 13) | ||
| 232 | + return 0; | ||
| 233 | + | ||
| 234 | + memcpy(ctx->buf, ptr, arg); | ||
| 235 | + len=ctx->buf[arg-2] << 8 | ctx->buf[arg-1]; | ||
| 236 | + | ||
| 237 | + /* Correct length for explicit IV */ | ||
| 238 | + len -= EVP_GCM_TLS_EXPLICIT_IV_LEN; | ||
| 239 | + | ||
| 240 | + /* If decrypting correct for tag too */ | ||
| 241 | + if (!ctx->encrypt) | ||
| 242 | + len -= EVP_GCM_TLS_TAG_LEN; | ||
| 243 | + | ||
| 244 | + ctx->buf[arg-2] = len >> 8; | ||
| 245 | + ctx->buf[arg-1] = len & 0xff; | ||
| 246 | + | ||
| 247 | + state->aad = ctx->buf; | ||
| 248 | + state->aad_len = arg; | ||
| 249 | + state->len = len; | ||
| 250 | + | ||
| 251 | + /* Extra padding: tag appended to record */ | ||
| 252 | + return EVP_GCM_TLS_TAG_LEN; | ||
| 253 | + } | ||
| 254 | + case EVP_CTRL_GCM_SET_IV_INV: | ||
| 255 | + { | ||
| 256 | + if (ctx->encrypt) | ||
| 257 | + return 0; | ||
| 258 | + memcpy(state->iv + state->ivlen - arg, ptr, arg); | ||
| 259 | + return 1; | ||
| 260 | + } | ||
| 261 | + case EVP_CTRL_GCM_IV_GEN: | ||
| 262 | + if (arg <= 0 || arg > state->ivlen) | ||
| 263 | + arg = state->ivlen; | ||
| 264 | + memcpy(ptr, state->iv + state->ivlen - arg, arg); | ||
| 265 | + return 1; | ||
| 266 | + default: | ||
| 267 | + return -1; | ||
| 268 | + } | ||
| 269 | +} | ||
| 270 | /* | ||
| 271 | * libcrypto EVP stuff - this is how we get wired to EVP so the engine | ||
| 272 | * gets called when libcrypto requests a cipher NID. | ||
| 273 | @@ -901,6 +1108,23 @@ const EVP_CIPHER cryptodev_aes_256_cbc_hmac_sha1 = { | ||
| 274 | cryptodev_cbc_hmac_sha1_ctrl, | ||
| 275 | NULL | ||
| 276 | }; | ||
| 277 | + | ||
| 278 | +const EVP_CIPHER cryptodev_aes_128_gcm = { | ||
| 279 | + NID_aes_128_gcm, | ||
| 280 | + 1, 16, 12, | ||
| 281 | + EVP_CIPH_GCM_MODE | EVP_CIPH_FLAG_AEAD_CIPHER | EVP_CIPH_FLAG_DEFAULT_ASN1 \ | ||
| 282 | + | EVP_CIPH_CUSTOM_IV | EVP_CIPH_FLAG_CUSTOM_CIPHER \ | ||
| 283 | + | EVP_CIPH_ALWAYS_CALL_INIT | EVP_CIPH_CTRL_INIT, | ||
| 284 | + cryptodev_init_gcm_key, | ||
| 285 | + cryptodev_gcm_cipher, | ||
| 286 | + cryptodev_cleanup, | ||
| 287 | + sizeof(struct dev_crypto_state), | ||
| 288 | + EVP_CIPHER_set_asn1_iv, | ||
| 289 | + EVP_CIPHER_get_asn1_iv, | ||
| 290 | + cryptodev_gcm_ctrl, | ||
| 291 | + NULL | ||
| 292 | +}; | ||
| 293 | + | ||
| 294 | /* | ||
| 295 | * Registered by the ENGINE when used to find out how to deal with | ||
| 296 | * a particular NID in the ENGINE. this says what we'll do at the | ||
| 297 | @@ -944,6 +1168,9 @@ cryptodev_engine_ciphers(ENGINE *e, const EVP_CIPHER **cipher, | ||
| 298 | case NID_aes_256_cbc_hmac_sha1: | ||
| 299 | *cipher = &cryptodev_aes_256_cbc_hmac_sha1; | ||
| 300 | break; | ||
| 301 | + case NID_aes_128_gcm: | ||
| 302 | + *cipher = &cryptodev_aes_128_gcm; | ||
| 303 | + break; | ||
| 304 | default: | ||
| 305 | *cipher = NULL; | ||
| 306 | break; | ||
| 307 | -- | ||
| 308 | 2.3.5 | ||
| 309 | |||
diff --git a/recipes-connectivity/openssl/openssl-qoriq/qoriq/0017-eng_cryptodev-add-support-for-TLSv1.2-record-offload.patch b/recipes-connectivity/openssl/openssl-qoriq/qoriq/0017-eng_cryptodev-add-support-for-TLSv1.2-record-offload.patch new file mode 100644 index 000000000..5e65ec6ee --- /dev/null +++ b/recipes-connectivity/openssl/openssl-qoriq/qoriq/0017-eng_cryptodev-add-support-for-TLSv1.2-record-offload.patch | |||
| @@ -0,0 +1,377 @@ | |||
| 1 | From 4c1531a088076118ce3c06cb0af15998f0796cb3 Mon Sep 17 00:00:00 2001 | ||
| 2 | From: Tudor Ambarus <tudor.ambarus@freescale.com> | ||
| 3 | Date: Tue, 31 Mar 2015 16:32:35 +0300 | ||
| 4 | Subject: [PATCH 17/48] eng_cryptodev: add support for TLSv1.2 record offload | ||
| 5 | |||
| 6 | Supported cipher suites: | ||
| 7 | - 3des-ede-cbc-sha | ||
| 8 | - aes-128-cbc-hmac-sha | ||
| 9 | - aes-256-cbc-hmac-sha | ||
| 10 | - aes-128-cbc-hmac-sha256 | ||
| 11 | - aes-256-cbc-hmac-sha256 | ||
| 12 | |||
| 13 | Requires TLS patches on cryptodev and TLS algorithm support in Linux | ||
| 14 | kernel driver. | ||
| 15 | |||
| 16 | Signed-off-by: Tudor Ambarus <tudor.ambarus@freescale.com> | ||
| 17 | Tested-by: Cristian Stoica <cristian.stoica@freescale.com> | ||
| 18 | --- | ||
| 19 | crypto/engine/eng_cryptodev.c | 138 ++++++++++++++++++++++++++++++++++++++++++ | ||
| 20 | crypto/objects/obj_dat.h | 26 +++++++- | ||
| 21 | crypto/objects/obj_mac.h | 20 ++++++ | ||
| 22 | crypto/objects/obj_mac.num | 5 ++ | ||
| 23 | crypto/objects/objects.txt | 5 ++ | ||
| 24 | ssl/ssl_ciph.c | 25 ++++++++ | ||
| 25 | 6 files changed, 216 insertions(+), 3 deletions(-) | ||
| 26 | |||
| 27 | diff --git a/crypto/engine/eng_cryptodev.c b/crypto/engine/eng_cryptodev.c | ||
| 28 | index e37a661..e6f9f16 100644 | ||
| 29 | --- a/crypto/engine/eng_cryptodev.c | ||
| 30 | +++ b/crypto/engine/eng_cryptodev.c | ||
| 31 | @@ -139,6 +139,11 @@ const EVP_CIPHER cryptodev_aes_256_cbc_hmac_sha1; | ||
| 32 | const EVP_CIPHER cryptodev_tls11_3des_cbc_hmac_sha1; | ||
| 33 | const EVP_CIPHER cryptodev_tls11_aes_128_cbc_hmac_sha1; | ||
| 34 | const EVP_CIPHER cryptodev_tls11_aes_256_cbc_hmac_sha1; | ||
| 35 | +const EVP_CIPHER cryptodev_tls12_3des_cbc_hmac_sha1; | ||
| 36 | +const EVP_CIPHER cryptodev_tls12_aes_128_cbc_hmac_sha1; | ||
| 37 | +const EVP_CIPHER cryptodev_tls12_aes_256_cbc_hmac_sha1; | ||
| 38 | +const EVP_CIPHER cryptodev_tls12_aes_128_cbc_hmac_sha256; | ||
| 39 | +const EVP_CIPHER cryptodev_tls12_aes_256_cbc_hmac_sha256; | ||
| 40 | |||
| 41 | inline int spcf_bn2bin(BIGNUM *bn, unsigned char **bin, int *bin_len) | ||
| 42 | { | ||
| 43 | @@ -310,6 +315,26 @@ static struct { | ||
| 44 | 20 | ||
| 45 | }, | ||
| 46 | { | ||
| 47 | + CRYPTO_TLS12_3DES_CBC_HMAC_SHA1, NID_tls12_des_ede3_cbc_hmac_sha1, 8, | ||
| 48 | + 24, 20 | ||
| 49 | + }, | ||
| 50 | + { | ||
| 51 | + CRYPTO_TLS12_AES_CBC_HMAC_SHA1, NID_tls12_aes_128_cbc_hmac_sha1, 16, 16, | ||
| 52 | + 20 | ||
| 53 | + }, | ||
| 54 | + { | ||
| 55 | + CRYPTO_TLS12_AES_CBC_HMAC_SHA1, NID_tls12_aes_256_cbc_hmac_sha1, 16, 32, | ||
| 56 | + 20 | ||
| 57 | + }, | ||
| 58 | + { | ||
| 59 | + CRYPTO_TLS12_AES_CBC_HMAC_SHA256, NID_tls12_aes_128_cbc_hmac_sha256, 16, | ||
| 60 | + 16, 32 | ||
| 61 | + }, | ||
| 62 | + { | ||
| 63 | + CRYPTO_TLS12_AES_CBC_HMAC_SHA256, NID_tls12_aes_256_cbc_hmac_sha256, 16, | ||
| 64 | + 32, 32 | ||
| 65 | + }, | ||
| 66 | + { | ||
| 67 | CRYPTO_AES_GCM, NID_aes_128_gcm, 16, 16, 0 | ||
| 68 | }, | ||
| 69 | { | ||
| 70 | @@ -551,6 +576,21 @@ static int cryptodev_usable_ciphers(const int **nids) | ||
| 71 | case NID_tls11_aes_256_cbc_hmac_sha1: | ||
| 72 | EVP_add_cipher(&cryptodev_tls11_aes_256_cbc_hmac_sha1); | ||
| 73 | break; | ||
| 74 | + case NID_tls12_des_ede3_cbc_hmac_sha1: | ||
| 75 | + EVP_add_cipher(&cryptodev_tls12_3des_cbc_hmac_sha1); | ||
| 76 | + break; | ||
| 77 | + case NID_tls12_aes_128_cbc_hmac_sha1: | ||
| 78 | + EVP_add_cipher(&cryptodev_tls12_aes_128_cbc_hmac_sha1); | ||
| 79 | + break; | ||
| 80 | + case NID_tls12_aes_256_cbc_hmac_sha1: | ||
| 81 | + EVP_add_cipher(&cryptodev_tls12_aes_256_cbc_hmac_sha1); | ||
| 82 | + break; | ||
| 83 | + case NID_tls12_aes_128_cbc_hmac_sha256: | ||
| 84 | + EVP_add_cipher(&cryptodev_tls12_aes_128_cbc_hmac_sha256); | ||
| 85 | + break; | ||
| 86 | + case NID_tls12_aes_256_cbc_hmac_sha256: | ||
| 87 | + EVP_add_cipher(&cryptodev_tls12_aes_256_cbc_hmac_sha256); | ||
| 88 | + break; | ||
| 89 | } | ||
| 90 | } | ||
| 91 | return count; | ||
| 92 | @@ -659,6 +699,11 @@ static int cryptodev_aead_cipher(EVP_CIPHER_CTX *ctx, unsigned char *out, | ||
| 93 | case NID_tls11_des_ede3_cbc_hmac_sha1: | ||
| 94 | case NID_tls11_aes_128_cbc_hmac_sha1: | ||
| 95 | case NID_tls11_aes_256_cbc_hmac_sha1: | ||
| 96 | + case NID_tls12_des_ede3_cbc_hmac_sha1: | ||
| 97 | + case NID_tls12_aes_128_cbc_hmac_sha1: | ||
| 98 | + case NID_tls12_aes_256_cbc_hmac_sha1: | ||
| 99 | + case NID_tls12_aes_128_cbc_hmac_sha256: | ||
| 100 | + case NID_tls12_aes_256_cbc_hmac_sha256: | ||
| 101 | cryp.flags = COP_FLAG_AEAD_TLS_TYPE; | ||
| 102 | } | ||
| 103 | cryp.ses = sess->ses; | ||
| 104 | @@ -856,9 +901,17 @@ static int cryptodev_cbc_hmac_sha1_ctrl(EVP_CIPHER_CTX *ctx, int type, | ||
| 105 | case NID_tls11_des_ede3_cbc_hmac_sha1: | ||
| 106 | case NID_tls11_aes_128_cbc_hmac_sha1: | ||
| 107 | case NID_tls11_aes_256_cbc_hmac_sha1: | ||
| 108 | + case NID_tls12_des_ede3_cbc_hmac_sha1: | ||
| 109 | + case NID_tls12_aes_128_cbc_hmac_sha1: | ||
| 110 | + case NID_tls12_aes_256_cbc_hmac_sha1: | ||
| 111 | maclen = SHA_DIGEST_LENGTH; | ||
| 112 | aad_needs_fix = true; | ||
| 113 | break; | ||
| 114 | + case NID_tls12_aes_128_cbc_hmac_sha256: | ||
| 115 | + case NID_tls12_aes_256_cbc_hmac_sha256: | ||
| 116 | + maclen = SHA256_DIGEST_LENGTH; | ||
| 117 | + aad_needs_fix = true; | ||
| 118 | + break; | ||
| 119 | } | ||
| 120 | |||
| 121 | /* Correct length for AAD Length field */ | ||
| 122 | @@ -1270,6 +1323,76 @@ const EVP_CIPHER cryptodev_tls11_aes_256_cbc_hmac_sha1 = { | ||
| 123 | NULL | ||
| 124 | }; | ||
| 125 | |||
| 126 | +const EVP_CIPHER cryptodev_tls12_3des_cbc_hmac_sha1 = { | ||
| 127 | + NID_tls12_des_ede3_cbc_hmac_sha1, | ||
| 128 | + 8, 24, 8, | ||
| 129 | + EVP_CIPH_CBC_MODE | EVP_CIPH_FLAG_AEAD_CIPHER, | ||
| 130 | + cryptodev_init_aead_key, | ||
| 131 | + cryptodev_aead_cipher, | ||
| 132 | + cryptodev_cleanup, | ||
| 133 | + sizeof(struct dev_crypto_state), | ||
| 134 | + EVP_CIPHER_set_asn1_iv, | ||
| 135 | + EVP_CIPHER_get_asn1_iv, | ||
| 136 | + cryptodev_cbc_hmac_sha1_ctrl, | ||
| 137 | + NULL | ||
| 138 | +}; | ||
| 139 | + | ||
| 140 | +const EVP_CIPHER cryptodev_tls12_aes_128_cbc_hmac_sha1 = { | ||
| 141 | + NID_tls12_aes_128_cbc_hmac_sha1, | ||
| 142 | + 16, 16, 16, | ||
| 143 | + EVP_CIPH_CBC_MODE | EVP_CIPH_FLAG_AEAD_CIPHER, | ||
| 144 | + cryptodev_init_aead_key, | ||
| 145 | + cryptodev_aead_cipher, | ||
| 146 | + cryptodev_cleanup, | ||
| 147 | + sizeof(struct dev_crypto_state), | ||
| 148 | + EVP_CIPHER_set_asn1_iv, | ||
| 149 | + EVP_CIPHER_get_asn1_iv, | ||
| 150 | + cryptodev_cbc_hmac_sha1_ctrl, | ||
| 151 | + NULL | ||
| 152 | +}; | ||
| 153 | + | ||
| 154 | +const EVP_CIPHER cryptodev_tls12_aes_256_cbc_hmac_sha1 = { | ||
| 155 | + NID_tls12_aes_256_cbc_hmac_sha1, | ||
| 156 | + 16, 32, 16, | ||
| 157 | + EVP_CIPH_CBC_MODE | EVP_CIPH_FLAG_AEAD_CIPHER, | ||
| 158 | + cryptodev_init_aead_key, | ||
| 159 | + cryptodev_aead_cipher, | ||
| 160 | + cryptodev_cleanup, | ||
| 161 | + sizeof(struct dev_crypto_state), | ||
| 162 | + EVP_CIPHER_set_asn1_iv, | ||
| 163 | + EVP_CIPHER_get_asn1_iv, | ||
| 164 | + cryptodev_cbc_hmac_sha1_ctrl, | ||
| 165 | + NULL | ||
| 166 | +}; | ||
| 167 | + | ||
| 168 | +const EVP_CIPHER cryptodev_tls12_aes_128_cbc_hmac_sha256 = { | ||
| 169 | + NID_tls12_aes_128_cbc_hmac_sha256, | ||
| 170 | + 16, 16, 16, | ||
| 171 | + EVP_CIPH_CBC_MODE | EVP_CIPH_FLAG_AEAD_CIPHER, | ||
| 172 | + cryptodev_init_aead_key, | ||
| 173 | + cryptodev_aead_cipher, | ||
| 174 | + cryptodev_cleanup, | ||
| 175 | + sizeof(struct dev_crypto_state), | ||
| 176 | + EVP_CIPHER_set_asn1_iv, | ||
| 177 | + EVP_CIPHER_get_asn1_iv, | ||
| 178 | + cryptodev_cbc_hmac_sha1_ctrl, | ||
| 179 | + NULL | ||
| 180 | +}; | ||
| 181 | + | ||
| 182 | +const EVP_CIPHER cryptodev_tls12_aes_256_cbc_hmac_sha256 = { | ||
| 183 | + NID_tls12_aes_256_cbc_hmac_sha256, | ||
| 184 | + 16, 32, 16, | ||
| 185 | + EVP_CIPH_CBC_MODE | EVP_CIPH_FLAG_AEAD_CIPHER, | ||
| 186 | + cryptodev_init_aead_key, | ||
| 187 | + cryptodev_aead_cipher, | ||
| 188 | + cryptodev_cleanup, | ||
| 189 | + sizeof(struct dev_crypto_state), | ||
| 190 | + EVP_CIPHER_set_asn1_iv, | ||
| 191 | + EVP_CIPHER_get_asn1_iv, | ||
| 192 | + cryptodev_cbc_hmac_sha1_ctrl, | ||
| 193 | + NULL | ||
| 194 | +}; | ||
| 195 | + | ||
| 196 | const EVP_CIPHER cryptodev_aes_128_gcm = { | ||
| 197 | NID_aes_128_gcm, | ||
| 198 | 1, 16, 12, | ||
| 199 | @@ -1395,6 +1518,21 @@ cryptodev_engine_ciphers(ENGINE *e, const EVP_CIPHER **cipher, | ||
| 200 | case NID_aes_128_gcm: | ||
| 201 | *cipher = &cryptodev_aes_128_gcm; | ||
| 202 | break; | ||
| 203 | + case NID_tls12_des_ede3_cbc_hmac_sha1: | ||
| 204 | + *cipher = &cryptodev_tls12_3des_cbc_hmac_sha1; | ||
| 205 | + break; | ||
| 206 | + case NID_tls12_aes_128_cbc_hmac_sha1: | ||
| 207 | + *cipher = &cryptodev_tls12_aes_128_cbc_hmac_sha1; | ||
| 208 | + break; | ||
| 209 | + case NID_tls12_aes_256_cbc_hmac_sha1: | ||
| 210 | + *cipher = &cryptodev_tls12_aes_256_cbc_hmac_sha1; | ||
| 211 | + break; | ||
| 212 | + case NID_tls12_aes_128_cbc_hmac_sha256: | ||
| 213 | + *cipher = &cryptodev_tls12_aes_128_cbc_hmac_sha256; | ||
| 214 | + break; | ||
| 215 | + case NID_tls12_aes_256_cbc_hmac_sha256: | ||
| 216 | + *cipher = &cryptodev_tls12_aes_256_cbc_hmac_sha256; | ||
| 217 | + break; | ||
| 218 | default: | ||
| 219 | *cipher = NULL; | ||
| 220 | break; | ||
| 221 | diff --git a/crypto/objects/obj_dat.h b/crypto/objects/obj_dat.h | ||
| 222 | index 4dd32a1..e3a2505 100644 | ||
| 223 | --- a/crypto/objects/obj_dat.h | ||
| 224 | +++ b/crypto/objects/obj_dat.h | ||
| 225 | @@ -62,9 +62,9 @@ | ||
| 226 | * [including the GNU Public Licence.] | ||
| 227 | */ | ||
| 228 | |||
| 229 | -#define NUM_NID 962 | ||
| 230 | -#define NUM_SN 955 | ||
| 231 | -#define NUM_LN 955 | ||
| 232 | +#define NUM_NID 967 | ||
| 233 | +#define NUM_SN 960 | ||
| 234 | +#define NUM_LN 960 | ||
| 235 | #define NUM_OBJ 890 | ||
| 236 | |||
| 237 | static const unsigned char lvalues[6255]={ | ||
| 238 | @@ -2522,6 +2522,16 @@ static const ASN1_OBJECT nid_objs[NUM_NID]={ | ||
| 239 | NID_tls11_aes_128_cbc_hmac_sha1,0,NULL,0}, | ||
| 240 | {"TLS11-AES-256-CBC-HMAC-SHA1","tls11-aes-256-cbc-hmac-sha1", | ||
| 241 | NID_tls11_aes_256_cbc_hmac_sha1,0,NULL,0}, | ||
| 242 | +{"TLS12-DES-EDE3-CBC-HMAC-SHA1","tls12-des-ede3-cbc-hmac-sha1", | ||
| 243 | + NID_tls12_des_ede3_cbc_hmac_sha1,0,NULL,0}, | ||
| 244 | +{"TLS12-AES-128-CBC-HMAC-SHA1","tls12-aes-128-cbc-hmac-sha1", | ||
| 245 | + NID_tls12_aes_128_cbc_hmac_sha1,0,NULL,0}, | ||
| 246 | +{"TLS12-AES-256-CBC-HMAC-SHA1","tls12-aes-256-cbc-hmac-sha1", | ||
| 247 | + NID_tls12_aes_256_cbc_hmac_sha1,0,NULL,0}, | ||
| 248 | +{"TLS12-AES-128-CBC-HMAC-SHA256","tls12-aes-128-cbc-hmac-sha256", | ||
| 249 | + NID_tls12_aes_128_cbc_hmac_sha256,0,NULL,0}, | ||
| 250 | +{"TLS12-AES-256-CBC-HMAC-SHA256","tls12-aes-256-cbc-hmac-sha256", | ||
| 251 | + NID_tls12_aes_256_cbc_hmac_sha256,0,NULL,0}, | ||
| 252 | }; | ||
| 253 | |||
| 254 | static const unsigned int sn_objs[NUM_SN]={ | ||
| 255 | @@ -2714,6 +2724,11 @@ static const unsigned int sn_objs[NUM_SN]={ | ||
| 256 | 960, /* "TLS11-AES-128-CBC-HMAC-SHA1" */ | ||
| 257 | 961, /* "TLS11-AES-256-CBC-HMAC-SHA1" */ | ||
| 258 | 959, /* "TLS11-DES-EDE3-CBC-HMAC-SHA1" */ | ||
| 259 | +963, /* "TLS12-AES-128-CBC-HMAC-SHA1" */ | ||
| 260 | +965, /* "TLS12-AES-128-CBC-HMAC-SHA256" */ | ||
| 261 | +964, /* "TLS12-AES-256-CBC-HMAC-SHA1" */ | ||
| 262 | +966, /* "TLS12-AES-256-CBC-HMAC-SHA256" */ | ||
| 263 | +962, /* "TLS12-DES-EDE3-CBC-HMAC-SHA1" */ | ||
| 264 | 458, /* "UID" */ | ||
| 265 | 0, /* "UNDEF" */ | ||
| 266 | 11, /* "X500" */ | ||
| 267 | @@ -4408,6 +4423,11 @@ static const unsigned int ln_objs[NUM_LN]={ | ||
| 268 | 960, /* "tls11-aes-128-cbc-hmac-sha1" */ | ||
| 269 | 961, /* "tls11-aes-256-cbc-hmac-sha1" */ | ||
| 270 | 959, /* "tls11-des-ede3-cbc-hmac-sha1" */ | ||
| 271 | +963, /* "tls12-aes-128-cbc-hmac-sha1" */ | ||
| 272 | +965, /* "tls12-aes-128-cbc-hmac-sha256" */ | ||
| 273 | +964, /* "tls12-aes-256-cbc-hmac-sha1" */ | ||
| 274 | +966, /* "tls12-aes-256-cbc-hmac-sha256" */ | ||
| 275 | +962, /* "tls12-des-ede3-cbc-hmac-sha1" */ | ||
| 276 | 682, /* "tpBasis" */ | ||
| 277 | 436, /* "ucl" */ | ||
| 278 | 0, /* "undefined" */ | ||
| 279 | diff --git a/crypto/objects/obj_mac.h b/crypto/objects/obj_mac.h | ||
| 280 | index 5930563..f4a81cb 100644 | ||
| 281 | --- a/crypto/objects/obj_mac.h | ||
| 282 | +++ b/crypto/objects/obj_mac.h | ||
| 283 | @@ -4063,6 +4063,26 @@ | ||
| 284 | #define LN_tls11_aes_256_cbc_hmac_sha1 "tls11-aes-256-cbc-hmac-sha1" | ||
| 285 | #define NID_tls11_aes_256_cbc_hmac_sha1 961 | ||
| 286 | |||
| 287 | +#define SN_tls12_des_ede3_cbc_hmac_sha1 "TLS12-DES-EDE3-CBC-HMAC-SHA1" | ||
| 288 | +#define LN_tls12_des_ede3_cbc_hmac_sha1 "tls12-des-ede3-cbc-hmac-sha1" | ||
| 289 | +#define NID_tls12_des_ede3_cbc_hmac_sha1 962 | ||
| 290 | + | ||
| 291 | +#define SN_tls12_aes_128_cbc_hmac_sha1 "TLS12-AES-128-CBC-HMAC-SHA1" | ||
| 292 | +#define LN_tls12_aes_128_cbc_hmac_sha1 "tls12-aes-128-cbc-hmac-sha1" | ||
| 293 | +#define NID_tls12_aes_128_cbc_hmac_sha1 963 | ||
| 294 | + | ||
| 295 | +#define SN_tls12_aes_256_cbc_hmac_sha1 "TLS12-AES-256-CBC-HMAC-SHA1" | ||
| 296 | +#define LN_tls12_aes_256_cbc_hmac_sha1 "tls12-aes-256-cbc-hmac-sha1" | ||
| 297 | +#define NID_tls12_aes_256_cbc_hmac_sha1 964 | ||
| 298 | + | ||
| 299 | +#define SN_tls12_aes_128_cbc_hmac_sha256 "TLS12-AES-128-CBC-HMAC-SHA256" | ||
| 300 | +#define LN_tls12_aes_128_cbc_hmac_sha256 "tls12-aes-128-cbc-hmac-sha256" | ||
| 301 | +#define NID_tls12_aes_128_cbc_hmac_sha256 965 | ||
| 302 | + | ||
| 303 | +#define SN_tls12_aes_256_cbc_hmac_sha256 "TLS12-AES-256-CBC-HMAC-SHA256" | ||
| 304 | +#define LN_tls12_aes_256_cbc_hmac_sha256 "tls12-aes-256-cbc-hmac-sha256" | ||
| 305 | +#define NID_tls12_aes_256_cbc_hmac_sha256 966 | ||
| 306 | + | ||
| 307 | #define SN_dhpublicnumber "dhpublicnumber" | ||
| 308 | #define LN_dhpublicnumber "X9.42 DH" | ||
| 309 | #define NID_dhpublicnumber 920 | ||
| 310 | diff --git a/crypto/objects/obj_mac.num b/crypto/objects/obj_mac.num | ||
| 311 | index 02f1728..401be03 100644 | ||
| 312 | --- a/crypto/objects/obj_mac.num | ||
| 313 | +++ b/crypto/objects/obj_mac.num | ||
| 314 | @@ -959,3 +959,8 @@ des_ede3_cbc_hmac_sha1 958 | ||
| 315 | tls11_des_ede3_cbc_hmac_sha1 959 | ||
| 316 | tls11_aes_128_cbc_hmac_sha1 960 | ||
| 317 | tls11_aes_256_cbc_hmac_sha1 961 | ||
| 318 | +tls12_des_ede3_cbc_hmac_sha1 962 | ||
| 319 | +tls12_aes_128_cbc_hmac_sha1 963 | ||
| 320 | +tls12_aes_256_cbc_hmac_sha1 964 | ||
| 321 | +tls12_aes_128_cbc_hmac_sha256 965 | ||
| 322 | +tls12_aes_256_cbc_hmac_sha256 966 | ||
| 323 | diff --git a/crypto/objects/objects.txt b/crypto/objects/objects.txt | ||
| 324 | index cda81da..68a8da8 100644 | ||
| 325 | --- a/crypto/objects/objects.txt | ||
| 326 | +++ b/crypto/objects/objects.txt | ||
| 327 | @@ -1298,6 +1298,11 @@ kisa 1 6 : SEED-OFB : seed-ofb | ||
| 328 | : TLS11-DES-EDE3-CBC-HMAC-SHA1 : tls11-des-ede3-cbc-hmac-sha1 | ||
| 329 | : TLS11-AES-128-CBC-HMAC-SHA1 : tls11-aes-128-cbc-hmac-sha1 | ||
| 330 | : TLS11-AES-256-CBC-HMAC-SHA1 : tls11-aes-256-cbc-hmac-sha1 | ||
| 331 | + : TLS12-DES-EDE3-CBC-HMAC-SHA1 : tls12-des-ede3-cbc-hmac-sha1 | ||
| 332 | + : TLS12-AES-128-CBC-HMAC-SHA1 : tls12-aes-128-cbc-hmac-sha1 | ||
| 333 | + : TLS12-AES-256-CBC-HMAC-SHA1 : tls12-aes-256-cbc-hmac-sha1 | ||
| 334 | + : TLS12-AES-128-CBC-HMAC-SHA256 : tls12-aes-128-cbc-hmac-sha256 | ||
| 335 | + : TLS12-AES-256-CBC-HMAC-SHA256 : tls12-aes-256-cbc-hmac-sha256 | ||
| 336 | |||
| 337 | ISO-US 10046 2 1 : dhpublicnumber : X9.42 DH | ||
| 338 | |||
| 339 | diff --git a/ssl/ssl_ciph.c b/ssl/ssl_ciph.c | ||
| 340 | index e3d73ac..4698528 100644 | ||
| 341 | --- a/ssl/ssl_ciph.c | ||
| 342 | +++ b/ssl/ssl_ciph.c | ||
| 343 | @@ -690,6 +690,31 @@ int ssl_cipher_get_evp(const SSL_SESSION *s, const EVP_CIPHER **enc, | ||
| 344 | c->algorithm_mac == SSL_SHA1 && | ||
| 345 | (evp = EVP_get_cipherbyname("TLS11-AES-256-CBC-HMAC-SHA1"))) | ||
| 346 | *enc = evp, *md = NULL; | ||
| 347 | + else if (s->ssl_version == TLS1_2_VERSION && | ||
| 348 | + c->algorithm_enc == SSL_3DES && | ||
| 349 | + c->algorithm_mac == SSL_SHA1 && | ||
| 350 | + (evp=EVP_get_cipherbyname("TLS12-DES-EDE3-CBC-HMAC-SHA1"))) | ||
| 351 | + *enc = evp, *md = NULL; | ||
| 352 | + else if (s->ssl_version == TLS1_2_VERSION && | ||
| 353 | + c->algorithm_enc == SSL_AES128 && | ||
| 354 | + c->algorithm_mac == SSL_SHA1 && | ||
| 355 | + (evp=EVP_get_cipherbyname("TLS12-AES-128-CBC-HMAC-SHA1"))) | ||
| 356 | + *enc = evp, *md = NULL; | ||
| 357 | + else if (s->ssl_version == TLS1_2_VERSION && | ||
| 358 | + c->algorithm_enc == SSL_AES256 && | ||
| 359 | + c->algorithm_mac == SSL_SHA1 && | ||
| 360 | + (evp=EVP_get_cipherbyname("TLS12-AES-256-CBC-HMAC-SHA1"))) | ||
| 361 | + *enc = evp, *md = NULL; | ||
| 362 | + else if (s->ssl_version == TLS1_2_VERSION && | ||
| 363 | + c->algorithm_enc == SSL_AES128 && | ||
| 364 | + c->algorithm_mac == SSL_SHA256 && | ||
| 365 | + (evp=EVP_get_cipherbyname("TLS12-AES-128-CBC-HMAC-SHA256"))) | ||
| 366 | + *enc = evp, *md = NULL; | ||
| 367 | + else if (s->ssl_version == TLS1_2_VERSION && | ||
| 368 | + c->algorithm_enc == SSL_AES256 && | ||
| 369 | + c->algorithm_mac == SSL_SHA256 && | ||
| 370 | + (evp=EVP_get_cipherbyname("TLS12-AES-256-CBC-HMAC-SHA256"))) | ||
| 371 | + *enc = evp, *md = NULL; | ||
| 372 | return (1); | ||
| 373 | } else | ||
| 374 | return (0); | ||
| 375 | -- | ||
| 376 | 2.7.0 | ||
| 377 | |||
diff --git a/recipes-connectivity/openssl/openssl-qoriq/qoriq/0018-cryptodev-drop-redundant-function.patch b/recipes-connectivity/openssl/openssl-qoriq/qoriq/0018-cryptodev-drop-redundant-function.patch new file mode 100644 index 000000000..c1f0c9dbe --- /dev/null +++ b/recipes-connectivity/openssl/openssl-qoriq/qoriq/0018-cryptodev-drop-redundant-function.patch | |||
| @@ -0,0 +1,72 @@ | |||
| 1 | From 07d8dad75fb1e4c3487ae560ac51e2141aa0e0c1 Mon Sep 17 00:00:00 2001 | ||
| 2 | From: Cristian Stoica <cristian.stoica@freescale.com> | ||
| 3 | Date: Thu, 19 Feb 2015 16:11:53 +0200 | ||
| 4 | Subject: [PATCH 18/48] cryptodev: drop redundant function | ||
| 5 | |||
| 6 | get_dev_crypto already caches the result. Another cache in-between is | ||
| 7 | useless. | ||
| 8 | |||
| 9 | Signed-off-by: Cristian Stoica <cristian.stoica@freescale.com> | ||
| 10 | --- | ||
| 11 | crypto/engine/eng_cryptodev.c | 17 +++-------------- | ||
| 12 | 1 file changed, 3 insertions(+), 14 deletions(-) | ||
| 13 | |||
| 14 | diff --git a/crypto/engine/eng_cryptodev.c b/crypto/engine/eng_cryptodev.c | ||
| 15 | index e6f9f16..4cffaf1 100644 | ||
| 16 | --- a/crypto/engine/eng_cryptodev.c | ||
| 17 | +++ b/crypto/engine/eng_cryptodev.c | ||
| 18 | @@ -93,7 +93,6 @@ struct dev_crypto_state { | ||
| 19 | |||
| 20 | static u_int32_t cryptodev_asymfeat = 0; | ||
| 21 | |||
| 22 | -static int get_asym_dev_crypto(void); | ||
| 23 | static int open_dev_crypto(void); | ||
| 24 | static int get_dev_crypto(void); | ||
| 25 | static int get_cryptodev_ciphers(const int **cnids); | ||
| 26 | @@ -440,16 +439,6 @@ static void put_dev_crypto(int fd) | ||
| 27 | # endif | ||
| 28 | } | ||
| 29 | |||
| 30 | -/* Caching version for asym operations */ | ||
| 31 | -static int get_asym_dev_crypto(void) | ||
| 32 | -{ | ||
| 33 | - static int fd = -1; | ||
| 34 | - | ||
| 35 | - if (fd == -1) | ||
| 36 | - fd = get_dev_crypto(); | ||
| 37 | - return fd; | ||
| 38 | -} | ||
| 39 | - | ||
| 40 | /* | ||
| 41 | * Find out what ciphers /dev/crypto will let us have a session for. | ||
| 42 | * XXX note, that some of these openssl doesn't deal with yet! | ||
| 43 | @@ -1919,7 +1908,7 @@ cryptodev_asym(struct crypt_kop *kop, int rlen, BIGNUM *r, int slen, | ||
| 44 | { | ||
| 45 | int fd, ret = -1; | ||
| 46 | |||
| 47 | - if ((fd = get_asym_dev_crypto()) < 0) | ||
| 48 | + if ((fd = get_dev_crypto()) < 0) | ||
| 49 | return (ret); | ||
| 50 | |||
| 51 | if (r) { | ||
| 52 | @@ -2509,7 +2498,7 @@ static int cryptodev_rsa_keygen(RSA *rsa, int bits, BIGNUM *e, BN_GENCB *cb) | ||
| 53 | int p_len, q_len; | ||
| 54 | int i; | ||
| 55 | |||
| 56 | - if ((fd = get_asym_dev_crypto()) < 0) | ||
| 57 | + if ((fd = get_dev_crypto()) < 0) | ||
| 58 | goto sw_try; | ||
| 59 | |||
| 60 | if (!rsa->n && ((rsa->n = BN_new()) == NULL)) | ||
| 61 | @@ -4098,7 +4087,7 @@ cryptodev_dh_compute_key(unsigned char *key, const BIGNUM *pub_key, DH *dh) | ||
| 62 | BIGNUM *temp = NULL; | ||
| 63 | unsigned char *padded_pub_key = NULL, *p = NULL; | ||
| 64 | |||
| 65 | - if ((fd = get_asym_dev_crypto()) < 0) | ||
| 66 | + if ((fd = get_dev_crypto()) < 0) | ||
| 67 | goto sw_try; | ||
| 68 | |||
| 69 | memset(&kop, 0, sizeof kop); | ||
| 70 | -- | ||
| 71 | 2.7.0 | ||
| 72 | |||
diff --git a/recipes-connectivity/openssl/openssl-qoriq/qoriq/0018-eng_cryptodev-extend-TLS-offload-with-3des_cbc_hmac_.patch b/recipes-connectivity/openssl/openssl-qoriq/qoriq/0018-eng_cryptodev-extend-TLS-offload-with-3des_cbc_hmac_.patch deleted file mode 100644 index 1118a6fc3..000000000 --- a/recipes-connectivity/openssl/openssl-qoriq/qoriq/0018-eng_cryptodev-extend-TLS-offload-with-3des_cbc_hmac_.patch +++ /dev/null | |||
| @@ -1,193 +0,0 @@ | |||
| 1 | From 21e3ca4ec77f9258aa4001f07faac1c4942b48b4 Mon Sep 17 00:00:00 2001 | ||
| 2 | From: Tudor Ambarus <tudor.ambarus@freescale.com> | ||
| 3 | Date: Fri, 9 May 2014 17:54:06 +0300 | ||
| 4 | Subject: [PATCH 18/26] eng_cryptodev: extend TLS offload with | ||
| 5 | 3des_cbc_hmac_sha1 | ||
| 6 | |||
| 7 | Both obj_mac.h and obj_dat.h were generated using the scripts | ||
| 8 | from crypto/objects: | ||
| 9 | |||
| 10 | $ cd crypto/objects | ||
| 11 | $ perl objects.pl objects.txt obj_mac.num obj_mac.h | ||
| 12 | $ perl obj_dat.pl obj_mac.h obj_dat.h | ||
| 13 | |||
| 14 | Change-Id: I94f13cdd09df67e33e6acd3c00aab47cb358ac46 | ||
| 15 | Signed-off-by: Tudor Ambarus <tudor.ambarus@freescale.com> | ||
| 16 | Signed-off-by: Cristian Stoica <cristian.stoica@freescale.com> | ||
| 17 | Reviewed-on: http://git.am.freescale.net:8181/34001 | ||
| 18 | --- | ||
| 19 | crypto/engine/eng_cryptodev.c | 24 ++++++++++++++++++++++++ | ||
| 20 | crypto/objects/obj_dat.h | 10 +++++++--- | ||
| 21 | crypto/objects/obj_mac.h | 4 ++++ | ||
| 22 | crypto/objects/obj_mac.num | 1 + | ||
| 23 | crypto/objects/objects.txt | 1 + | ||
| 24 | ssl/ssl_ciph.c | 4 ++++ | ||
| 25 | 6 files changed, 41 insertions(+), 3 deletions(-) | ||
| 26 | |||
| 27 | diff --git a/crypto/engine/eng_cryptodev.c b/crypto/engine/eng_cryptodev.c | ||
| 28 | index 79b2678..299e84b 100644 | ||
| 29 | --- a/crypto/engine/eng_cryptodev.c | ||
| 30 | +++ b/crypto/engine/eng_cryptodev.c | ||
| 31 | @@ -135,6 +135,7 @@ static int cryptodev_ctrl(ENGINE *e, int cmd, long i, void *p, | ||
| 32 | void ENGINE_load_cryptodev(void); | ||
| 33 | const EVP_CIPHER cryptodev_aes_128_cbc_hmac_sha1; | ||
| 34 | const EVP_CIPHER cryptodev_aes_256_cbc_hmac_sha1; | ||
| 35 | +const EVP_CIPHER cryptodev_3des_cbc_hmac_sha1; | ||
| 36 | |||
| 37 | inline int spcf_bn2bin(BIGNUM *bn, unsigned char **bin, int *bin_len) | ||
| 38 | { | ||
| 39 | @@ -252,6 +253,7 @@ static struct { | ||
| 40 | { CRYPTO_BLF_CBC, NID_bf_cbc, 8, 16, 0}, | ||
| 41 | { CRYPTO_CAST_CBC, NID_cast5_cbc, 8, 16, 0}, | ||
| 42 | { CRYPTO_SKIPJACK_CBC, NID_undef, 0, 0, 0}, | ||
| 43 | + { CRYPTO_TLS10_3DES_CBC_HMAC_SHA1, NID_des_ede3_cbc_hmac_sha1, 8, 24, 20}, | ||
| 44 | { CRYPTO_TLS10_AES_CBC_HMAC_SHA1, NID_aes_128_cbc_hmac_sha1, 16, 16, 20}, | ||
| 45 | { CRYPTO_TLS10_AES_CBC_HMAC_SHA1, NID_aes_256_cbc_hmac_sha1, 16, 32, 20}, | ||
| 46 | { CRYPTO_AES_GCM, NID_aes_128_gcm, 16, 16, 0}, | ||
| 47 | @@ -466,6 +468,9 @@ cryptodev_usable_ciphers(const int **nids) | ||
| 48 | case NID_aes_256_cbc_hmac_sha1: | ||
| 49 | EVP_add_cipher(&cryptodev_aes_256_cbc_hmac_sha1); | ||
| 50 | break; | ||
| 51 | + case NID_des_ede3_cbc_hmac_sha1: | ||
| 52 | + EVP_add_cipher(&cryptodev_3des_cbc_hmac_sha1); | ||
| 53 | + break; | ||
| 54 | } | ||
| 55 | } | ||
| 56 | return count; | ||
| 57 | @@ -571,6 +576,7 @@ static int cryptodev_aead_cipher(EVP_CIPHER_CTX *ctx, unsigned char *out, | ||
| 58 | switch (ctx->cipher->nid) { | ||
| 59 | case NID_aes_128_cbc_hmac_sha1: | ||
| 60 | case NID_aes_256_cbc_hmac_sha1: | ||
| 61 | + case NID_des_ede3_cbc_hmac_sha1: | ||
| 62 | cryp.flags = COP_FLAG_AEAD_TLS_TYPE; | ||
| 63 | } | ||
| 64 | cryp.ses = sess->ses; | ||
| 65 | @@ -763,6 +769,7 @@ static int cryptodev_cbc_hmac_sha1_ctrl(EVP_CIPHER_CTX *ctx, int type, int arg, | ||
| 66 | switch (ctx->cipher->nid) { | ||
| 67 | case NID_aes_128_cbc_hmac_sha1: | ||
| 68 | case NID_aes_256_cbc_hmac_sha1: | ||
| 69 | + case NID_des_ede3_cbc_hmac_sha1: | ||
| 70 | maclen = SHA_DIGEST_LENGTH; | ||
| 71 | } | ||
| 72 | |||
| 73 | @@ -1082,6 +1089,20 @@ const EVP_CIPHER cryptodev_aes_256_cbc = { | ||
| 74 | NULL | ||
| 75 | }; | ||
| 76 | |||
| 77 | +const EVP_CIPHER cryptodev_3des_cbc_hmac_sha1 = { | ||
| 78 | + NID_des_ede3_cbc_hmac_sha1, | ||
| 79 | + 8, 24, 8, | ||
| 80 | + EVP_CIPH_CBC_MODE | EVP_CIPH_FLAG_AEAD_CIPHER, | ||
| 81 | + cryptodev_init_aead_key, | ||
| 82 | + cryptodev_aead_cipher, | ||
| 83 | + cryptodev_cleanup, | ||
| 84 | + sizeof(struct dev_crypto_state), | ||
| 85 | + EVP_CIPHER_set_asn1_iv, | ||
| 86 | + EVP_CIPHER_get_asn1_iv, | ||
| 87 | + cryptodev_cbc_hmac_sha1_ctrl, | ||
| 88 | + NULL | ||
| 89 | +}; | ||
| 90 | + | ||
| 91 | const EVP_CIPHER cryptodev_aes_128_cbc_hmac_sha1 = { | ||
| 92 | NID_aes_128_cbc_hmac_sha1, | ||
| 93 | 16, 16, 16, | ||
| 94 | @@ -1163,6 +1184,9 @@ cryptodev_engine_ciphers(ENGINE *e, const EVP_CIPHER **cipher, | ||
| 95 | case NID_aes_256_cbc: | ||
| 96 | *cipher = &cryptodev_aes_256_cbc; | ||
| 97 | break; | ||
| 98 | + case NID_des_ede3_cbc_hmac_sha1: | ||
| 99 | + *cipher = &cryptodev_3des_cbc_hmac_sha1; | ||
| 100 | + break; | ||
| 101 | case NID_aes_128_cbc_hmac_sha1: | ||
| 102 | *cipher = &cryptodev_aes_128_cbc_hmac_sha1; | ||
| 103 | break; | ||
| 104 | diff --git a/crypto/objects/obj_dat.h b/crypto/objects/obj_dat.h | ||
| 105 | index bc69665..9f2267a 100644 | ||
| 106 | --- a/crypto/objects/obj_dat.h | ||
| 107 | +++ b/crypto/objects/obj_dat.h | ||
| 108 | @@ -62,9 +62,9 @@ | ||
| 109 | * [including the GNU Public Licence.] | ||
| 110 | */ | ||
| 111 | |||
| 112 | -#define NUM_NID 920 | ||
| 113 | -#define NUM_SN 913 | ||
| 114 | -#define NUM_LN 913 | ||
| 115 | +#define NUM_NID 921 | ||
| 116 | +#define NUM_SN 914 | ||
| 117 | +#define NUM_LN 914 | ||
| 118 | #define NUM_OBJ 857 | ||
| 119 | |||
| 120 | static const unsigned char lvalues[5974]={ | ||
| 121 | @@ -2399,6 +2399,8 @@ static const ASN1_OBJECT nid_objs[NUM_NID]={ | ||
| 122 | {"AES-256-CBC-HMAC-SHA1","aes-256-cbc-hmac-sha1", | ||
| 123 | NID_aes_256_cbc_hmac_sha1,0,NULL,0}, | ||
| 124 | {"RSAES-OAEP","rsaesOaep",NID_rsaesOaep,9,&(lvalues[5964]),0}, | ||
| 125 | +{"DES-EDE3-CBC-HMAC-SHA1","des-ede3-cbc-hmac-sha1", | ||
| 126 | + NID_des_ede3_cbc_hmac_sha1,0,NULL,0}, | ||
| 127 | }; | ||
| 128 | |||
| 129 | static const unsigned int sn_objs[NUM_SN]={ | ||
| 130 | @@ -2474,6 +2476,7 @@ static const unsigned int sn_objs[NUM_SN]={ | ||
| 131 | 62, /* "DES-EDE-OFB" */ | ||
| 132 | 33, /* "DES-EDE3" */ | ||
| 133 | 44, /* "DES-EDE3-CBC" */ | ||
| 134 | +920, /* "DES-EDE3-CBC-HMAC-SHA1" */ | ||
| 135 | 61, /* "DES-EDE3-CFB" */ | ||
| 136 | 658, /* "DES-EDE3-CFB1" */ | ||
| 137 | 659, /* "DES-EDE3-CFB8" */ | ||
| 138 | @@ -3585,6 +3588,7 @@ static const unsigned int ln_objs[NUM_LN]={ | ||
| 139 | 62, /* "des-ede-ofb" */ | ||
| 140 | 33, /* "des-ede3" */ | ||
| 141 | 44, /* "des-ede3-cbc" */ | ||
| 142 | +920, /* "des-ede3-cbc-hmac-sha1" */ | ||
| 143 | 61, /* "des-ede3-cfb" */ | ||
| 144 | 658, /* "des-ede3-cfb1" */ | ||
| 145 | 659, /* "des-ede3-cfb8" */ | ||
| 146 | diff --git a/crypto/objects/obj_mac.h b/crypto/objects/obj_mac.h | ||
| 147 | index b5ea7cd..8751902 100644 | ||
| 148 | --- a/crypto/objects/obj_mac.h | ||
| 149 | +++ b/crypto/objects/obj_mac.h | ||
| 150 | @@ -4030,3 +4030,7 @@ | ||
| 151 | #define LN_aes_256_cbc_hmac_sha1 "aes-256-cbc-hmac-sha1" | ||
| 152 | #define NID_aes_256_cbc_hmac_sha1 918 | ||
| 153 | |||
| 154 | +#define SN_des_ede3_cbc_hmac_sha1 "DES-EDE3-CBC-HMAC-SHA1" | ||
| 155 | +#define LN_des_ede3_cbc_hmac_sha1 "des-ede3-cbc-hmac-sha1" | ||
| 156 | +#define NID_des_ede3_cbc_hmac_sha1 920 | ||
| 157 | + | ||
| 158 | diff --git a/crypto/objects/obj_mac.num b/crypto/objects/obj_mac.num | ||
| 159 | index 1d0a7c8..9d44bb5 100644 | ||
| 160 | --- a/crypto/objects/obj_mac.num | ||
| 161 | +++ b/crypto/objects/obj_mac.num | ||
| 162 | @@ -917,3 +917,4 @@ aes_128_cbc_hmac_sha1 916 | ||
| 163 | aes_192_cbc_hmac_sha1 917 | ||
| 164 | aes_256_cbc_hmac_sha1 918 | ||
| 165 | rsaesOaep 919 | ||
| 166 | +des_ede3_cbc_hmac_sha1 920 | ||
| 167 | diff --git a/crypto/objects/objects.txt b/crypto/objects/objects.txt | ||
| 168 | index d3bfad7..90d2fc5 100644 | ||
| 169 | --- a/crypto/objects/objects.txt | ||
| 170 | +++ b/crypto/objects/objects.txt | ||
| 171 | @@ -1290,3 +1290,4 @@ kisa 1 6 : SEED-OFB : seed-ofb | ||
| 172 | : AES-128-CBC-HMAC-SHA1 : aes-128-cbc-hmac-sha1 | ||
| 173 | : AES-192-CBC-HMAC-SHA1 : aes-192-cbc-hmac-sha1 | ||
| 174 | : AES-256-CBC-HMAC-SHA1 : aes-256-cbc-hmac-sha1 | ||
| 175 | + : DES-EDE3-CBC-HMAC-SHA1 : des-ede3-cbc-hmac-sha1 | ||
| 176 | diff --git a/ssl/ssl_ciph.c b/ssl/ssl_ciph.c | ||
| 177 | index 8188ff5..310fe76 100644 | ||
| 178 | --- a/ssl/ssl_ciph.c | ||
| 179 | +++ b/ssl/ssl_ciph.c | ||
| 180 | @@ -639,6 +639,10 @@ int ssl_cipher_get_evp(const SSL_SESSION *s, const EVP_CIPHER **enc, | ||
| 181 | c->algorithm_mac == SSL_SHA1 && | ||
| 182 | (evp=EVP_get_cipherbyname("AES-256-CBC-HMAC-SHA1"))) | ||
| 183 | *enc = evp, *md = NULL; | ||
| 184 | + else if (c->algorithm_enc == SSL_3DES && | ||
| 185 | + c->algorithm_mac == SSL_SHA1 && | ||
| 186 | + (evp = EVP_get_cipherbyname("DES-EDE3-CBC-HMAC-SHA1"))) | ||
| 187 | + *enc = evp, *md = NULL; | ||
| 188 | return(1); | ||
| 189 | } | ||
| 190 | else | ||
| 191 | -- | ||
| 192 | 2.3.5 | ||
| 193 | |||
diff --git a/recipes-connectivity/openssl/openssl-qoriq/qoriq/0019-cryptodev-do-not-zero-the-buffer-before-use.patch b/recipes-connectivity/openssl/openssl-qoriq/qoriq/0019-cryptodev-do-not-zero-the-buffer-before-use.patch new file mode 100644 index 000000000..248d88ec1 --- /dev/null +++ b/recipes-connectivity/openssl/openssl-qoriq/qoriq/0019-cryptodev-do-not-zero-the-buffer-before-use.patch | |||
| @@ -0,0 +1,48 @@ | |||
| 1 | From 1f7ef531a010a3a86c9c16f801044b5f01652eb2 Mon Sep 17 00:00:00 2001 | ||
| 2 | From: Cristian Stoica <cristian.stoica@freescale.com> | ||
| 3 | Date: Tue, 17 Feb 2015 13:12:53 +0200 | ||
| 4 | Subject: [PATCH 19/48] cryptodev: do not zero the buffer before use | ||
| 5 | |||
| 6 | - The buffer is just about to be overwritten. Zeroing it before that has | ||
| 7 | no purpose | ||
| 8 | |||
| 9 | Change-Id: I478c31bd2e254561474a7edf5e37980ca04217ce | ||
| 10 | Signed-off-by: Cristian Stoica <cristian.stoica@freescale.com> | ||
| 11 | Reviewed-on: http://git.am.freescale.net:8181/34217 | ||
| 12 | --- | ||
| 13 | crypto/engine/eng_cryptodev.c | 14 ++++---------- | ||
| 14 | 1 file changed, 4 insertions(+), 10 deletions(-) | ||
| 15 | |||
| 16 | diff --git a/crypto/engine/eng_cryptodev.c b/crypto/engine/eng_cryptodev.c | ||
| 17 | index 4cffaf1..bbc903b 100644 | ||
| 18 | --- a/crypto/engine/eng_cryptodev.c | ||
| 19 | +++ b/crypto/engine/eng_cryptodev.c | ||
| 20 | @@ -1801,21 +1801,15 @@ cryptodev_engine_digests(ENGINE *e, const EVP_MD **digest, | ||
| 21 | static int bn2crparam(const BIGNUM *a, struct crparam *crp) | ||
| 22 | { | ||
| 23 | ssize_t bytes, bits; | ||
| 24 | - u_char *b; | ||
| 25 | - | ||
| 26 | - crp->crp_p = NULL; | ||
| 27 | - crp->crp_nbits = 0; | ||
| 28 | |||
| 29 | bits = BN_num_bits(a); | ||
| 30 | bytes = (bits + 7) / 8; | ||
| 31 | |||
| 32 | - b = malloc(bytes); | ||
| 33 | - if (b == NULL) | ||
| 34 | - return (1); | ||
| 35 | - memset(b, 0, bytes); | ||
| 36 | - | ||
| 37 | - crp->crp_p = (caddr_t) b; | ||
| 38 | crp->crp_nbits = bits; | ||
| 39 | + crp->crp_p = malloc(bytes); | ||
| 40 | + | ||
| 41 | + if (crp->crp_p == NULL) | ||
| 42 | + return (1); | ||
| 43 | |||
| 44 | BN_bn2bin(a, crp->crp_p); | ||
| 45 | return (0); | ||
| 46 | -- | ||
| 47 | 2.7.0 | ||
| 48 | |||
diff --git a/recipes-connectivity/openssl/openssl-qoriq/qoriq/0019-eng_cryptodev-add-support-for-TLSv1.1-record-offload.patch b/recipes-connectivity/openssl/openssl-qoriq/qoriq/0019-eng_cryptodev-add-support-for-TLSv1.1-record-offload.patch deleted file mode 100644 index 988d79ea6..000000000 --- a/recipes-connectivity/openssl/openssl-qoriq/qoriq/0019-eng_cryptodev-add-support-for-TLSv1.1-record-offload.patch +++ /dev/null | |||
| @@ -1,355 +0,0 @@ | |||
| 1 | From 1de2b740a3bdcd8e98abb5f4e176d46fd817b932 Mon Sep 17 00:00:00 2001 | ||
| 2 | From: Tudor Ambarus <tudor.ambarus@freescale.com> | ||
| 3 | Date: Tue, 31 Mar 2015 16:30:17 +0300 | ||
| 4 | Subject: [PATCH 19/26] eng_cryptodev: add support for TLSv1.1 record offload | ||
| 5 | |||
| 6 | Supported cipher suites: | ||
| 7 | - 3des-ede-cbc-sha | ||
| 8 | - aes-128-cbc-hmac-sha | ||
| 9 | - aes-256-cbc-hmac-sha | ||
| 10 | |||
| 11 | Requires TLS patches on cryptodev and TLS algorithm support in Linux | ||
| 12 | kernel driver. | ||
| 13 | |||
| 14 | Signed-off-by: Tudor Ambarus <tudor.ambarus@freescale.com> | ||
| 15 | Change-Id: Id414f36a528de3f476b72688cf85714787d7ccae | ||
| 16 | Reviewed-on: http://git.am.freescale.net:8181/34002 | ||
| 17 | Reviewed-by: Cristian Stoica <cristian.stoica@freescale.com> | ||
| 18 | Tested-by: Cristian Stoica <cristian.stoica@freescale.com> | ||
| 19 | --- | ||
| 20 | crypto/engine/eng_cryptodev.c | 101 ++++++++++++++++++++++++++++++++++++++---- | ||
| 21 | crypto/objects/obj_dat.h | 18 ++++++-- | ||
| 22 | crypto/objects/obj_mac.h | 12 +++++ | ||
| 23 | crypto/objects/obj_mac.num | 3 ++ | ||
| 24 | crypto/objects/objects.txt | 3 ++ | ||
| 25 | ssl/ssl_ciph.c | 26 +++++++++-- | ||
| 26 | 6 files changed, 148 insertions(+), 15 deletions(-) | ||
| 27 | |||
| 28 | diff --git a/crypto/engine/eng_cryptodev.c b/crypto/engine/eng_cryptodev.c | ||
| 29 | index 299e84b..f71ab27 100644 | ||
| 30 | --- a/crypto/engine/eng_cryptodev.c | ||
| 31 | +++ b/crypto/engine/eng_cryptodev.c | ||
| 32 | @@ -66,6 +66,7 @@ ENGINE_load_cryptodev(void) | ||
| 33 | #include <sys/ioctl.h> | ||
| 34 | #include <errno.h> | ||
| 35 | #include <stdio.h> | ||
| 36 | +#include <stdbool.h> | ||
| 37 | #include <unistd.h> | ||
| 38 | #include <fcntl.h> | ||
| 39 | #include <stdarg.h> | ||
| 40 | @@ -133,9 +134,12 @@ static int cryptodev_dh_compute_key(unsigned char *key, | ||
| 41 | static int cryptodev_ctrl(ENGINE *e, int cmd, long i, void *p, | ||
| 42 | void (*f)(void)); | ||
| 43 | void ENGINE_load_cryptodev(void); | ||
| 44 | +const EVP_CIPHER cryptodev_3des_cbc_hmac_sha1; | ||
| 45 | const EVP_CIPHER cryptodev_aes_128_cbc_hmac_sha1; | ||
| 46 | const EVP_CIPHER cryptodev_aes_256_cbc_hmac_sha1; | ||
| 47 | -const EVP_CIPHER cryptodev_3des_cbc_hmac_sha1; | ||
| 48 | +const EVP_CIPHER cryptodev_tls11_3des_cbc_hmac_sha1; | ||
| 49 | +const EVP_CIPHER cryptodev_tls11_aes_128_cbc_hmac_sha1; | ||
| 50 | +const EVP_CIPHER cryptodev_tls11_aes_256_cbc_hmac_sha1; | ||
| 51 | |||
| 52 | inline int spcf_bn2bin(BIGNUM *bn, unsigned char **bin, int *bin_len) | ||
| 53 | { | ||
| 54 | @@ -256,6 +260,9 @@ static struct { | ||
| 55 | { CRYPTO_TLS10_3DES_CBC_HMAC_SHA1, NID_des_ede3_cbc_hmac_sha1, 8, 24, 20}, | ||
| 56 | { CRYPTO_TLS10_AES_CBC_HMAC_SHA1, NID_aes_128_cbc_hmac_sha1, 16, 16, 20}, | ||
| 57 | { CRYPTO_TLS10_AES_CBC_HMAC_SHA1, NID_aes_256_cbc_hmac_sha1, 16, 32, 20}, | ||
| 58 | + { CRYPTO_TLS11_3DES_CBC_HMAC_SHA1, NID_tls11_des_ede3_cbc_hmac_sha1, 8, 24, 20}, | ||
| 59 | + { CRYPTO_TLS11_AES_CBC_HMAC_SHA1, NID_tls11_aes_128_cbc_hmac_sha1, 16, 16, 20}, | ||
| 60 | + { CRYPTO_TLS11_AES_CBC_HMAC_SHA1, NID_tls11_aes_256_cbc_hmac_sha1, 16, 32, 20}, | ||
| 61 | { CRYPTO_AES_GCM, NID_aes_128_gcm, 16, 16, 0}, | ||
| 62 | { 0, NID_undef, 0, 0, 0}, | ||
| 63 | }; | ||
| 64 | @@ -462,14 +469,23 @@ cryptodev_usable_ciphers(const int **nids) | ||
| 65 | /* add ciphers specific to cryptodev if found in kernel */ | ||
| 66 | for(i = 0; i < count; i++) { | ||
| 67 | switch (*(*nids + i)) { | ||
| 68 | + case NID_des_ede3_cbc_hmac_sha1: | ||
| 69 | + EVP_add_cipher(&cryptodev_3des_cbc_hmac_sha1); | ||
| 70 | + break; | ||
| 71 | case NID_aes_128_cbc_hmac_sha1: | ||
| 72 | EVP_add_cipher(&cryptodev_aes_128_cbc_hmac_sha1); | ||
| 73 | break; | ||
| 74 | case NID_aes_256_cbc_hmac_sha1: | ||
| 75 | EVP_add_cipher(&cryptodev_aes_256_cbc_hmac_sha1); | ||
| 76 | break; | ||
| 77 | - case NID_des_ede3_cbc_hmac_sha1: | ||
| 78 | - EVP_add_cipher(&cryptodev_3des_cbc_hmac_sha1); | ||
| 79 | + case NID_tls11_des_ede3_cbc_hmac_sha1: | ||
| 80 | + EVP_add_cipher(&cryptodev_tls11_3des_cbc_hmac_sha1); | ||
| 81 | + break; | ||
| 82 | + case NID_tls11_aes_128_cbc_hmac_sha1: | ||
| 83 | + EVP_add_cipher(&cryptodev_tls11_aes_128_cbc_hmac_sha1); | ||
| 84 | + break; | ||
| 85 | + case NID_tls11_aes_256_cbc_hmac_sha1: | ||
| 86 | + EVP_add_cipher(&cryptodev_tls11_aes_256_cbc_hmac_sha1); | ||
| 87 | break; | ||
| 88 | } | ||
| 89 | } | ||
| 90 | @@ -574,9 +590,12 @@ static int cryptodev_aead_cipher(EVP_CIPHER_CTX *ctx, unsigned char *out, | ||
| 91 | |||
| 92 | /* TODO: make a seamless integration with cryptodev flags */ | ||
| 93 | switch (ctx->cipher->nid) { | ||
| 94 | + case NID_des_ede3_cbc_hmac_sha1: | ||
| 95 | case NID_aes_128_cbc_hmac_sha1: | ||
| 96 | case NID_aes_256_cbc_hmac_sha1: | ||
| 97 | - case NID_des_ede3_cbc_hmac_sha1: | ||
| 98 | + case NID_tls11_des_ede3_cbc_hmac_sha1: | ||
| 99 | + case NID_tls11_aes_128_cbc_hmac_sha1: | ||
| 100 | + case NID_tls11_aes_256_cbc_hmac_sha1: | ||
| 101 | cryp.flags = COP_FLAG_AEAD_TLS_TYPE; | ||
| 102 | } | ||
| 103 | cryp.ses = sess->ses; | ||
| 104 | @@ -758,8 +777,9 @@ static int cryptodev_cbc_hmac_sha1_ctrl(EVP_CIPHER_CTX *ctx, int type, int arg, | ||
| 105 | struct dev_crypto_state *state = ctx->cipher_data; | ||
| 106 | unsigned char *p = ptr; | ||
| 107 | unsigned int cryptlen = p[arg - 2] << 8 | p[arg - 1]; | ||
| 108 | - unsigned int maclen, padlen; | ||
| 109 | + unsigned int maclen, padlen, len; | ||
| 110 | unsigned int bs = ctx->cipher->block_size; | ||
| 111 | + bool aad_needs_fix = false; | ||
| 112 | |||
| 113 | state->aad = ptr; | ||
| 114 | state->aad_len = arg; | ||
| 115 | @@ -767,10 +787,24 @@ static int cryptodev_cbc_hmac_sha1_ctrl(EVP_CIPHER_CTX *ctx, int type, int arg, | ||
| 116 | |||
| 117 | /* TODO: this should be an extension of EVP_CIPHER struct */ | ||
| 118 | switch (ctx->cipher->nid) { | ||
| 119 | + case NID_des_ede3_cbc_hmac_sha1: | ||
| 120 | case NID_aes_128_cbc_hmac_sha1: | ||
| 121 | case NID_aes_256_cbc_hmac_sha1: | ||
| 122 | - case NID_des_ede3_cbc_hmac_sha1: | ||
| 123 | maclen = SHA_DIGEST_LENGTH; | ||
| 124 | + break; | ||
| 125 | + case NID_tls11_des_ede3_cbc_hmac_sha1: | ||
| 126 | + case NID_tls11_aes_128_cbc_hmac_sha1: | ||
| 127 | + case NID_tls11_aes_256_cbc_hmac_sha1: | ||
| 128 | + maclen = SHA_DIGEST_LENGTH; | ||
| 129 | + aad_needs_fix = true; | ||
| 130 | + break; | ||
| 131 | + } | ||
| 132 | + | ||
| 133 | + /* Correct length for AAD Length field */ | ||
| 134 | + if (ctx->encrypt && aad_needs_fix) { | ||
| 135 | + len = cryptlen - bs; | ||
| 136 | + p[arg-2] = len >> 8; | ||
| 137 | + p[arg-1] = len & 0xff; | ||
| 138 | } | ||
| 139 | |||
| 140 | /* space required for encryption (not only TLS padding) */ | ||
| 141 | @@ -1131,6 +1165,48 @@ const EVP_CIPHER cryptodev_aes_256_cbc_hmac_sha1 = { | ||
| 142 | NULL | ||
| 143 | }; | ||
| 144 | |||
| 145 | +const EVP_CIPHER cryptodev_tls11_3des_cbc_hmac_sha1 = { | ||
| 146 | + NID_tls11_des_ede3_cbc_hmac_sha1, | ||
| 147 | + 8, 24, 8, | ||
| 148 | + EVP_CIPH_CBC_MODE | EVP_CIPH_FLAG_AEAD_CIPHER, | ||
| 149 | + cryptodev_init_aead_key, | ||
| 150 | + cryptodev_aead_cipher, | ||
| 151 | + cryptodev_cleanup, | ||
| 152 | + sizeof(struct dev_crypto_state), | ||
| 153 | + EVP_CIPHER_set_asn1_iv, | ||
| 154 | + EVP_CIPHER_get_asn1_iv, | ||
| 155 | + cryptodev_cbc_hmac_sha1_ctrl, | ||
| 156 | + NULL | ||
| 157 | +}; | ||
| 158 | + | ||
| 159 | +const EVP_CIPHER cryptodev_tls11_aes_128_cbc_hmac_sha1 = { | ||
| 160 | + NID_tls11_aes_128_cbc_hmac_sha1, | ||
| 161 | + 16, 16, 16, | ||
| 162 | + EVP_CIPH_CBC_MODE | EVP_CIPH_FLAG_AEAD_CIPHER, | ||
| 163 | + cryptodev_init_aead_key, | ||
| 164 | + cryptodev_aead_cipher, | ||
| 165 | + cryptodev_cleanup, | ||
| 166 | + sizeof(struct dev_crypto_state), | ||
| 167 | + EVP_CIPHER_set_asn1_iv, | ||
| 168 | + EVP_CIPHER_get_asn1_iv, | ||
| 169 | + cryptodev_cbc_hmac_sha1_ctrl, | ||
| 170 | + NULL | ||
| 171 | +}; | ||
| 172 | + | ||
| 173 | +const EVP_CIPHER cryptodev_tls11_aes_256_cbc_hmac_sha1 = { | ||
| 174 | + NID_tls11_aes_256_cbc_hmac_sha1, | ||
| 175 | + 16, 32, 16, | ||
| 176 | + EVP_CIPH_CBC_MODE | EVP_CIPH_FLAG_AEAD_CIPHER, | ||
| 177 | + cryptodev_init_aead_key, | ||
| 178 | + cryptodev_aead_cipher, | ||
| 179 | + cryptodev_cleanup, | ||
| 180 | + sizeof(struct dev_crypto_state), | ||
| 181 | + EVP_CIPHER_set_asn1_iv, | ||
| 182 | + EVP_CIPHER_get_asn1_iv, | ||
| 183 | + cryptodev_cbc_hmac_sha1_ctrl, | ||
| 184 | + NULL | ||
| 185 | +}; | ||
| 186 | + | ||
| 187 | const EVP_CIPHER cryptodev_aes_128_gcm = { | ||
| 188 | NID_aes_128_gcm, | ||
| 189 | 1, 16, 12, | ||
| 190 | @@ -1184,6 +1260,9 @@ cryptodev_engine_ciphers(ENGINE *e, const EVP_CIPHER **cipher, | ||
| 191 | case NID_aes_256_cbc: | ||
| 192 | *cipher = &cryptodev_aes_256_cbc; | ||
| 193 | break; | ||
| 194 | + case NID_aes_128_gcm: | ||
| 195 | + *cipher = &cryptodev_aes_128_gcm; | ||
| 196 | + break; | ||
| 197 | case NID_des_ede3_cbc_hmac_sha1: | ||
| 198 | *cipher = &cryptodev_3des_cbc_hmac_sha1; | ||
| 199 | break; | ||
| 200 | @@ -1193,8 +1272,14 @@ cryptodev_engine_ciphers(ENGINE *e, const EVP_CIPHER **cipher, | ||
| 201 | case NID_aes_256_cbc_hmac_sha1: | ||
| 202 | *cipher = &cryptodev_aes_256_cbc_hmac_sha1; | ||
| 203 | break; | ||
| 204 | - case NID_aes_128_gcm: | ||
| 205 | - *cipher = &cryptodev_aes_128_gcm; | ||
| 206 | + case NID_tls11_des_ede3_cbc_hmac_sha1: | ||
| 207 | + *cipher = &cryptodev_tls11_3des_cbc_hmac_sha1; | ||
| 208 | + break; | ||
| 209 | + case NID_tls11_aes_128_cbc_hmac_sha1: | ||
| 210 | + *cipher = &cryptodev_tls11_aes_128_cbc_hmac_sha1; | ||
| 211 | + break; | ||
| 212 | + case NID_tls11_aes_256_cbc_hmac_sha1: | ||
| 213 | + *cipher = &cryptodev_tls11_aes_256_cbc_hmac_sha1; | ||
| 214 | break; | ||
| 215 | default: | ||
| 216 | *cipher = NULL; | ||
| 217 | diff --git a/crypto/objects/obj_dat.h b/crypto/objects/obj_dat.h | ||
| 218 | index 9f2267a..dc89b0a 100644 | ||
| 219 | --- a/crypto/objects/obj_dat.h | ||
| 220 | +++ b/crypto/objects/obj_dat.h | ||
| 221 | @@ -62,9 +62,9 @@ | ||
| 222 | * [including the GNU Public Licence.] | ||
| 223 | */ | ||
| 224 | |||
| 225 | -#define NUM_NID 921 | ||
| 226 | -#define NUM_SN 914 | ||
| 227 | -#define NUM_LN 914 | ||
| 228 | +#define NUM_NID 924 | ||
| 229 | +#define NUM_SN 917 | ||
| 230 | +#define NUM_LN 917 | ||
| 231 | #define NUM_OBJ 857 | ||
| 232 | |||
| 233 | static const unsigned char lvalues[5974]={ | ||
| 234 | @@ -2401,6 +2401,12 @@ static const ASN1_OBJECT nid_objs[NUM_NID]={ | ||
| 235 | {"RSAES-OAEP","rsaesOaep",NID_rsaesOaep,9,&(lvalues[5964]),0}, | ||
| 236 | {"DES-EDE3-CBC-HMAC-SHA1","des-ede3-cbc-hmac-sha1", | ||
| 237 | NID_des_ede3_cbc_hmac_sha1,0,NULL,0}, | ||
| 238 | +{"TLS11-DES-EDE3-CBC-HMAC-SHA1","tls11-des-ede3-cbc-hmac-sha1", | ||
| 239 | + NID_tls11_des_ede3_cbc_hmac_sha1,0,NULL,0}, | ||
| 240 | +{"TLS11-AES-128-CBC-HMAC-SHA1","tls11-aes-128-cbc-hmac-sha1", | ||
| 241 | + NID_tls11_aes_128_cbc_hmac_sha1,0,NULL,0}, | ||
| 242 | +{"TLS11-AES-256-CBC-HMAC-SHA1","tls11-aes-256-cbc-hmac-sha1", | ||
| 243 | + NID_tls11_aes_256_cbc_hmac_sha1,0,NULL,0}, | ||
| 244 | }; | ||
| 245 | |||
| 246 | static const unsigned int sn_objs[NUM_SN]={ | ||
| 247 | @@ -2586,6 +2592,9 @@ static const unsigned int sn_objs[NUM_SN]={ | ||
| 248 | 100, /* "SN" */ | ||
| 249 | 16, /* "ST" */ | ||
| 250 | 143, /* "SXNetID" */ | ||
| 251 | +922, /* "TLS11-AES-128-CBC-HMAC-SHA1" */ | ||
| 252 | +923, /* "TLS11-AES-256-CBC-HMAC-SHA1" */ | ||
| 253 | +921, /* "TLS11-DES-EDE3-CBC-HMAC-SHA1" */ | ||
| 254 | 458, /* "UID" */ | ||
| 255 | 0, /* "UNDEF" */ | ||
| 256 | 11, /* "X500" */ | ||
| 257 | @@ -4205,6 +4214,9 @@ static const unsigned int ln_objs[NUM_LN]={ | ||
| 258 | 459, /* "textEncodedORAddress" */ | ||
| 259 | 293, /* "textNotice" */ | ||
| 260 | 106, /* "title" */ | ||
| 261 | +922, /* "tls11-aes-128-cbc-hmac-sha1" */ | ||
| 262 | +923, /* "tls11-aes-256-cbc-hmac-sha1" */ | ||
| 263 | +921, /* "tls11-des-ede3-cbc-hmac-sha1" */ | ||
| 264 | 682, /* "tpBasis" */ | ||
| 265 | 436, /* "ucl" */ | ||
| 266 | 0, /* "undefined" */ | ||
| 267 | diff --git a/crypto/objects/obj_mac.h b/crypto/objects/obj_mac.h | ||
| 268 | index 8751902..f181890 100644 | ||
| 269 | --- a/crypto/objects/obj_mac.h | ||
| 270 | +++ b/crypto/objects/obj_mac.h | ||
| 271 | @@ -4034,3 +4034,15 @@ | ||
| 272 | #define LN_des_ede3_cbc_hmac_sha1 "des-ede3-cbc-hmac-sha1" | ||
| 273 | #define NID_des_ede3_cbc_hmac_sha1 920 | ||
| 274 | |||
| 275 | +#define SN_tls11_des_ede3_cbc_hmac_sha1 "TLS11-DES-EDE3-CBC-HMAC-SHA1" | ||
| 276 | +#define LN_tls11_des_ede3_cbc_hmac_sha1 "tls11-des-ede3-cbc-hmac-sha1" | ||
| 277 | +#define NID_tls11_des_ede3_cbc_hmac_sha1 921 | ||
| 278 | + | ||
| 279 | +#define SN_tls11_aes_128_cbc_hmac_sha1 "TLS11-AES-128-CBC-HMAC-SHA1" | ||
| 280 | +#define LN_tls11_aes_128_cbc_hmac_sha1 "tls11-aes-128-cbc-hmac-sha1" | ||
| 281 | +#define NID_tls11_aes_128_cbc_hmac_sha1 922 | ||
| 282 | + | ||
| 283 | +#define SN_tls11_aes_256_cbc_hmac_sha1 "TLS11-AES-256-CBC-HMAC-SHA1" | ||
| 284 | +#define LN_tls11_aes_256_cbc_hmac_sha1 "tls11-aes-256-cbc-hmac-sha1" | ||
| 285 | +#define NID_tls11_aes_256_cbc_hmac_sha1 923 | ||
| 286 | + | ||
| 287 | diff --git a/crypto/objects/obj_mac.num b/crypto/objects/obj_mac.num | ||
| 288 | index 9d44bb5..a02b58c 100644 | ||
| 289 | --- a/crypto/objects/obj_mac.num | ||
| 290 | +++ b/crypto/objects/obj_mac.num | ||
| 291 | @@ -918,3 +918,6 @@ aes_192_cbc_hmac_sha1 917 | ||
| 292 | aes_256_cbc_hmac_sha1 918 | ||
| 293 | rsaesOaep 919 | ||
| 294 | des_ede3_cbc_hmac_sha1 920 | ||
| 295 | +tls11_des_ede3_cbc_hmac_sha1 921 | ||
| 296 | +tls11_aes_128_cbc_hmac_sha1 922 | ||
| 297 | +tls11_aes_256_cbc_hmac_sha1 923 | ||
| 298 | diff --git a/crypto/objects/objects.txt b/crypto/objects/objects.txt | ||
| 299 | index 90d2fc5..1973658 100644 | ||
| 300 | --- a/crypto/objects/objects.txt | ||
| 301 | +++ b/crypto/objects/objects.txt | ||
| 302 | @@ -1291,3 +1291,6 @@ kisa 1 6 : SEED-OFB : seed-ofb | ||
| 303 | : AES-192-CBC-HMAC-SHA1 : aes-192-cbc-hmac-sha1 | ||
| 304 | : AES-256-CBC-HMAC-SHA1 : aes-256-cbc-hmac-sha1 | ||
| 305 | : DES-EDE3-CBC-HMAC-SHA1 : des-ede3-cbc-hmac-sha1 | ||
| 306 | + : TLS11-DES-EDE3-CBC-HMAC-SHA1 : tls11-des-ede3-cbc-hmac-sha1 | ||
| 307 | + : TLS11-AES-128-CBC-HMAC-SHA1 : tls11-aes-128-cbc-hmac-sha1 | ||
| 308 | + : TLS11-AES-256-CBC-HMAC-SHA1 : tls11-aes-256-cbc-hmac-sha1 | ||
| 309 | diff --git a/ssl/ssl_ciph.c b/ssl/ssl_ciph.c | ||
| 310 | index 310fe76..0408986 100644 | ||
| 311 | --- a/ssl/ssl_ciph.c | ||
| 312 | +++ b/ssl/ssl_ciph.c | ||
| 313 | @@ -631,17 +631,35 @@ int ssl_cipher_get_evp(const SSL_SESSION *s, const EVP_CIPHER **enc, | ||
| 314 | c->algorithm_mac == SSL_MD5 && | ||
| 315 | (evp=EVP_get_cipherbyname("RC4-HMAC-MD5"))) | ||
| 316 | *enc = evp, *md = NULL; | ||
| 317 | - else if (c->algorithm_enc == SSL_AES128 && | ||
| 318 | + else if (s->ssl_version == TLS1_VERSION && | ||
| 319 | + c->algorithm_enc == SSL_3DES && | ||
| 320 | + c->algorithm_mac == SSL_SHA1 && | ||
| 321 | + (evp=EVP_get_cipherbyname("DES-EDE3-CBC-HMAC-SHA1"))) | ||
| 322 | + *enc = evp, *md = NULL; | ||
| 323 | + else if (s->ssl_version == TLS1_VERSION && | ||
| 324 | + c->algorithm_enc == SSL_AES128 && | ||
| 325 | c->algorithm_mac == SSL_SHA1 && | ||
| 326 | (evp=EVP_get_cipherbyname("AES-128-CBC-HMAC-SHA1"))) | ||
| 327 | *enc = evp, *md = NULL; | ||
| 328 | - else if (c->algorithm_enc == SSL_AES256 && | ||
| 329 | + else if (s->ssl_version == TLS1_VERSION && | ||
| 330 | + c->algorithm_enc == SSL_AES256 && | ||
| 331 | c->algorithm_mac == SSL_SHA1 && | ||
| 332 | (evp=EVP_get_cipherbyname("AES-256-CBC-HMAC-SHA1"))) | ||
| 333 | *enc = evp, *md = NULL; | ||
| 334 | - else if (c->algorithm_enc == SSL_3DES && | ||
| 335 | + else if (s->ssl_version == TLS1_1_VERSION && | ||
| 336 | + c->algorithm_enc == SSL_3DES && | ||
| 337 | + c->algorithm_mac == SSL_SHA1 && | ||
| 338 | + (evp=EVP_get_cipherbyname("TLS11-DES-EDE3-CBC-HMAC-SHA1"))) | ||
| 339 | + *enc = evp, *md = NULL; | ||
| 340 | + else if (s->ssl_version == TLS1_1_VERSION && | ||
| 341 | + c->algorithm_enc == SSL_AES128 && | ||
| 342 | + c->algorithm_mac == SSL_SHA1 && | ||
| 343 | + (evp=EVP_get_cipherbyname("TLS11-AES-128-CBC-HMAC-SHA1"))) | ||
| 344 | + *enc = evp, *md = NULL; | ||
| 345 | + else if (s->ssl_version == TLS1_1_VERSION && | ||
| 346 | + c->algorithm_enc == SSL_AES256 && | ||
| 347 | c->algorithm_mac == SSL_SHA1 && | ||
| 348 | - (evp = EVP_get_cipherbyname("DES-EDE3-CBC-HMAC-SHA1"))) | ||
| 349 | + (evp=EVP_get_cipherbyname("TLS11-AES-256-CBC-HMAC-SHA1"))) | ||
| 350 | *enc = evp, *md = NULL; | ||
| 351 | return(1); | ||
| 352 | } | ||
| 353 | -- | ||
| 354 | 2.3.5 | ||
| 355 | |||
diff --git a/recipes-connectivity/openssl/openssl-qoriq/qoriq/0020-cryptodev-clean-up-code-layout.patch b/recipes-connectivity/openssl/openssl-qoriq/qoriq/0020-cryptodev-clean-up-code-layout.patch new file mode 100644 index 000000000..c600bdab4 --- /dev/null +++ b/recipes-connectivity/openssl/openssl-qoriq/qoriq/0020-cryptodev-clean-up-code-layout.patch | |||
| @@ -0,0 +1,73 @@ | |||
| 1 | From 453c617b10fb2c4e748b5799ab4b00c184470c60 Mon Sep 17 00:00:00 2001 | ||
| 2 | From: Cristian Stoica <cristian.stoica@freescale.com> | ||
| 3 | Date: Wed, 18 Feb 2015 10:39:46 +0200 | ||
| 4 | Subject: [PATCH 20/48] cryptodev: clean-up code layout | ||
| 5 | |||
| 6 | This is just a refactoring that uses else branch to check for malloc failures | ||
| 7 | |||
| 8 | Signed-off-by: Cristian Stoica <cristian.stoica@freescale.com> | ||
| 9 | --- | ||
| 10 | crypto/engine/eng_cryptodev.c | 45 ++++++++++++++++++++----------------------- | ||
| 11 | 1 file changed, 21 insertions(+), 24 deletions(-) | ||
| 12 | |||
| 13 | diff --git a/crypto/engine/eng_cryptodev.c b/crypto/engine/eng_cryptodev.c | ||
| 14 | index bbc903b..14dcddf 100644 | ||
| 15 | --- a/crypto/engine/eng_cryptodev.c | ||
| 16 | +++ b/crypto/engine/eng_cryptodev.c | ||
| 17 | @@ -1865,32 +1865,29 @@ cryptodev_asym_async(struct crypt_kop *kop, int rlen, BIGNUM *r, int slen, | ||
| 18 | fd = *(int *)cookie->eng_handle; | ||
| 19 | |||
| 20 | eng_cookie = malloc(sizeof(struct cryptodev_cookie_s)); | ||
| 21 | - | ||
| 22 | - if (eng_cookie) { | ||
| 23 | - memset(eng_cookie, 0, sizeof(struct cryptodev_cookie_s)); | ||
| 24 | - if (r) { | ||
| 25 | - kop->crk_param[kop->crk_iparams].crp_p = | ||
| 26 | - calloc(rlen, sizeof(char)); | ||
| 27 | - if (!kop->crk_param[kop->crk_iparams].crp_p) | ||
| 28 | - return -ENOMEM; | ||
| 29 | - kop->crk_param[kop->crk_iparams].crp_nbits = rlen * 8; | ||
| 30 | - kop->crk_oparams++; | ||
| 31 | - eng_cookie->r = r; | ||
| 32 | - eng_cookie->r_param = kop->crk_param[kop->crk_iparams]; | ||
| 33 | - } | ||
| 34 | - if (s) { | ||
| 35 | - kop->crk_param[kop->crk_iparams + 1].crp_p = | ||
| 36 | - calloc(slen, sizeof(char)); | ||
| 37 | - if (!kop->crk_param[kop->crk_iparams + 1].crp_p) | ||
| 38 | - return -ENOMEM; | ||
| 39 | - kop->crk_param[kop->crk_iparams + 1].crp_nbits = slen * 8; | ||
| 40 | - kop->crk_oparams++; | ||
| 41 | - eng_cookie->s = s; | ||
| 42 | - eng_cookie->s_param = kop->crk_param[kop->crk_iparams + 1]; | ||
| 43 | - } | ||
| 44 | - } else | ||
| 45 | + if (!eng_cookie) | ||
| 46 | return -ENOMEM; | ||
| 47 | |||
| 48 | + memset(eng_cookie, 0, sizeof(struct cryptodev_cookie_s)); | ||
| 49 | + if (r) { | ||
| 50 | + kop->crk_param[kop->crk_iparams].crp_p = calloc(rlen, sizeof(char)); | ||
| 51 | + if (!kop->crk_param[kop->crk_iparams].crp_p) | ||
| 52 | + return -ENOMEM; | ||
| 53 | + kop->crk_param[kop->crk_iparams].crp_nbits = rlen * 8; | ||
| 54 | + kop->crk_oparams++; | ||
| 55 | + eng_cookie->r = r; | ||
| 56 | + eng_cookie->r_param = kop->crk_param[kop->crk_iparams]; | ||
| 57 | + } | ||
| 58 | + if (s) { | ||
| 59 | + kop->crk_param[kop->crk_iparams + 1].crp_p = | ||
| 60 | + calloc(slen, sizeof(char)); | ||
| 61 | + if (!kop->crk_param[kop->crk_iparams + 1].crp_p) | ||
| 62 | + return -ENOMEM; | ||
| 63 | + kop->crk_param[kop->crk_iparams + 1].crp_nbits = slen * 8; | ||
| 64 | + kop->crk_oparams++; | ||
| 65 | + eng_cookie->s = s; | ||
| 66 | + eng_cookie->s_param = kop->crk_param[kop->crk_iparams + 1]; | ||
| 67 | + } | ||
| 68 | eng_cookie->kop = kop; | ||
| 69 | cookie->eng_cookie = eng_cookie; | ||
| 70 | return ioctl(fd, CIOCASYMASYNCRYPT, kop); | ||
| 71 | -- | ||
| 72 | 2.7.0 | ||
| 73 | |||
diff --git a/recipes-connectivity/openssl/openssl-qoriq/qoriq/0020-eng_cryptodev-add-support-for-TLSv1.2-record-offload.patch b/recipes-connectivity/openssl/openssl-qoriq/qoriq/0020-eng_cryptodev-add-support-for-TLSv1.2-record-offload.patch deleted file mode 100644 index 7370c4969..000000000 --- a/recipes-connectivity/openssl/openssl-qoriq/qoriq/0020-eng_cryptodev-add-support-for-TLSv1.2-record-offload.patch +++ /dev/null | |||
| @@ -1,359 +0,0 @@ | |||
| 1 | From a58703e6601fcfcfe69fdb3e7152ed76b40d67e9 Mon Sep 17 00:00:00 2001 | ||
| 2 | From: Tudor Ambarus <tudor.ambarus@freescale.com> | ||
| 3 | Date: Tue, 31 Mar 2015 16:32:35 +0300 | ||
| 4 | Subject: [PATCH 20/26] eng_cryptodev: add support for TLSv1.2 record offload | ||
| 5 | |||
| 6 | Supported cipher suites: | ||
| 7 | - 3des-ede-cbc-sha | ||
| 8 | - aes-128-cbc-hmac-sha | ||
| 9 | - aes-256-cbc-hmac-sha | ||
| 10 | - aes-128-cbc-hmac-sha256 | ||
| 11 | - aes-256-cbc-hmac-sha256 | ||
| 12 | |||
| 13 | Requires TLS patches on cryptodev and TLS algorithm support in Linux | ||
| 14 | kernel driver. | ||
| 15 | |||
| 16 | Signed-off-by: Tudor Ambarus <tudor.ambarus@freescale.com> | ||
| 17 | Change-Id: I0ac6953dd62e2655a59d8f3eaefd012b7ecebf55 | ||
| 18 | Reviewed-on: http://git.am.freescale.net:8181/34003 | ||
| 19 | Reviewed-by: Cristian Stoica <cristian.stoica@freescale.com> | ||
| 20 | Tested-by: Cristian Stoica <cristian.stoica@freescale.com> | ||
| 21 | --- | ||
| 22 | crypto/engine/eng_cryptodev.c | 123 ++++++++++++++++++++++++++++++++++++++++++ | ||
| 23 | crypto/objects/obj_dat.h | 26 +++++++-- | ||
| 24 | crypto/objects/obj_mac.h | 20 +++++++ | ||
| 25 | crypto/objects/obj_mac.num | 5 ++ | ||
| 26 | crypto/objects/objects.txt | 5 ++ | ||
| 27 | ssl/ssl_ciph.c | 25 +++++++++ | ||
| 28 | 6 files changed, 201 insertions(+), 3 deletions(-) | ||
| 29 | |||
| 30 | diff --git a/crypto/engine/eng_cryptodev.c b/crypto/engine/eng_cryptodev.c | ||
| 31 | index f71ab27..fa5fe1b 100644 | ||
| 32 | --- a/crypto/engine/eng_cryptodev.c | ||
| 33 | +++ b/crypto/engine/eng_cryptodev.c | ||
| 34 | @@ -140,6 +140,11 @@ const EVP_CIPHER cryptodev_aes_256_cbc_hmac_sha1; | ||
| 35 | const EVP_CIPHER cryptodev_tls11_3des_cbc_hmac_sha1; | ||
| 36 | const EVP_CIPHER cryptodev_tls11_aes_128_cbc_hmac_sha1; | ||
| 37 | const EVP_CIPHER cryptodev_tls11_aes_256_cbc_hmac_sha1; | ||
| 38 | +const EVP_CIPHER cryptodev_tls12_3des_cbc_hmac_sha1; | ||
| 39 | +const EVP_CIPHER cryptodev_tls12_aes_128_cbc_hmac_sha1; | ||
| 40 | +const EVP_CIPHER cryptodev_tls12_aes_256_cbc_hmac_sha1; | ||
| 41 | +const EVP_CIPHER cryptodev_tls12_aes_128_cbc_hmac_sha256; | ||
| 42 | +const EVP_CIPHER cryptodev_tls12_aes_256_cbc_hmac_sha256; | ||
| 43 | |||
| 44 | inline int spcf_bn2bin(BIGNUM *bn, unsigned char **bin, int *bin_len) | ||
| 45 | { | ||
| 46 | @@ -263,6 +268,11 @@ static struct { | ||
| 47 | { CRYPTO_TLS11_3DES_CBC_HMAC_SHA1, NID_tls11_des_ede3_cbc_hmac_sha1, 8, 24, 20}, | ||
| 48 | { CRYPTO_TLS11_AES_CBC_HMAC_SHA1, NID_tls11_aes_128_cbc_hmac_sha1, 16, 16, 20}, | ||
| 49 | { CRYPTO_TLS11_AES_CBC_HMAC_SHA1, NID_tls11_aes_256_cbc_hmac_sha1, 16, 32, 20}, | ||
| 50 | + { CRYPTO_TLS12_3DES_CBC_HMAC_SHA1, NID_tls12_des_ede3_cbc_hmac_sha1, 8, 24, 20}, | ||
| 51 | + { CRYPTO_TLS12_AES_CBC_HMAC_SHA1, NID_tls12_aes_128_cbc_hmac_sha1, 16, 16, 20}, | ||
| 52 | + { CRYPTO_TLS12_AES_CBC_HMAC_SHA1, NID_tls12_aes_256_cbc_hmac_sha1, 16, 32, 20}, | ||
| 53 | + { CRYPTO_TLS12_AES_CBC_HMAC_SHA256, NID_tls12_aes_128_cbc_hmac_sha256, 16, 16, 32}, | ||
| 54 | + { CRYPTO_TLS12_AES_CBC_HMAC_SHA256, NID_tls12_aes_256_cbc_hmac_sha256, 16, 32, 32}, | ||
| 55 | { CRYPTO_AES_GCM, NID_aes_128_gcm, 16, 16, 0}, | ||
| 56 | { 0, NID_undef, 0, 0, 0}, | ||
| 57 | }; | ||
| 58 | @@ -487,6 +497,21 @@ cryptodev_usable_ciphers(const int **nids) | ||
| 59 | case NID_tls11_aes_256_cbc_hmac_sha1: | ||
| 60 | EVP_add_cipher(&cryptodev_tls11_aes_256_cbc_hmac_sha1); | ||
| 61 | break; | ||
| 62 | + case NID_tls12_des_ede3_cbc_hmac_sha1: | ||
| 63 | + EVP_add_cipher(&cryptodev_tls12_3des_cbc_hmac_sha1); | ||
| 64 | + break; | ||
| 65 | + case NID_tls12_aes_128_cbc_hmac_sha1: | ||
| 66 | + EVP_add_cipher(&cryptodev_tls12_aes_128_cbc_hmac_sha1); | ||
| 67 | + break; | ||
| 68 | + case NID_tls12_aes_256_cbc_hmac_sha1: | ||
| 69 | + EVP_add_cipher(&cryptodev_tls12_aes_256_cbc_hmac_sha1); | ||
| 70 | + break; | ||
| 71 | + case NID_tls12_aes_128_cbc_hmac_sha256: | ||
| 72 | + EVP_add_cipher(&cryptodev_tls12_aes_128_cbc_hmac_sha256); | ||
| 73 | + break; | ||
| 74 | + case NID_tls12_aes_256_cbc_hmac_sha256: | ||
| 75 | + EVP_add_cipher(&cryptodev_tls12_aes_256_cbc_hmac_sha256); | ||
| 76 | + break; | ||
| 77 | } | ||
| 78 | } | ||
| 79 | return count; | ||
| 80 | @@ -596,6 +621,11 @@ static int cryptodev_aead_cipher(EVP_CIPHER_CTX *ctx, unsigned char *out, | ||
| 81 | case NID_tls11_des_ede3_cbc_hmac_sha1: | ||
| 82 | case NID_tls11_aes_128_cbc_hmac_sha1: | ||
| 83 | case NID_tls11_aes_256_cbc_hmac_sha1: | ||
| 84 | + case NID_tls12_des_ede3_cbc_hmac_sha1: | ||
| 85 | + case NID_tls12_aes_128_cbc_hmac_sha1: | ||
| 86 | + case NID_tls12_aes_256_cbc_hmac_sha1: | ||
| 87 | + case NID_tls12_aes_128_cbc_hmac_sha256: | ||
| 88 | + case NID_tls12_aes_256_cbc_hmac_sha256: | ||
| 89 | cryp.flags = COP_FLAG_AEAD_TLS_TYPE; | ||
| 90 | } | ||
| 91 | cryp.ses = sess->ses; | ||
| 92 | @@ -795,9 +825,17 @@ static int cryptodev_cbc_hmac_sha1_ctrl(EVP_CIPHER_CTX *ctx, int type, int arg, | ||
| 93 | case NID_tls11_des_ede3_cbc_hmac_sha1: | ||
| 94 | case NID_tls11_aes_128_cbc_hmac_sha1: | ||
| 95 | case NID_tls11_aes_256_cbc_hmac_sha1: | ||
| 96 | + case NID_tls12_des_ede3_cbc_hmac_sha1: | ||
| 97 | + case NID_tls12_aes_128_cbc_hmac_sha1: | ||
| 98 | + case NID_tls12_aes_256_cbc_hmac_sha1: | ||
| 99 | maclen = SHA_DIGEST_LENGTH; | ||
| 100 | aad_needs_fix = true; | ||
| 101 | break; | ||
| 102 | + case NID_tls12_aes_128_cbc_hmac_sha256: | ||
| 103 | + case NID_tls12_aes_256_cbc_hmac_sha256: | ||
| 104 | + maclen = SHA256_DIGEST_LENGTH; | ||
| 105 | + aad_needs_fix = true; | ||
| 106 | + break; | ||
| 107 | } | ||
| 108 | |||
| 109 | /* Correct length for AAD Length field */ | ||
| 110 | @@ -1207,6 +1245,76 @@ const EVP_CIPHER cryptodev_tls11_aes_256_cbc_hmac_sha1 = { | ||
| 111 | NULL | ||
| 112 | }; | ||
| 113 | |||
| 114 | +const EVP_CIPHER cryptodev_tls12_3des_cbc_hmac_sha1 = { | ||
| 115 | + NID_tls12_des_ede3_cbc_hmac_sha1, | ||
| 116 | + 8, 24, 8, | ||
| 117 | + EVP_CIPH_CBC_MODE | EVP_CIPH_FLAG_AEAD_CIPHER, | ||
| 118 | + cryptodev_init_aead_key, | ||
| 119 | + cryptodev_aead_cipher, | ||
| 120 | + cryptodev_cleanup, | ||
| 121 | + sizeof(struct dev_crypto_state), | ||
| 122 | + EVP_CIPHER_set_asn1_iv, | ||
| 123 | + EVP_CIPHER_get_asn1_iv, | ||
| 124 | + cryptodev_cbc_hmac_sha1_ctrl, | ||
| 125 | + NULL | ||
| 126 | +}; | ||
| 127 | + | ||
| 128 | +const EVP_CIPHER cryptodev_tls12_aes_128_cbc_hmac_sha1 = { | ||
| 129 | + NID_tls12_aes_128_cbc_hmac_sha1, | ||
| 130 | + 16, 16, 16, | ||
| 131 | + EVP_CIPH_CBC_MODE | EVP_CIPH_FLAG_AEAD_CIPHER, | ||
| 132 | + cryptodev_init_aead_key, | ||
| 133 | + cryptodev_aead_cipher, | ||
| 134 | + cryptodev_cleanup, | ||
| 135 | + sizeof(struct dev_crypto_state), | ||
| 136 | + EVP_CIPHER_set_asn1_iv, | ||
| 137 | + EVP_CIPHER_get_asn1_iv, | ||
| 138 | + cryptodev_cbc_hmac_sha1_ctrl, | ||
| 139 | + NULL | ||
| 140 | +}; | ||
| 141 | + | ||
| 142 | +const EVP_CIPHER cryptodev_tls12_aes_256_cbc_hmac_sha1 = { | ||
| 143 | + NID_tls12_aes_256_cbc_hmac_sha1, | ||
| 144 | + 16, 32, 16, | ||
| 145 | + EVP_CIPH_CBC_MODE | EVP_CIPH_FLAG_AEAD_CIPHER, | ||
| 146 | + cryptodev_init_aead_key, | ||
| 147 | + cryptodev_aead_cipher, | ||
| 148 | + cryptodev_cleanup, | ||
| 149 | + sizeof(struct dev_crypto_state), | ||
| 150 | + EVP_CIPHER_set_asn1_iv, | ||
| 151 | + EVP_CIPHER_get_asn1_iv, | ||
| 152 | + cryptodev_cbc_hmac_sha1_ctrl, | ||
| 153 | + NULL | ||
| 154 | +}; | ||
| 155 | + | ||
| 156 | +const EVP_CIPHER cryptodev_tls12_aes_128_cbc_hmac_sha256 = { | ||
| 157 | + NID_tls12_aes_128_cbc_hmac_sha256, | ||
| 158 | + 16, 16, 16, | ||
| 159 | + EVP_CIPH_CBC_MODE | EVP_CIPH_FLAG_AEAD_CIPHER, | ||
| 160 | + cryptodev_init_aead_key, | ||
| 161 | + cryptodev_aead_cipher, | ||
| 162 | + cryptodev_cleanup, | ||
| 163 | + sizeof(struct dev_crypto_state), | ||
| 164 | + EVP_CIPHER_set_asn1_iv, | ||
| 165 | + EVP_CIPHER_get_asn1_iv, | ||
| 166 | + cryptodev_cbc_hmac_sha1_ctrl, | ||
| 167 | + NULL | ||
| 168 | +}; | ||
| 169 | + | ||
| 170 | +const EVP_CIPHER cryptodev_tls12_aes_256_cbc_hmac_sha256 = { | ||
| 171 | + NID_tls12_aes_256_cbc_hmac_sha256, | ||
| 172 | + 16, 32, 16, | ||
| 173 | + EVP_CIPH_CBC_MODE | EVP_CIPH_FLAG_AEAD_CIPHER, | ||
| 174 | + cryptodev_init_aead_key, | ||
| 175 | + cryptodev_aead_cipher, | ||
| 176 | + cryptodev_cleanup, | ||
| 177 | + sizeof(struct dev_crypto_state), | ||
| 178 | + EVP_CIPHER_set_asn1_iv, | ||
| 179 | + EVP_CIPHER_get_asn1_iv, | ||
| 180 | + cryptodev_cbc_hmac_sha1_ctrl, | ||
| 181 | + NULL | ||
| 182 | +}; | ||
| 183 | + | ||
| 184 | const EVP_CIPHER cryptodev_aes_128_gcm = { | ||
| 185 | NID_aes_128_gcm, | ||
| 186 | 1, 16, 12, | ||
| 187 | @@ -1281,6 +1389,21 @@ cryptodev_engine_ciphers(ENGINE *e, const EVP_CIPHER **cipher, | ||
| 188 | case NID_tls11_aes_256_cbc_hmac_sha1: | ||
| 189 | *cipher = &cryptodev_tls11_aes_256_cbc_hmac_sha1; | ||
| 190 | break; | ||
| 191 | + case NID_tls12_des_ede3_cbc_hmac_sha1: | ||
| 192 | + *cipher = &cryptodev_tls12_3des_cbc_hmac_sha1; | ||
| 193 | + break; | ||
| 194 | + case NID_tls12_aes_128_cbc_hmac_sha1: | ||
| 195 | + *cipher = &cryptodev_tls12_aes_128_cbc_hmac_sha1; | ||
| 196 | + break; | ||
| 197 | + case NID_tls12_aes_256_cbc_hmac_sha1: | ||
| 198 | + *cipher = &cryptodev_tls12_aes_256_cbc_hmac_sha1; | ||
| 199 | + break; | ||
| 200 | + case NID_tls12_aes_128_cbc_hmac_sha256: | ||
| 201 | + *cipher = &cryptodev_tls12_aes_128_cbc_hmac_sha256; | ||
| 202 | + break; | ||
| 203 | + case NID_tls12_aes_256_cbc_hmac_sha256: | ||
| 204 | + *cipher = &cryptodev_tls12_aes_256_cbc_hmac_sha256; | ||
| 205 | + break; | ||
| 206 | default: | ||
| 207 | *cipher = NULL; | ||
| 208 | break; | ||
| 209 | diff --git a/crypto/objects/obj_dat.h b/crypto/objects/obj_dat.h | ||
| 210 | index dc89b0a..dfe19da 100644 | ||
| 211 | --- a/crypto/objects/obj_dat.h | ||
| 212 | +++ b/crypto/objects/obj_dat.h | ||
| 213 | @@ -62,9 +62,9 @@ | ||
| 214 | * [including the GNU Public Licence.] | ||
| 215 | */ | ||
| 216 | |||
| 217 | -#define NUM_NID 924 | ||
| 218 | -#define NUM_SN 917 | ||
| 219 | -#define NUM_LN 917 | ||
| 220 | +#define NUM_NID 929 | ||
| 221 | +#define NUM_SN 922 | ||
| 222 | +#define NUM_LN 922 | ||
| 223 | #define NUM_OBJ 857 | ||
| 224 | |||
| 225 | static const unsigned char lvalues[5974]={ | ||
| 226 | @@ -2407,6 +2407,16 @@ static const ASN1_OBJECT nid_objs[NUM_NID]={ | ||
| 227 | NID_tls11_aes_128_cbc_hmac_sha1,0,NULL,0}, | ||
| 228 | {"TLS11-AES-256-CBC-HMAC-SHA1","tls11-aes-256-cbc-hmac-sha1", | ||
| 229 | NID_tls11_aes_256_cbc_hmac_sha1,0,NULL,0}, | ||
| 230 | +{"TLS12-DES-EDE3-CBC-HMAC-SHA1","tls12-des-ede3-cbc-hmac-sha1", | ||
| 231 | + NID_tls12_des_ede3_cbc_hmac_sha1,0,NULL,0}, | ||
| 232 | +{"TLS12-AES-128-CBC-HMAC-SHA1","tls12-aes-128-cbc-hmac-sha1", | ||
| 233 | + NID_tls12_aes_128_cbc_hmac_sha1,0,NULL,0}, | ||
| 234 | +{"TLS12-AES-256-CBC-HMAC-SHA1","tls12-aes-256-cbc-hmac-sha1", | ||
| 235 | + NID_tls12_aes_256_cbc_hmac_sha1,0,NULL,0}, | ||
| 236 | +{"TLS12-AES-128-CBC-HMAC-SHA256","tls12-aes-128-cbc-hmac-sha256", | ||
| 237 | + NID_tls12_aes_128_cbc_hmac_sha256,0,NULL,0}, | ||
| 238 | +{"TLS12-AES-256-CBC-HMAC-SHA256","tls12-aes-256-cbc-hmac-sha256", | ||
| 239 | + NID_tls12_aes_256_cbc_hmac_sha256,0,NULL,0}, | ||
| 240 | }; | ||
| 241 | |||
| 242 | static const unsigned int sn_objs[NUM_SN]={ | ||
| 243 | @@ -2595,6 +2605,11 @@ static const unsigned int sn_objs[NUM_SN]={ | ||
| 244 | 922, /* "TLS11-AES-128-CBC-HMAC-SHA1" */ | ||
| 245 | 923, /* "TLS11-AES-256-CBC-HMAC-SHA1" */ | ||
| 246 | 921, /* "TLS11-DES-EDE3-CBC-HMAC-SHA1" */ | ||
| 247 | +925, /* "TLS12-AES-128-CBC-HMAC-SHA1" */ | ||
| 248 | +927, /* "TLS12-AES-128-CBC-HMAC-SHA256" */ | ||
| 249 | +926, /* "TLS12-AES-256-CBC-HMAC-SHA1" */ | ||
| 250 | +928, /* "TLS12-AES-256-CBC-HMAC-SHA256" */ | ||
| 251 | +924, /* "TLS12-DES-EDE3-CBC-HMAC-SHA1" */ | ||
| 252 | 458, /* "UID" */ | ||
| 253 | 0, /* "UNDEF" */ | ||
| 254 | 11, /* "X500" */ | ||
| 255 | @@ -4217,6 +4232,11 @@ static const unsigned int ln_objs[NUM_LN]={ | ||
| 256 | 922, /* "tls11-aes-128-cbc-hmac-sha1" */ | ||
| 257 | 923, /* "tls11-aes-256-cbc-hmac-sha1" */ | ||
| 258 | 921, /* "tls11-des-ede3-cbc-hmac-sha1" */ | ||
| 259 | +925, /* "tls12-aes-128-cbc-hmac-sha1" */ | ||
| 260 | +927, /* "tls12-aes-128-cbc-hmac-sha256" */ | ||
| 261 | +926, /* "tls12-aes-256-cbc-hmac-sha1" */ | ||
| 262 | +928, /* "tls12-aes-256-cbc-hmac-sha256" */ | ||
| 263 | +924, /* "tls12-des-ede3-cbc-hmac-sha1" */ | ||
| 264 | 682, /* "tpBasis" */ | ||
| 265 | 436, /* "ucl" */ | ||
| 266 | 0, /* "undefined" */ | ||
| 267 | diff --git a/crypto/objects/obj_mac.h b/crypto/objects/obj_mac.h | ||
| 268 | index f181890..5af125e 100644 | ||
| 269 | --- a/crypto/objects/obj_mac.h | ||
| 270 | +++ b/crypto/objects/obj_mac.h | ||
| 271 | @@ -4046,3 +4046,23 @@ | ||
| 272 | #define LN_tls11_aes_256_cbc_hmac_sha1 "tls11-aes-256-cbc-hmac-sha1" | ||
| 273 | #define NID_tls11_aes_256_cbc_hmac_sha1 923 | ||
| 274 | |||
| 275 | +#define SN_tls12_des_ede3_cbc_hmac_sha1 "TLS12-DES-EDE3-CBC-HMAC-SHA1" | ||
| 276 | +#define LN_tls12_des_ede3_cbc_hmac_sha1 "tls12-des-ede3-cbc-hmac-sha1" | ||
| 277 | +#define NID_tls12_des_ede3_cbc_hmac_sha1 924 | ||
| 278 | + | ||
| 279 | +#define SN_tls12_aes_128_cbc_hmac_sha1 "TLS12-AES-128-CBC-HMAC-SHA1" | ||
| 280 | +#define LN_tls12_aes_128_cbc_hmac_sha1 "tls12-aes-128-cbc-hmac-sha1" | ||
| 281 | +#define NID_tls12_aes_128_cbc_hmac_sha1 925 | ||
| 282 | + | ||
| 283 | +#define SN_tls12_aes_256_cbc_hmac_sha1 "TLS12-AES-256-CBC-HMAC-SHA1" | ||
| 284 | +#define LN_tls12_aes_256_cbc_hmac_sha1 "tls12-aes-256-cbc-hmac-sha1" | ||
| 285 | +#define NID_tls12_aes_256_cbc_hmac_sha1 926 | ||
| 286 | + | ||
| 287 | +#define SN_tls12_aes_128_cbc_hmac_sha256 "TLS12-AES-128-CBC-HMAC-SHA256" | ||
| 288 | +#define LN_tls12_aes_128_cbc_hmac_sha256 "tls12-aes-128-cbc-hmac-sha256" | ||
| 289 | +#define NID_tls12_aes_128_cbc_hmac_sha256 927 | ||
| 290 | + | ||
| 291 | +#define SN_tls12_aes_256_cbc_hmac_sha256 "TLS12-AES-256-CBC-HMAC-SHA256" | ||
| 292 | +#define LN_tls12_aes_256_cbc_hmac_sha256 "tls12-aes-256-cbc-hmac-sha256" | ||
| 293 | +#define NID_tls12_aes_256_cbc_hmac_sha256 928 | ||
| 294 | + | ||
| 295 | diff --git a/crypto/objects/obj_mac.num b/crypto/objects/obj_mac.num | ||
| 296 | index a02b58c..deeba3a 100644 | ||
| 297 | --- a/crypto/objects/obj_mac.num | ||
| 298 | +++ b/crypto/objects/obj_mac.num | ||
| 299 | @@ -921,3 +921,8 @@ des_ede3_cbc_hmac_sha1 920 | ||
| 300 | tls11_des_ede3_cbc_hmac_sha1 921 | ||
| 301 | tls11_aes_128_cbc_hmac_sha1 922 | ||
| 302 | tls11_aes_256_cbc_hmac_sha1 923 | ||
| 303 | +tls12_des_ede3_cbc_hmac_sha1 924 | ||
| 304 | +tls12_aes_128_cbc_hmac_sha1 925 | ||
| 305 | +tls12_aes_256_cbc_hmac_sha1 926 | ||
| 306 | +tls12_aes_128_cbc_hmac_sha256 927 | ||
| 307 | +tls12_aes_256_cbc_hmac_sha256 928 | ||
| 308 | diff --git a/crypto/objects/objects.txt b/crypto/objects/objects.txt | ||
| 309 | index 1973658..6e4ac93 100644 | ||
| 310 | --- a/crypto/objects/objects.txt | ||
| 311 | +++ b/crypto/objects/objects.txt | ||
| 312 | @@ -1294,3 +1294,8 @@ kisa 1 6 : SEED-OFB : seed-ofb | ||
| 313 | : TLS11-DES-EDE3-CBC-HMAC-SHA1 : tls11-des-ede3-cbc-hmac-sha1 | ||
| 314 | : TLS11-AES-128-CBC-HMAC-SHA1 : tls11-aes-128-cbc-hmac-sha1 | ||
| 315 | : TLS11-AES-256-CBC-HMAC-SHA1 : tls11-aes-256-cbc-hmac-sha1 | ||
| 316 | + : TLS12-DES-EDE3-CBC-HMAC-SHA1 : tls12-des-ede3-cbc-hmac-sha1 | ||
| 317 | + : TLS12-AES-128-CBC-HMAC-SHA1 : tls12-aes-128-cbc-hmac-sha1 | ||
| 318 | + : TLS12-AES-256-CBC-HMAC-SHA1 : tls12-aes-256-cbc-hmac-sha1 | ||
| 319 | + : TLS12-AES-128-CBC-HMAC-SHA256 : tls12-aes-128-cbc-hmac-sha256 | ||
| 320 | + : TLS12-AES-256-CBC-HMAC-SHA256 : tls12-aes-256-cbc-hmac-sha256 | ||
| 321 | diff --git a/ssl/ssl_ciph.c b/ssl/ssl_ciph.c | ||
| 322 | index 0408986..77a82f6 100644 | ||
| 323 | --- a/ssl/ssl_ciph.c | ||
| 324 | +++ b/ssl/ssl_ciph.c | ||
| 325 | @@ -661,6 +661,31 @@ int ssl_cipher_get_evp(const SSL_SESSION *s, const EVP_CIPHER **enc, | ||
| 326 | c->algorithm_mac == SSL_SHA1 && | ||
| 327 | (evp=EVP_get_cipherbyname("TLS11-AES-256-CBC-HMAC-SHA1"))) | ||
| 328 | *enc = evp, *md = NULL; | ||
| 329 | + else if (s->ssl_version == TLS1_2_VERSION && | ||
| 330 | + c->algorithm_enc == SSL_3DES && | ||
| 331 | + c->algorithm_mac == SSL_SHA1 && | ||
| 332 | + (evp=EVP_get_cipherbyname("TLS12-DES-EDE3-CBC-HMAC-SHA1"))) | ||
| 333 | + *enc = evp, *md = NULL; | ||
| 334 | + else if (s->ssl_version == TLS1_2_VERSION && | ||
| 335 | + c->algorithm_enc == SSL_AES128 && | ||
| 336 | + c->algorithm_mac == SSL_SHA1 && | ||
| 337 | + (evp=EVP_get_cipherbyname("TLS12-AES-128-CBC-HMAC-SHA1"))) | ||
| 338 | + *enc = evp, *md = NULL; | ||
| 339 | + else if (s->ssl_version == TLS1_2_VERSION && | ||
| 340 | + c->algorithm_enc == SSL_AES256 && | ||
| 341 | + c->algorithm_mac == SSL_SHA1 && | ||
| 342 | + (evp=EVP_get_cipherbyname("TLS12-AES-256-CBC-HMAC-SHA1"))) | ||
| 343 | + *enc = evp, *md = NULL; | ||
| 344 | + else if (s->ssl_version == TLS1_2_VERSION && | ||
| 345 | + c->algorithm_enc == SSL_AES128 && | ||
| 346 | + c->algorithm_mac == SSL_SHA256 && | ||
| 347 | + (evp=EVP_get_cipherbyname("TLS12-AES-128-CBC-HMAC-SHA256"))) | ||
| 348 | + *enc = evp, *md = NULL; | ||
| 349 | + else if (s->ssl_version == TLS1_2_VERSION && | ||
| 350 | + c->algorithm_enc == SSL_AES256 && | ||
| 351 | + c->algorithm_mac == SSL_SHA256 && | ||
| 352 | + (evp=EVP_get_cipherbyname("TLS12-AES-256-CBC-HMAC-SHA256"))) | ||
| 353 | + *enc = evp, *md = NULL; | ||
| 354 | return(1); | ||
| 355 | } | ||
| 356 | else | ||
| 357 | -- | ||
| 358 | 2.3.5 | ||
| 359 | |||
diff --git a/recipes-connectivity/openssl/openssl-qoriq/qoriq/0021-cryptodev-do-not-cache-file-descriptor-in-open.patch b/recipes-connectivity/openssl/openssl-qoriq/qoriq/0021-cryptodev-do-not-cache-file-descriptor-in-open.patch new file mode 100644 index 000000000..9c6e503b8 --- /dev/null +++ b/recipes-connectivity/openssl/openssl-qoriq/qoriq/0021-cryptodev-do-not-cache-file-descriptor-in-open.patch | |||
| @@ -0,0 +1,93 @@ | |||
| 1 | From d9395f7d876f7dfaaae25867c88d1e1f684589de Mon Sep 17 00:00:00 2001 | ||
| 2 | From: Cristian Stoica <cristian.stoica@freescale.com> | ||
| 3 | Date: Thu, 19 Feb 2015 16:43:29 +0200 | ||
| 4 | Subject: [PATCH 21/48] cryptodev: do not cache file descriptor in 'open' | ||
| 5 | |||
| 6 | The file descriptor returned by get_dev_crypto is cached after a | ||
| 7 | successful return. The issue is, it is cached inside 'open_dev_crypto' | ||
| 8 | which is no longer useful as a general purpose open("/dev/crypto") | ||
| 9 | function. | ||
| 10 | |||
| 11 | This patch is a refactoring that moves the caching operation from | ||
| 12 | open_dev_crypto to get_dev_crypto and leaves the former as a simpler | ||
| 13 | function true to its name | ||
| 14 | |||
| 15 | Signed-off-by: Cristian Stoica <cristian.stoica@freescale.com> | ||
| 16 | --- | ||
| 17 | crypto/engine/eng_cryptodev.c | 43 +++++++++++++++++++++---------------------- | ||
| 18 | 1 file changed, 21 insertions(+), 22 deletions(-) | ||
| 19 | |||
| 20 | diff --git a/crypto/engine/eng_cryptodev.c b/crypto/engine/eng_cryptodev.c | ||
| 21 | index 14dcddf..75fca7f 100644 | ||
| 22 | --- a/crypto/engine/eng_cryptodev.c | ||
| 23 | +++ b/crypto/engine/eng_cryptodev.c | ||
| 24 | @@ -391,45 +391,44 @@ static void ctr64_inc(unsigned char *counter) | ||
| 25 | } while (n); | ||
| 26 | } | ||
| 27 | |||
| 28 | -/* | ||
| 29 | - * Return a fd if /dev/crypto seems usable, 0 otherwise. | ||
| 30 | - */ | ||
| 31 | static int open_dev_crypto(void) | ||
| 32 | { | ||
| 33 | - static int fd = -1; | ||
| 34 | + int fd; | ||
| 35 | |||
| 36 | - if (fd == -1) { | ||
| 37 | - if ((fd = open("/dev/crypto", O_RDWR, 0)) == -1) | ||
| 38 | - return (-1); | ||
| 39 | - /* close on exec */ | ||
| 40 | - if (fcntl(fd, F_SETFD, 1) == -1) { | ||
| 41 | - close(fd); | ||
| 42 | - fd = -1; | ||
| 43 | - return (-1); | ||
| 44 | - } | ||
| 45 | + fd = open("/dev/crypto", O_RDWR, 0); | ||
| 46 | + if (fd < 0) | ||
| 47 | + return -1; | ||
| 48 | + | ||
| 49 | + /* close on exec */ | ||
| 50 | + if (fcntl(fd, F_SETFD, 1) == -1) { | ||
| 51 | + close(fd); | ||
| 52 | + return -1; | ||
| 53 | } | ||
| 54 | - return (fd); | ||
| 55 | + | ||
| 56 | + return fd; | ||
| 57 | } | ||
| 58 | |||
| 59 | static int get_dev_crypto(void) | ||
| 60 | { | ||
| 61 | - int fd, retfd; | ||
| 62 | + static int fd = -1; | ||
| 63 | + int retfd; | ||
| 64 | |||
| 65 | - if ((fd = open_dev_crypto()) == -1) | ||
| 66 | - return (-1); | ||
| 67 | -# ifndef CRIOGET_NOT_NEEDED | ||
| 68 | + if (fd == -1) | ||
| 69 | + fd = open_dev_crypto(); | ||
| 70 | +# ifdef CRIOGET_NOT_NEEDED | ||
| 71 | + return fd; | ||
| 72 | +# else | ||
| 73 | + if (fd == -1) | ||
| 74 | + return -1; | ||
| 75 | if (ioctl(fd, CRIOGET, &retfd) == -1) | ||
| 76 | return (-1); | ||
| 77 | - | ||
| 78 | /* close on exec */ | ||
| 79 | if (fcntl(retfd, F_SETFD, 1) == -1) { | ||
| 80 | close(retfd); | ||
| 81 | return (-1); | ||
| 82 | } | ||
| 83 | -# else | ||
| 84 | - retfd = fd; | ||
| 85 | + return retfd; | ||
| 86 | # endif | ||
| 87 | - return (retfd); | ||
| 88 | } | ||
| 89 | |||
| 90 | static void put_dev_crypto(int fd) | ||
| 91 | -- | ||
| 92 | 2.7.0 | ||
| 93 | |||
diff --git a/recipes-connectivity/openssl/openssl-qoriq/qoriq/0021-cryptodev-drop-redundant-function.patch b/recipes-connectivity/openssl/openssl-qoriq/qoriq/0021-cryptodev-drop-redundant-function.patch deleted file mode 100644 index 16cc6882b..000000000 --- a/recipes-connectivity/openssl/openssl-qoriq/qoriq/0021-cryptodev-drop-redundant-function.patch +++ /dev/null | |||
| @@ -1,75 +0,0 @@ | |||
| 1 | From ea4abc255c6c5feec01cb1e30c6082cfe47860e2 Mon Sep 17 00:00:00 2001 | ||
| 2 | From: Cristian Stoica <cristian.stoica@freescale.com> | ||
| 3 | Date: Thu, 19 Feb 2015 16:11:53 +0200 | ||
| 4 | Subject: [PATCH 21/26] cryptodev: drop redundant function | ||
| 5 | |||
| 6 | get_dev_crypto already caches the result. Another cache in-between is | ||
| 7 | useless. | ||
| 8 | |||
| 9 | Change-Id: Ibd162529d3fb7a561a17f1a707d5d287c1586a3a | ||
| 10 | Signed-off-by: Cristian Stoica <cristian.stoica@freescale.com> | ||
| 11 | Reviewed-on: http://git.am.freescale.net:8181/34216 | ||
| 12 | --- | ||
| 13 | crypto/engine/eng_cryptodev.c | 18 +++--------------- | ||
| 14 | 1 file changed, 3 insertions(+), 15 deletions(-) | ||
| 15 | |||
| 16 | diff --git a/crypto/engine/eng_cryptodev.c b/crypto/engine/eng_cryptodev.c | ||
| 17 | index fa5fe1b..1ab5551 100644 | ||
| 18 | --- a/crypto/engine/eng_cryptodev.c | ||
| 19 | +++ b/crypto/engine/eng_cryptodev.c | ||
| 20 | @@ -96,7 +96,6 @@ struct dev_crypto_state { | ||
| 21 | |||
| 22 | static u_int32_t cryptodev_asymfeat = 0; | ||
| 23 | |||
| 24 | -static int get_asym_dev_crypto(void); | ||
| 25 | static int open_dev_crypto(void); | ||
| 26 | static int get_dev_crypto(void); | ||
| 27 | static int get_cryptodev_ciphers(const int **cnids); | ||
| 28 | @@ -357,17 +356,6 @@ static void put_dev_crypto(int fd) | ||
| 29 | #endif | ||
| 30 | } | ||
| 31 | |||
| 32 | -/* Caching version for asym operations */ | ||
| 33 | -static int | ||
| 34 | -get_asym_dev_crypto(void) | ||
| 35 | -{ | ||
| 36 | - static int fd = -1; | ||
| 37 | - | ||
| 38 | - if (fd == -1) | ||
| 39 | - fd = get_dev_crypto(); | ||
| 40 | - return fd; | ||
| 41 | -} | ||
| 42 | - | ||
| 43 | /* | ||
| 44 | * Find out what ciphers /dev/crypto will let us have a session for. | ||
| 45 | * XXX note, that some of these openssl doesn't deal with yet! | ||
| 46 | @@ -1796,7 +1784,7 @@ cryptodev_asym(struct crypt_kop *kop, int rlen, BIGNUM *r, int slen, BIGNUM *s) | ||
| 47 | { | ||
| 48 | int fd, ret = -1; | ||
| 49 | |||
| 50 | - if ((fd = get_asym_dev_crypto()) < 0) | ||
| 51 | + if ((fd = get_dev_crypto()) < 0) | ||
| 52 | return (ret); | ||
| 53 | |||
| 54 | if (r) { | ||
| 55 | @@ -2374,7 +2362,7 @@ static int cryptodev_rsa_keygen(RSA *rsa, int bits, BIGNUM *e, BN_GENCB *cb) | ||
| 56 | int p_len, q_len; | ||
| 57 | int i; | ||
| 58 | |||
| 59 | - if ((fd = get_asym_dev_crypto()) < 0) | ||
| 60 | + if ((fd = get_dev_crypto()) < 0) | ||
| 61 | goto sw_try; | ||
| 62 | |||
| 63 | if(!rsa->n && ((rsa->n=BN_new()) == NULL)) goto err; | ||
| 64 | @@ -3928,7 +3916,7 @@ cryptodev_dh_compute_key(unsigned char *key, const BIGNUM *pub_key, DH *dh) | ||
| 65 | BIGNUM *temp = NULL; | ||
| 66 | unsigned char *padded_pub_key = NULL, *p = NULL; | ||
| 67 | |||
| 68 | - if ((fd = get_asym_dev_crypto()) < 0) | ||
| 69 | + if ((fd = get_dev_crypto()) < 0) | ||
| 70 | goto sw_try; | ||
| 71 | |||
| 72 | memset(&kop, 0, sizeof kop); | ||
| 73 | -- | ||
| 74 | 2.3.5 | ||
| 75 | |||
diff --git a/recipes-connectivity/openssl/openssl-qoriq/qoriq/0022-cryptodev-do-not-zero-the-buffer-before-use.patch b/recipes-connectivity/openssl/openssl-qoriq/qoriq/0022-cryptodev-do-not-zero-the-buffer-before-use.patch deleted file mode 100644 index 0b2f0f1b5..000000000 --- a/recipes-connectivity/openssl/openssl-qoriq/qoriq/0022-cryptodev-do-not-zero-the-buffer-before-use.patch +++ /dev/null | |||
| @@ -1,48 +0,0 @@ | |||
| 1 | From 75e3e7d600eb72e7374b1ecf5ece7b831bc98ed8 Mon Sep 17 00:00:00 2001 | ||
| 2 | From: Cristian Stoica <cristian.stoica@freescale.com> | ||
| 3 | Date: Tue, 17 Feb 2015 13:12:53 +0200 | ||
| 4 | Subject: [PATCH 22/26] cryptodev: do not zero the buffer before use | ||
| 5 | |||
| 6 | - The buffer is just about to be overwritten. Zeroing it before that has | ||
| 7 | no purpose | ||
| 8 | |||
| 9 | Change-Id: I478c31bd2e254561474a7edf5e37980ca04217ce | ||
| 10 | Signed-off-by: Cristian Stoica <cristian.stoica@freescale.com> | ||
| 11 | Reviewed-on: http://git.am.freescale.net:8181/34217 | ||
| 12 | --- | ||
| 13 | crypto/engine/eng_cryptodev.c | 13 ++++--------- | ||
| 14 | 1 file changed, 4 insertions(+), 9 deletions(-) | ||
| 15 | |||
| 16 | diff --git a/crypto/engine/eng_cryptodev.c b/crypto/engine/eng_cryptodev.c | ||
| 17 | index 1ab5551..dbc5989 100644 | ||
| 18 | --- a/crypto/engine/eng_cryptodev.c | ||
| 19 | +++ b/crypto/engine/eng_cryptodev.c | ||
| 20 | @@ -1681,21 +1681,16 @@ static int | ||
| 21 | bn2crparam(const BIGNUM *a, struct crparam *crp) | ||
| 22 | { | ||
| 23 | ssize_t bytes, bits; | ||
| 24 | - u_char *b; | ||
| 25 | - | ||
| 26 | - crp->crp_p = NULL; | ||
| 27 | - crp->crp_nbits = 0; | ||
| 28 | |||
| 29 | bits = BN_num_bits(a); | ||
| 30 | bytes = (bits + 7) / 8; | ||
| 31 | |||
| 32 | - b = malloc(bytes); | ||
| 33 | - if (b == NULL) | ||
| 34 | + crp->crp_nbits = bits; | ||
| 35 | + crp->crp_p = malloc(bytes); | ||
| 36 | + | ||
| 37 | + if (crp->crp_p == NULL) | ||
| 38 | return (1); | ||
| 39 | - memset(b, 0, bytes); | ||
| 40 | |||
| 41 | - crp->crp_p = (caddr_t) b; | ||
| 42 | - crp->crp_nbits = bits; | ||
| 43 | BN_bn2bin(a, crp->crp_p); | ||
| 44 | return (0); | ||
| 45 | } | ||
| 46 | -- | ||
| 47 | 2.3.5 | ||
| 48 | |||
diff --git a/recipes-connectivity/openssl/openssl-qoriq/qoriq/0025-cryptodev-put_dev_crypto-should-be-an-int.patch b/recipes-connectivity/openssl/openssl-qoriq/qoriq/0022-cryptodev-put_dev_crypto-should-be-an-int.patch index a48dc6a67..121123d63 100644 --- a/recipes-connectivity/openssl/openssl-qoriq/qoriq/0025-cryptodev-put_dev_crypto-should-be-an-int.patch +++ b/recipes-connectivity/openssl/openssl-qoriq/qoriq/0022-cryptodev-put_dev_crypto-should-be-an-int.patch | |||
| @@ -1,7 +1,7 @@ | |||
| 1 | From 84a8007b6e92fe4c2696cc9e330207ee03303a20 Mon Sep 17 00:00:00 2001 | 1 | From 79d6976e2ad2e5ac31374bc24ee29ae53f55c0e1 Mon Sep 17 00:00:00 2001 |
| 2 | From: Cristian Stoica <cristian.stoica@freescale.com> | 2 | From: Cristian Stoica <cristian.stoica@freescale.com> |
| 3 | Date: Thu, 19 Feb 2015 13:09:32 +0200 | 3 | Date: Thu, 19 Feb 2015 13:09:32 +0200 |
| 4 | Subject: [PATCH 25/26] cryptodev: put_dev_crypto should be an int | 4 | Subject: [PATCH 22/48] cryptodev: put_dev_crypto should be an int |
| 5 | 5 | ||
| 6 | Change-Id: Ie0a83bc07a37132286c098b17ef35d98de74b043 | 6 | Change-Id: Ie0a83bc07a37132286c098b17ef35d98de74b043 |
| 7 | Signed-off-by: Cristian Stoica <cristian.stoica@freescale.com> | 7 | Signed-off-by: Cristian Stoica <cristian.stoica@freescale.com> |
| @@ -11,25 +11,25 @@ Reviewed-on: http://git.am.freescale.net:8181/34220 | |||
| 11 | 1 file changed, 5 insertions(+), 3 deletions(-) | 11 | 1 file changed, 5 insertions(+), 3 deletions(-) |
| 12 | 12 | ||
| 13 | diff --git a/crypto/engine/eng_cryptodev.c b/crypto/engine/eng_cryptodev.c | 13 | diff --git a/crypto/engine/eng_cryptodev.c b/crypto/engine/eng_cryptodev.c |
| 14 | index b74fc7c..c9db27d 100644 | 14 | index 75fca7f..b162646 100644 |
| 15 | --- a/crypto/engine/eng_cryptodev.c | 15 | --- a/crypto/engine/eng_cryptodev.c |
| 16 | +++ b/crypto/engine/eng_cryptodev.c | 16 | +++ b/crypto/engine/eng_cryptodev.c |
| 17 | @@ -347,10 +347,12 @@ static int get_dev_crypto(void) | 17 | @@ -431,10 +431,12 @@ static int get_dev_crypto(void) |
| 18 | #endif | 18 | # endif |
| 19 | } | 19 | } |
| 20 | 20 | ||
| 21 | -static void put_dev_crypto(int fd) | 21 | -static void put_dev_crypto(int fd) |
| 22 | +static int put_dev_crypto(int fd) | 22 | +static int put_dev_crypto(int fd) |
| 23 | { | 23 | { |
| 24 | -#ifndef CRIOGET_NOT_NEEDED | 24 | -# ifndef CRIOGET_NOT_NEEDED |
| 25 | - close(fd); | 25 | - close(fd); |
| 26 | +#ifdef CRIOGET_NOT_NEEDED | 26 | +#ifdef CRIOGET_NOT_NEEDED |
| 27 | + return 0; | 27 | + return 0; |
| 28 | +#else | 28 | +#else |
| 29 | + return close(fd); | 29 | + return close(fd); |
| 30 | #endif | 30 | # endif |
| 31 | } | 31 | } |
| 32 | 32 | ||
| 33 | -- | 33 | -- |
| 34 | 2.3.5 | 34 | 2.7.0 |
| 35 | 35 | ||
diff --git a/recipes-connectivity/openssl/openssl-qoriq/qoriq/0023-cryptodev-clean-up-code-layout.patch b/recipes-connectivity/openssl/openssl-qoriq/qoriq/0023-cryptodev-clean-up-code-layout.patch deleted file mode 100644 index 5ff1c5cac..000000000 --- a/recipes-connectivity/openssl/openssl-qoriq/qoriq/0023-cryptodev-clean-up-code-layout.patch +++ /dev/null | |||
| @@ -1,72 +0,0 @@ | |||
| 1 | From 4453b06b940fc03a0973cfd96f908e46cce61054 Mon Sep 17 00:00:00 2001 | ||
| 2 | From: Cristian Stoica <cristian.stoica@freescale.com> | ||
| 3 | Date: Wed, 18 Feb 2015 10:39:46 +0200 | ||
| 4 | Subject: [PATCH 23/26] cryptodev: clean-up code layout | ||
| 5 | |||
| 6 | This is just a refactoring that uses else branch to check for malloc failures | ||
| 7 | |||
| 8 | Change-Id: I6dc157af36d6ec51a4edfc82cf97fae2e7e83628 | ||
| 9 | Signed-off-by: Cristian Stoica <cristian.stoica@freescale.com> | ||
| 10 | Reviewed-on: http://git.am.freescale.net:8181/34218 | ||
| 11 | --- | ||
| 12 | crypto/engine/eng_cryptodev.c | 42 ++++++++++++++++++++---------------------- | ||
| 13 | 1 file changed, 20 insertions(+), 22 deletions(-) | ||
| 14 | |||
| 15 | diff --git a/crypto/engine/eng_cryptodev.c b/crypto/engine/eng_cryptodev.c | ||
| 16 | index dbc5989..dceb4f5 100644 | ||
| 17 | --- a/crypto/engine/eng_cryptodev.c | ||
| 18 | +++ b/crypto/engine/eng_cryptodev.c | ||
| 19 | @@ -1745,30 +1745,28 @@ cryptodev_asym_async(struct crypt_kop *kop, int rlen, BIGNUM *r, int slen, | ||
| 20 | fd = *(int *)cookie->eng_handle; | ||
| 21 | |||
| 22 | eng_cookie = malloc(sizeof(struct cryptodev_cookie_s)); | ||
| 23 | - | ||
| 24 | - if (eng_cookie) { | ||
| 25 | - memset(eng_cookie, 0, sizeof(struct cryptodev_cookie_s)); | ||
| 26 | - if (r) { | ||
| 27 | - kop->crk_param[kop->crk_iparams].crp_p = calloc(rlen, sizeof(char)); | ||
| 28 | - if (!kop->crk_param[kop->crk_iparams].crp_p) | ||
| 29 | - return -ENOMEM; | ||
| 30 | - kop->crk_param[kop->crk_iparams].crp_nbits = rlen * 8; | ||
| 31 | - kop->crk_oparams++; | ||
| 32 | - eng_cookie->r = r; | ||
| 33 | - eng_cookie->r_param = kop->crk_param[kop->crk_iparams]; | ||
| 34 | - } | ||
| 35 | - if (s) { | ||
| 36 | - kop->crk_param[kop->crk_iparams+1].crp_p = calloc(slen, sizeof(char)); | ||
| 37 | - if (!kop->crk_param[kop->crk_iparams+1].crp_p) | ||
| 38 | - return -ENOMEM; | ||
| 39 | - kop->crk_param[kop->crk_iparams+1].crp_nbits = slen * 8; | ||
| 40 | - kop->crk_oparams++; | ||
| 41 | - eng_cookie->s = s; | ||
| 42 | - eng_cookie->s_param = kop->crk_param[kop->crk_iparams + 1]; | ||
| 43 | - } | ||
| 44 | - } else | ||
| 45 | + if (!eng_cookie) | ||
| 46 | return -ENOMEM; | ||
| 47 | |||
| 48 | + memset(eng_cookie, 0, sizeof(struct cryptodev_cookie_s)); | ||
| 49 | + if (r) { | ||
| 50 | + kop->crk_param[kop->crk_iparams].crp_p = calloc(rlen, sizeof(char)); | ||
| 51 | + if (!kop->crk_param[kop->crk_iparams].crp_p) | ||
| 52 | + return -ENOMEM; | ||
| 53 | + kop->crk_param[kop->crk_iparams].crp_nbits = rlen * 8; | ||
| 54 | + kop->crk_oparams++; | ||
| 55 | + eng_cookie->r = r; | ||
| 56 | + eng_cookie->r_param = kop->crk_param[kop->crk_iparams]; | ||
| 57 | + } | ||
| 58 | + if (s) { | ||
| 59 | + kop->crk_param[kop->crk_iparams+1].crp_p = calloc(slen, sizeof(char)); | ||
| 60 | + if (!kop->crk_param[kop->crk_iparams+1].crp_p) | ||
| 61 | + return -ENOMEM; | ||
| 62 | + kop->crk_param[kop->crk_iparams+1].crp_nbits = slen * 8; | ||
| 63 | + kop->crk_oparams++; | ||
| 64 | + eng_cookie->s = s; | ||
| 65 | + eng_cookie->s_param = kop->crk_param[kop->crk_iparams + 1]; | ||
| 66 | + } | ||
| 67 | eng_cookie->kop = kop; | ||
| 68 | cookie->eng_cookie = eng_cookie; | ||
| 69 | return ioctl(fd, CIOCASYMASYNCRYPT, kop); | ||
| 70 | -- | ||
| 71 | 2.3.5 | ||
| 72 | |||
diff --git a/recipes-connectivity/openssl/openssl-qoriq/qoriq/0026-cryptodev-simplify-cryptodev-pkc-support-code.patch b/recipes-connectivity/openssl/openssl-qoriq/qoriq/0023-cryptodev-simplify-cryptodev-pkc-support-code.patch index 6527ac8f3..1043fbd49 100644 --- a/recipes-connectivity/openssl/openssl-qoriq/qoriq/0026-cryptodev-simplify-cryptodev-pkc-support-code.patch +++ b/recipes-connectivity/openssl/openssl-qoriq/qoriq/0023-cryptodev-simplify-cryptodev-pkc-support-code.patch | |||
| @@ -1,27 +1,25 @@ | |||
| 1 | From 787539e7720c99785f6c664a7484842bba08f6ed Mon Sep 17 00:00:00 2001 | 1 | From f99682e0ccaeadb7446d211dfad6dbf8fcd5675f Mon Sep 17 00:00:00 2001 |
| 2 | From: Cristian Stoica <cristian.stoica@freescale.com> | 2 | From: Cristian Stoica <cristian.stoica@freescale.com> |
| 3 | Date: Thu, 19 Feb 2015 13:39:52 +0200 | 3 | Date: Thu, 19 Feb 2015 13:39:52 +0200 |
| 4 | Subject: [PATCH 26/26] cryptodev: simplify cryptodev pkc support code | 4 | Subject: [PATCH 23/48] cryptodev: simplify cryptodev pkc support code |
| 5 | 5 | ||
| 6 | - Engine init returns directly a file descriptor instead of a pointer to one | 6 | - Engine init returns directly a file descriptor instead of a pointer to one |
| 7 | - Similarly, the Engine close will now just close the file | 7 | - Similarly, the Engine close will now just close the file |
| 8 | 8 | ||
| 9 | Change-Id: Ief736d0776c7009dee002204fb1d4ce9d31c8787 | ||
| 10 | Signed-off-by: Cristian Stoica <cristian.stoica@freescale.com> | 9 | Signed-off-by: Cristian Stoica <cristian.stoica@freescale.com> |
| 11 | Reviewed-on: http://git.am.freescale.net:8181/34221 | ||
| 12 | --- | 10 | --- |
| 13 | crypto/crypto.h | 2 +- | 11 | crypto/crypto.h | 2 +- |
| 14 | crypto/engine/eng_cryptodev.c | 35 +++----------------------- | 12 | crypto/engine/eng_cryptodev.c | 43 +++++++---------------------------- |
| 15 | crypto/engine/eng_int.h | 14 +++-------- | 13 | crypto/engine/eng_int.h | 14 +++--------- |
| 16 | crypto/engine/eng_lib.c | 57 +++++++++++++++++++++---------------------- | 14 | crypto/engine/eng_lib.c | 53 +++++++++++++++++++++---------------------- |
| 17 | crypto/engine/engine.h | 13 +++++----- | 15 | crypto/engine/engine.h | 13 +++++------ |
| 18 | 5 files changed, 42 insertions(+), 79 deletions(-) | 16 | 5 files changed, 44 insertions(+), 81 deletions(-) |
| 19 | 17 | ||
| 20 | diff --git a/crypto/crypto.h b/crypto/crypto.h | 18 | diff --git a/crypto/crypto.h b/crypto/crypto.h |
| 21 | index ce12731..292427e 100644 | 19 | index 2b4ec59..ddb9b69 100644 |
| 22 | --- a/crypto/crypto.h | 20 | --- a/crypto/crypto.h |
| 23 | +++ b/crypto/crypto.h | 21 | +++ b/crypto/crypto.h |
| 24 | @@ -618,7 +618,7 @@ struct pkc_cookie_s { | 22 | @@ -668,7 +668,7 @@ struct pkc_cookie_s { |
| 25 | * -EINVAL: Parameters Invalid | 23 | * -EINVAL: Parameters Invalid |
| 26 | */ | 24 | */ |
| 27 | void (*pkc_callback)(struct pkc_cookie_s *cookie, int status); | 25 | void (*pkc_callback)(struct pkc_cookie_s *cookie, int status); |
| @@ -31,77 +29,92 @@ index ce12731..292427e 100644 | |||
| 31 | 29 | ||
| 32 | #ifdef __cplusplus | 30 | #ifdef __cplusplus |
| 33 | diff --git a/crypto/engine/eng_cryptodev.c b/crypto/engine/eng_cryptodev.c | 31 | diff --git a/crypto/engine/eng_cryptodev.c b/crypto/engine/eng_cryptodev.c |
| 34 | index c9db27d..f173bde 100644 | 32 | index b162646..1910c89 100644 |
| 35 | --- a/crypto/engine/eng_cryptodev.c | 33 | --- a/crypto/engine/eng_cryptodev.c |
| 36 | +++ b/crypto/engine/eng_cryptodev.c | 34 | +++ b/crypto/engine/eng_cryptodev.c |
| 37 | @@ -1742,7 +1742,7 @@ cryptodev_asym_async(struct crypt_kop *kop, int rlen, BIGNUM *r, int slen, | 35 | @@ -433,10 +433,10 @@ static int get_dev_crypto(void) |
| 38 | struct pkc_cookie_s *cookie = kop->cookie; | ||
| 39 | struct cryptodev_cookie_s *eng_cookie; | ||
| 40 | 36 | ||
| 41 | - fd = *(int *)cookie->eng_handle; | 37 | static int put_dev_crypto(int fd) |
| 42 | + fd = cookie->eng_handle; | 38 | { |
| 39 | -#ifdef CRIOGET_NOT_NEEDED | ||
| 40 | - return 0; | ||
| 41 | -#else | ||
| 42 | - return close(fd); | ||
| 43 | +# ifdef CRIOGET_NOT_NEEDED | ||
| 44 | + return 0; | ||
| 45 | +# else | ||
| 46 | + return close(fd); | ||
| 47 | # endif | ||
| 48 | } | ||
| 49 | |||
| 50 | @@ -1863,7 +1863,7 @@ cryptodev_asym_async(struct crypt_kop *kop, int rlen, BIGNUM *r, int slen, | ||
| 51 | struct pkc_cookie_s *cookie = kop->cookie; | ||
| 52 | struct cryptodev_cookie_s *eng_cookie; | ||
| 53 | |||
| 54 | - fd = *(int *)cookie->eng_handle; | ||
| 55 | + fd = cookie->eng_handle; | ||
| 43 | 56 | ||
| 44 | eng_cookie = malloc(sizeof(struct cryptodev_cookie_s)); | 57 | eng_cookie = malloc(sizeof(struct cryptodev_cookie_s)); |
| 45 | if (!eng_cookie) | 58 | if (!eng_cookie) |
| 46 | @@ -1802,38 +1802,11 @@ cryptodev_asym(struct crypt_kop *kop, int rlen, BIGNUM *r, int slen, BIGNUM *s) | 59 | @@ -1926,38 +1926,11 @@ cryptodev_asym(struct crypt_kop *kop, int rlen, BIGNUM *r, int slen, |
| 47 | return (ret); | 60 | return (ret); |
| 48 | } | 61 | } |
| 49 | 62 | ||
| 50 | -/* Close an opened instance of cryptodev engine */ | 63 | -/* Close an opened instance of cryptodev engine */ |
| 51 | -void cryptodev_close_instance(void *handle) | 64 | -void cryptodev_close_instance(void *handle) |
| 52 | -{ | 65 | -{ |
| 53 | - int fd; | 66 | - int fd; |
| 54 | - | 67 | - |
| 55 | - if (handle) { | 68 | - if (handle) { |
| 56 | - fd = *(int *)handle; | 69 | - fd = *(int *)handle; |
| 57 | - close(fd); | 70 | - close(fd); |
| 58 | - free(handle); | 71 | - free(handle); |
| 59 | - } | 72 | - } |
| 60 | -} | 73 | -} |
| 61 | - | 74 | - |
| 62 | -/* Create an instance of cryptodev for asynchronous interface */ | 75 | -/* Create an instance of cryptodev for asynchronous interface */ |
| 63 | -void *cryptodev_init_instance(void) | 76 | -void *cryptodev_init_instance(void) |
| 64 | -{ | 77 | -{ |
| 65 | - int *fd = malloc(sizeof(int)); | 78 | - int *fd = malloc(sizeof(int)); |
| 66 | - | 79 | - |
| 67 | - if (fd) { | 80 | - if (fd) { |
| 68 | - if ((*fd = open("/dev/crypto", O_RDWR, 0)) == -1) { | 81 | - if ((*fd = open("/dev/crypto", O_RDWR, 0)) == -1) { |
| 69 | - free(fd); | 82 | - free(fd); |
| 70 | - return NULL; | 83 | - return NULL; |
| 71 | - } | 84 | - } |
| 72 | - } | 85 | - } |
| 73 | - return fd; | 86 | - return fd; |
| 74 | -} | 87 | -} |
| 75 | - | 88 | - |
| 76 | #include <poll.h> | 89 | # include <poll.h> |
| 77 | 90 | ||
| 78 | /* Return 0 on success and 1 on failure */ | 91 | /* Return 0 on success and 1 on failure */ |
| 79 | -int cryptodev_check_availability(void *eng_handle) | 92 | -int cryptodev_check_availability(void *eng_handle) |
| 80 | +int cryptodev_check_availability(int fd) | 93 | +int cryptodev_check_availability(int fd) |
| 81 | { | 94 | { |
| 82 | - int fd = *(int *)eng_handle; | 95 | - int fd = *(int *)eng_handle; |
| 83 | struct pkc_cookie_list_s cookie_list; | 96 | struct pkc_cookie_list_s cookie_list; |
| 84 | struct pkc_cookie_s *cookie; | 97 | struct pkc_cookie_s *cookie; |
| 85 | int i; | 98 | int i; |
| 86 | @@ -4540,8 +4513,8 @@ ENGINE_load_cryptodev(void) | 99 | @@ -4706,8 +4679,8 @@ void ENGINE_load_cryptodev(void) |
| 87 | } | 100 | } |
| 88 | 101 | ||
| 89 | ENGINE_set_check_pkc_availability(engine, cryptodev_check_availability); | 102 | ENGINE_set_check_pkc_availability(engine, cryptodev_check_availability); |
| 90 | - ENGINE_set_close_instance(engine, cryptodev_close_instance); | 103 | - ENGINE_set_close_instance(engine, cryptodev_close_instance); |
| 91 | - ENGINE_set_init_instance(engine, cryptodev_init_instance); | 104 | - ENGINE_set_init_instance(engine, cryptodev_init_instance); |
| 92 | + ENGINE_set_close_instance(engine, put_dev_crypto); | 105 | + ENGINE_set_close_instance(engine, put_dev_crypto); |
| 93 | + ENGINE_set_open_instance(engine, open_dev_crypto); | 106 | + ENGINE_set_open_instance(engine, open_dev_crypto); |
| 94 | ENGINE_set_async_map(engine, ENGINE_ALLPKC_ASYNC); | 107 | ENGINE_set_async_map(engine, ENGINE_ALLPKC_ASYNC); |
| 95 | 108 | ||
| 96 | ENGINE_add(engine); | 109 | ENGINE_add(engine); |
| 97 | diff --git a/crypto/engine/eng_int.h b/crypto/engine/eng_int.h | 110 | diff --git a/crypto/engine/eng_int.h b/crypto/engine/eng_int.h |
| 98 | index 8fc3077..8fb79c0 100644 | 111 | index b698a0c..7541beb 100644 |
| 99 | --- a/crypto/engine/eng_int.h | 112 | --- a/crypto/engine/eng_int.h |
| 100 | +++ b/crypto/engine/eng_int.h | 113 | +++ b/crypto/engine/eng_int.h |
| 101 | @@ -181,23 +181,15 @@ struct engine_st | 114 | @@ -198,23 +198,15 @@ struct engine_st { |
| 102 | ENGINE_LOAD_KEY_PTR load_pubkey; | 115 | ENGINE_LOAD_KEY_PTR load_privkey; |
| 103 | 116 | ENGINE_LOAD_KEY_PTR load_pubkey; | |
| 104 | ENGINE_SSL_CLIENT_CERT_PTR load_ssl_client_cert; | 117 | ENGINE_SSL_CLIENT_CERT_PTR load_ssl_client_cert; |
| 105 | - /* | 118 | - /* |
| 106 | - * Instantiate Engine handle to be passed in check_pkc_availability | 119 | - * Instantiate Engine handle to be passed in check_pkc_availability |
| 107 | - * Ensure that Engine is instantiated before any pkc asynchronous call. | 120 | - * Ensure that Engine is instantiated before any pkc asynchronous call. |
| @@ -126,20 +139,20 @@ index 8fc3077..8fb79c0 100644 | |||
| 126 | * The following map is used to check if the engine supports asynchronous implementation | 139 | * The following map is used to check if the engine supports asynchronous implementation |
| 127 | * ENGINE_ASYNC_FLAG* for available bitmap. Any application checking for asynchronous | 140 | * ENGINE_ASYNC_FLAG* for available bitmap. Any application checking for asynchronous |
| 128 | diff --git a/crypto/engine/eng_lib.c b/crypto/engine/eng_lib.c | 141 | diff --git a/crypto/engine/eng_lib.c b/crypto/engine/eng_lib.c |
| 129 | index 6fa621c..6c9471b 100644 | 142 | index 0c57e12..4fdcfd6 100644 |
| 130 | --- a/crypto/engine/eng_lib.c | 143 | --- a/crypto/engine/eng_lib.c |
| 131 | +++ b/crypto/engine/eng_lib.c | 144 | +++ b/crypto/engine/eng_lib.c |
| 132 | @@ -99,7 +99,7 @@ void engine_set_all_null(ENGINE *e) | 145 | @@ -101,7 +101,7 @@ void engine_set_all_null(ENGINE *e) |
| 133 | e->load_privkey = NULL; | 146 | e->load_privkey = NULL; |
| 134 | e->load_pubkey = NULL; | 147 | e->load_pubkey = NULL; |
| 135 | e->check_pkc_availability = NULL; | 148 | e->check_pkc_availability = NULL; |
| 136 | - e->engine_init_instance = NULL; | 149 | - e->engine_init_instance = NULL; |
| 137 | + e->engine_open_instance = NULL; | 150 | + e->engine_open_instance = NULL; |
| 138 | e->engine_close_instance = NULL; | 151 | e->engine_close_instance = NULL; |
| 139 | e->cmd_defns = NULL; | 152 | e->cmd_defns = NULL; |
| 140 | e->async_map = 0; | 153 | e->async_map = 0; |
| 141 | @@ -237,47 +237,46 @@ int ENGINE_set_id(ENGINE *e, const char *id) | 154 | @@ -252,46 +252,45 @@ int ENGINE_set_id(ENGINE *e, const char *id) |
| 142 | return 1; | 155 | return 1; |
| 143 | } | 156 | } |
| 144 | 157 | ||
| 145 | -void ENGINE_set_init_instance(ENGINE *e, void *(*engine_init_instance)(void)) | 158 | -void ENGINE_set_init_instance(ENGINE *e, void *(*engine_init_instance)(void)) |
| @@ -181,43 +194,40 @@ index 6fa621c..6c9471b 100644 | |||
| 181 | return e->async_map; | 194 | return e->async_map; |
| 182 | } | 195 | } |
| 183 | 196 | ||
| 184 | -void ENGINE_set_check_pkc_availability(ENGINE *e, | ||
| 185 | - int (*check_pkc_availability)(void *eng_handle)) | ||
| 186 | - { | ||
| 187 | - e->check_pkc_availability = check_pkc_availability; | ||
| 188 | - } | ||
| 189 | +int ENGINE_open_instance(ENGINE *e) | 197 | +int ENGINE_open_instance(ENGINE *e) |
| 190 | +{ | 198 | +{ |
| 191 | + return e->engine_open_instance(); | 199 | + return e->engine_open_instance(); |
| 192 | +} | 200 | +} |
| 193 | 201 | + | |
| 194 | -int ENGINE_check_pkc_availability(ENGINE *e, void *eng_handle) | ||
| 195 | - { | ||
| 196 | - return e->check_pkc_availability(eng_handle); | ||
| 197 | - } | ||
| 198 | +int ENGINE_close_instance(ENGINE *e, int fd) | 202 | +int ENGINE_close_instance(ENGINE *e, int fd) |
| 199 | +{ | 203 | +{ |
| 200 | + return e->engine_close_instance(fd); | 204 | + return e->engine_close_instance(fd); |
| 201 | +} | 205 | +} |
| 202 | + | 206 | + |
| 203 | +void ENGINE_set_check_pkc_availability(ENGINE *e, | 207 | void ENGINE_set_check_pkc_availability(ENGINE *e, |
| 208 | - int (*check_pkc_availability)(void *eng_handle)) | ||
| 209 | - { | ||
| 210 | - e->check_pkc_availability = check_pkc_availability; | ||
| 211 | - } | ||
| 204 | + int (*check_pkc_availability)(int fd)) | 212 | + int (*check_pkc_availability)(int fd)) |
| 205 | +{ | 213 | +{ |
| 206 | + e->check_pkc_availability = check_pkc_availability; | 214 | + e->check_pkc_availability = check_pkc_availability; |
| 207 | +} | 215 | +} |
| 208 | + | 216 | |
| 217 | -int ENGINE_check_pkc_availability(ENGINE *e, void *eng_handle) | ||
| 218 | - { | ||
| 219 | - return e->check_pkc_availability(eng_handle); | ||
| 209 | +int ENGINE_check_pkc_availability(ENGINE *e, int fd) | 220 | +int ENGINE_check_pkc_availability(ENGINE *e, int fd) |
| 210 | +{ | 221 | +{ |
| 211 | + return e->check_pkc_availability(fd); | 222 | + return e->check_pkc_availability(fd); |
| 212 | +} | 223 | } |
| 213 | 224 | ||
| 214 | int ENGINE_set_name(ENGINE *e, const char *name) | 225 | int ENGINE_set_name(ENGINE *e, const char *name) |
| 215 | { | ||
| 216 | diff --git a/crypto/engine/engine.h b/crypto/engine/engine.h | 226 | diff --git a/crypto/engine/engine.h b/crypto/engine/engine.h |
| 217 | index ccff86a..3ba3e97 100644 | 227 | index 4527aa1..f83ee73 100644 |
| 218 | --- a/crypto/engine/engine.h | 228 | --- a/crypto/engine/engine.h |
| 219 | +++ b/crypto/engine/engine.h | 229 | +++ b/crypto/engine/engine.h |
| 220 | @@ -473,9 +473,6 @@ ENGINE *ENGINE_new(void); | 230 | @@ -551,9 +551,6 @@ ENGINE *ENGINE_new(void); |
| 221 | int ENGINE_free(ENGINE *e); | 231 | int ENGINE_free(ENGINE *e); |
| 222 | int ENGINE_up_ref(ENGINE *e); | 232 | int ENGINE_up_ref(ENGINE *e); |
| 223 | int ENGINE_set_id(ENGINE *e, const char *id); | 233 | int ENGINE_set_id(ENGINE *e, const char *id); |
| @@ -227,7 +237,7 @@ index ccff86a..3ba3e97 100644 | |||
| 227 | /* | 237 | /* |
| 228 | * Following FLAGS are bitmap store in async_map to set asynchronous interface capability | 238 | * Following FLAGS are bitmap store in async_map to set asynchronous interface capability |
| 229 | *of the engine | 239 | *of the engine |
| 230 | @@ -492,11 +489,13 @@ void ENGINE_set_async_map(ENGINE *e, int async_map); | 240 | @@ -570,11 +567,13 @@ void ENGINE_set_async_map(ENGINE *e, int async_map); |
| 231 | * to confirm asynchronous methods supported | 241 | * to confirm asynchronous methods supported |
| 232 | */ | 242 | */ |
| 233 | int ENGINE_get_async_map(ENGINE *e); | 243 | int ENGINE_get_async_map(ENGINE *e); |
| @@ -246,5 +256,5 @@ index ccff86a..3ba3e97 100644 | |||
| 246 | int ENGINE_set_RSA(ENGINE *e, const RSA_METHOD *rsa_meth); | 256 | int ENGINE_set_RSA(ENGINE *e, const RSA_METHOD *rsa_meth); |
| 247 | int ENGINE_set_DSA(ENGINE *e, const DSA_METHOD *dsa_meth); | 257 | int ENGINE_set_DSA(ENGINE *e, const DSA_METHOD *dsa_meth); |
| 248 | -- | 258 | -- |
| 249 | 2.3.5 | 259 | 2.7.0 |
| 250 | 260 | ||
diff --git a/recipes-connectivity/openssl/openssl-qoriq/qoriq/0024-cryptodev-clarify-code-remove-assignments-from-condi.patch b/recipes-connectivity/openssl/openssl-qoriq/qoriq/0024-cryptodev-clarify-code-remove-assignments-from-condi.patch new file mode 100644 index 000000000..27ccd95a5 --- /dev/null +++ b/recipes-connectivity/openssl/openssl-qoriq/qoriq/0024-cryptodev-clarify-code-remove-assignments-from-condi.patch | |||
| @@ -0,0 +1,37 @@ | |||
| 1 | From cb6842dac159b40acdc755526b0ba0afb61d9d64 Mon Sep 17 00:00:00 2001 | ||
| 2 | From: Cristian Stoica <cristian.stoica@nxp.com> | ||
| 3 | Date: Mon, 14 Dec 2015 14:02:00 +0200 | ||
| 4 | Subject: [PATCH 24/48] cryptodev: clarify code, remove assignments from | ||
| 5 | conditionals | ||
| 6 | |||
| 7 | Signed-off-by: Cristian Stoica <cristian.stoica@nxp.com> | ||
| 8 | --- | ||
| 9 | crypto/engine/eng_cryptodev.c | 6 ++++-- | ||
| 10 | 1 file changed, 4 insertions(+), 2 deletions(-) | ||
| 11 | |||
| 12 | diff --git a/crypto/engine/eng_cryptodev.c b/crypto/engine/eng_cryptodev.c | ||
| 13 | index 1910c89..fcfd232 100644 | ||
| 14 | --- a/crypto/engine/eng_cryptodev.c | ||
| 15 | +++ b/crypto/engine/eng_cryptodev.c | ||
| 16 | @@ -1559,14 +1559,16 @@ static int cryptodev_digest_init(EVP_MD_CTX *ctx) | ||
| 17 | struct session_op *sess = &state->d_sess; | ||
| 18 | int digest; | ||
| 19 | |||
| 20 | - if ((digest = digest_nid_to_cryptodev(ctx->digest->type)) == NID_undef) { | ||
| 21 | + digest = digest_nid_to_cryptodev(ctx->digest->type); | ||
| 22 | + if (digest == NID_undef) { | ||
| 23 | printf("cryptodev_digest_init: Can't get digest \n"); | ||
| 24 | return (0); | ||
| 25 | } | ||
| 26 | |||
| 27 | memset(state, 0, sizeof(struct dev_crypto_state)); | ||
| 28 | |||
| 29 | - if ((state->d_fd = get_dev_crypto()) < 0) { | ||
| 30 | + state->d_fd = get_dev_crypto(); | ||
| 31 | + if (state->d_fd < 0) { | ||
| 32 | printf("cryptodev_digest_init: Can't get Dev \n"); | ||
| 33 | return (0); | ||
| 34 | } | ||
| 35 | -- | ||
| 36 | 2.7.0 | ||
| 37 | |||
diff --git a/recipes-connectivity/openssl/openssl-qoriq/qoriq/0024-cryptodev-do-not-cache-file-descriptor-in-open.patch b/recipes-connectivity/openssl/openssl-qoriq/qoriq/0024-cryptodev-do-not-cache-file-descriptor-in-open.patch deleted file mode 100644 index e798d3e23..000000000 --- a/recipes-connectivity/openssl/openssl-qoriq/qoriq/0024-cryptodev-do-not-cache-file-descriptor-in-open.patch +++ /dev/null | |||
| @@ -1,100 +0,0 @@ | |||
| 1 | From a44701abd995b3db80001d0c5d88e9ead05972c1 Mon Sep 17 00:00:00 2001 | ||
| 2 | From: Cristian Stoica <cristian.stoica@freescale.com> | ||
| 3 | Date: Thu, 19 Feb 2015 16:43:29 +0200 | ||
| 4 | Subject: [PATCH 24/26] cryptodev: do not cache file descriptor in 'open' | ||
| 5 | |||
| 6 | The file descriptor returned by get_dev_crypto is cached after a | ||
| 7 | successful return. The issue is, it is cached inside 'open_dev_crypto' | ||
| 8 | which is no longer useful as a general purpose open("/dev/crypto") | ||
| 9 | function. | ||
| 10 | |||
| 11 | This patch is a refactoring that moves the caching operation from | ||
| 12 | open_dev_crypto to get_dev_crypto and leaves the former as a simpler | ||
| 13 | function true to its name | ||
| 14 | |||
| 15 | Change-Id: I980170969410381973ce75f6679a4a1401738847 | ||
| 16 | Signed-off-by: Cristian Stoica <cristian.stoica@freescale.com> | ||
| 17 | Reviewed-on: http://git.am.freescale.net:8181/34219 | ||
| 18 | --- | ||
| 19 | crypto/engine/eng_cryptodev.c | 50 +++++++++++++++++++++---------------------- | ||
| 20 | 1 file changed, 24 insertions(+), 26 deletions(-) | ||
| 21 | |||
| 22 | diff --git a/crypto/engine/eng_cryptodev.c b/crypto/engine/eng_cryptodev.c | ||
| 23 | index dceb4f5..b74fc7c 100644 | ||
| 24 | --- a/crypto/engine/eng_cryptodev.c | ||
| 25 | +++ b/crypto/engine/eng_cryptodev.c | ||
| 26 | @@ -306,47 +306,45 @@ static void ctr64_inc(unsigned char *counter) { | ||
| 27 | if (c) return; | ||
| 28 | } while (n); | ||
| 29 | } | ||
| 30 | -/* | ||
| 31 | - * Return a fd if /dev/crypto seems usable, 0 otherwise. | ||
| 32 | - */ | ||
| 33 | -static int | ||
| 34 | -open_dev_crypto(void) | ||
| 35 | + | ||
| 36 | +static int open_dev_crypto(void) | ||
| 37 | { | ||
| 38 | - static int fd = -1; | ||
| 39 | + int fd; | ||
| 40 | |||
| 41 | - if (fd == -1) { | ||
| 42 | - if ((fd = open("/dev/crypto", O_RDWR, 0)) == -1) | ||
| 43 | - return (-1); | ||
| 44 | - /* close on exec */ | ||
| 45 | - if (fcntl(fd, F_SETFD, 1) == -1) { | ||
| 46 | - close(fd); | ||
| 47 | - fd = -1; | ||
| 48 | - return (-1); | ||
| 49 | - } | ||
| 50 | + fd = open("/dev/crypto", O_RDWR, 0); | ||
| 51 | + if ( fd < 0) | ||
| 52 | + return -1; | ||
| 53 | + | ||
| 54 | + /* close on exec */ | ||
| 55 | + if (fcntl(fd, F_SETFD, 1) == -1) { | ||
| 56 | + close(fd); | ||
| 57 | + return -1; | ||
| 58 | } | ||
| 59 | - return (fd); | ||
| 60 | + | ||
| 61 | + return fd; | ||
| 62 | } | ||
| 63 | |||
| 64 | -static int | ||
| 65 | -get_dev_crypto(void) | ||
| 66 | +static int get_dev_crypto(void) | ||
| 67 | { | ||
| 68 | - int fd, retfd; | ||
| 69 | + static int fd = -1; | ||
| 70 | + int retfd; | ||
| 71 | |||
| 72 | - if ((fd = open_dev_crypto()) == -1) | ||
| 73 | - return (-1); | ||
| 74 | -#ifndef CRIOGET_NOT_NEEDED | ||
| 75 | + if (fd == -1) | ||
| 76 | + fd = open_dev_crypto(); | ||
| 77 | +#ifdef CRIOGET_NOT_NEEDED | ||
| 78 | + return fd; | ||
| 79 | +#else | ||
| 80 | + if (fd == -1) | ||
| 81 | + return -1; | ||
| 82 | if (ioctl(fd, CRIOGET, &retfd) == -1) | ||
| 83 | return (-1); | ||
| 84 | - | ||
| 85 | /* close on exec */ | ||
| 86 | if (fcntl(retfd, F_SETFD, 1) == -1) { | ||
| 87 | close(retfd); | ||
| 88 | return (-1); | ||
| 89 | } | ||
| 90 | -#else | ||
| 91 | - retfd = fd; | ||
| 92 | + return retfd; | ||
| 93 | #endif | ||
| 94 | - return (retfd); | ||
| 95 | } | ||
| 96 | |||
| 97 | static void put_dev_crypto(int fd) | ||
| 98 | -- | ||
| 99 | 2.3.5 | ||
| 100 | |||
diff --git a/recipes-connectivity/openssl/openssl-qoriq/qoriq/0025-cryptodev-clean-up-context-state-before-anything-els.patch b/recipes-connectivity/openssl/openssl-qoriq/qoriq/0025-cryptodev-clean-up-context-state-before-anything-els.patch new file mode 100644 index 000000000..ad5c3035e --- /dev/null +++ b/recipes-connectivity/openssl/openssl-qoriq/qoriq/0025-cryptodev-clean-up-context-state-before-anything-els.patch | |||
| @@ -0,0 +1,34 @@ | |||
| 1 | From 087ae4ecbaf9cd49a2fcae9cb09c491beabc4c88 Mon Sep 17 00:00:00 2001 | ||
| 2 | From: Cristian Stoica <cristian.stoica@nxp.com> | ||
| 3 | Date: Tue, 15 Dec 2015 12:10:37 +0200 | ||
| 4 | Subject: [PATCH 25/48] cryptodev: clean-up context state before anything else | ||
| 5 | |||
| 6 | Signed-off-by: Cristian Stoica <cristian.stoica@nxp.com> | ||
| 7 | --- | ||
| 8 | crypto/engine/eng_cryptodev.c | 4 ++-- | ||
| 9 | 1 file changed, 2 insertions(+), 2 deletions(-) | ||
| 10 | |||
| 11 | diff --git a/crypto/engine/eng_cryptodev.c b/crypto/engine/eng_cryptodev.c | ||
| 12 | index fcfd232..16e6fd9 100644 | ||
| 13 | --- a/crypto/engine/eng_cryptodev.c | ||
| 14 | +++ b/crypto/engine/eng_cryptodev.c | ||
| 15 | @@ -1559,14 +1559,14 @@ static int cryptodev_digest_init(EVP_MD_CTX *ctx) | ||
| 16 | struct session_op *sess = &state->d_sess; | ||
| 17 | int digest; | ||
| 18 | |||
| 19 | + memset(state, 0, sizeof(struct dev_crypto_state)); | ||
| 20 | + | ||
| 21 | digest = digest_nid_to_cryptodev(ctx->digest->type); | ||
| 22 | if (digest == NID_undef) { | ||
| 23 | printf("cryptodev_digest_init: Can't get digest \n"); | ||
| 24 | return (0); | ||
| 25 | } | ||
| 26 | |||
| 27 | - memset(state, 0, sizeof(struct dev_crypto_state)); | ||
| 28 | - | ||
| 29 | state->d_fd = get_dev_crypto(); | ||
| 30 | if (state->d_fd < 0) { | ||
| 31 | printf("cryptodev_digest_init: Can't get Dev \n"); | ||
| 32 | -- | ||
| 33 | 2.7.0 | ||
| 34 | |||
diff --git a/recipes-connectivity/openssl/openssl-qoriq/qoriq/0026-cryptodev-remove-code-duplication-in-digest-operatio.patch b/recipes-connectivity/openssl/openssl-qoriq/qoriq/0026-cryptodev-remove-code-duplication-in-digest-operatio.patch new file mode 100644 index 000000000..936aafced --- /dev/null +++ b/recipes-connectivity/openssl/openssl-qoriq/qoriq/0026-cryptodev-remove-code-duplication-in-digest-operatio.patch | |||
| @@ -0,0 +1,155 @@ | |||
| 1 | From 02dd4d275f7544a4027ca3452b60ac5bdd9376fb Mon Sep 17 00:00:00 2001 | ||
| 2 | From: Cristian Stoica <cristian.stoica@nxp.com> | ||
| 3 | Date: Mon, 14 Dec 2015 17:49:08 +0200 | ||
| 4 | Subject: [PATCH 26/48] cryptodev: remove code duplication in digest operations | ||
| 5 | |||
| 6 | This patch simplifies code and removes duplication in digest_update and | ||
| 7 | digest_final for cryptodev engine. | ||
| 8 | |||
| 9 | Note: The current design of eng_cryptodev for digests operations assumes | ||
| 10 | the presence of all the data before processing (this is suboptimal | ||
| 11 | with cryptodev-linux because Linux kernel has support for digest-update | ||
| 12 | operations and there is no need to accumulate the input data). | ||
| 13 | |||
| 14 | Signed-off-by: Cristian Stoica <cristian.stoica@nxp.com> | ||
| 15 | --- | ||
| 16 | crypto/engine/eng_cryptodev.c | 76 ++++++++++++++++--------------------------- | ||
| 17 | 1 file changed, 28 insertions(+), 48 deletions(-) | ||
| 18 | |||
| 19 | diff --git a/crypto/engine/eng_cryptodev.c b/crypto/engine/eng_cryptodev.c | ||
| 20 | index 16e6fd9..048e050 100644 | ||
| 21 | --- a/crypto/engine/eng_cryptodev.c | ||
| 22 | +++ b/crypto/engine/eng_cryptodev.c | ||
| 23 | @@ -1590,24 +1590,25 @@ static int cryptodev_digest_init(EVP_MD_CTX *ctx) | ||
| 24 | static int cryptodev_digest_update(EVP_MD_CTX *ctx, const void *data, | ||
| 25 | size_t count) | ||
| 26 | { | ||
| 27 | - struct crypt_op cryp; | ||
| 28 | struct dev_crypto_state *state = ctx->md_data; | ||
| 29 | - struct session_op *sess = &state->d_sess; | ||
| 30 | |||
| 31 | - if (!data || state->d_fd < 0) { | ||
| 32 | + if (!data || !count) { | ||
| 33 | printf("cryptodev_digest_update: illegal inputs \n"); | ||
| 34 | - return (0); | ||
| 35 | - } | ||
| 36 | - | ||
| 37 | - if (!count) { | ||
| 38 | - return (0); | ||
| 39 | + return 0; | ||
| 40 | } | ||
| 41 | |||
| 42 | - if (!(ctx->flags & EVP_MD_CTX_FLAG_ONESHOT)) { | ||
| 43 | - /* if application doesn't support one buffer */ | ||
| 44 | + /* | ||
| 45 | + * Accumulate input data if it is scattered in several buffers. TODO: | ||
| 46 | + * Depending on number of calls and data size, this code can be optimized | ||
| 47 | + * to take advantage of Linux kernel crypto API, balancing between | ||
| 48 | + * cryptodev calls and accumulating small amounts of data | ||
| 49 | + */ | ||
| 50 | + if (ctx->flags & EVP_MD_CTX_FLAG_ONESHOT) { | ||
| 51 | + state->mac_data = data; | ||
| 52 | + state->mac_len = count; | ||
| 53 | + } else { | ||
| 54 | state->mac_data = | ||
| 55 | OPENSSL_realloc(state->mac_data, state->mac_len + count); | ||
| 56 | - | ||
| 57 | if (!state->mac_data) { | ||
| 58 | printf("cryptodev_digest_update: realloc failed\n"); | ||
| 59 | return (0); | ||
| 60 | @@ -1615,23 +1616,9 @@ static int cryptodev_digest_update(EVP_MD_CTX *ctx, const void *data, | ||
| 61 | |||
| 62 | memcpy(state->mac_data + state->mac_len, data, count); | ||
| 63 | state->mac_len += count; | ||
| 64 | - | ||
| 65 | - return (1); | ||
| 66 | } | ||
| 67 | |||
| 68 | - memset(&cryp, 0, sizeof(cryp)); | ||
| 69 | - | ||
| 70 | - cryp.ses = sess->ses; | ||
| 71 | - cryp.flags = 0; | ||
| 72 | - cryp.len = count; | ||
| 73 | - cryp.src = (caddr_t) data; | ||
| 74 | - cryp.dst = NULL; | ||
| 75 | - cryp.mac = (caddr_t) state->digest_res; | ||
| 76 | - if (ioctl(state->d_fd, CIOCCRYPT, &cryp) < 0) { | ||
| 77 | - printf("cryptodev_digest_update: digest failed\n"); | ||
| 78 | - return (0); | ||
| 79 | - } | ||
| 80 | - return (1); | ||
| 81 | + return 1; | ||
| 82 | } | ||
| 83 | |||
| 84 | static int cryptodev_digest_final(EVP_MD_CTX *ctx, unsigned char *md) | ||
| 85 | @@ -1640,33 +1627,25 @@ static int cryptodev_digest_final(EVP_MD_CTX *ctx, unsigned char *md) | ||
| 86 | struct dev_crypto_state *state = ctx->md_data; | ||
| 87 | struct session_op *sess = &state->d_sess; | ||
| 88 | |||
| 89 | - int ret = 1; | ||
| 90 | - | ||
| 91 | if (!md || state->d_fd < 0) { | ||
| 92 | printf("cryptodev_digest_final: illegal input\n"); | ||
| 93 | return (0); | ||
| 94 | } | ||
| 95 | |||
| 96 | - if (!(ctx->flags & EVP_MD_CTX_FLAG_ONESHOT)) { | ||
| 97 | - /* if application doesn't support one buffer */ | ||
| 98 | - memset(&cryp, 0, sizeof(cryp)); | ||
| 99 | - cryp.ses = sess->ses; | ||
| 100 | - cryp.flags = 0; | ||
| 101 | - cryp.len = state->mac_len; | ||
| 102 | - cryp.src = state->mac_data; | ||
| 103 | - cryp.dst = NULL; | ||
| 104 | - cryp.mac = (caddr_t) md; | ||
| 105 | - if (ioctl(state->d_fd, CIOCCRYPT, &cryp) < 0) { | ||
| 106 | - printf("cryptodev_digest_final: digest failed\n"); | ||
| 107 | - return (0); | ||
| 108 | - } | ||
| 109 | + memset(&cryp, 0, sizeof(cryp)); | ||
| 110 | |||
| 111 | - return 1; | ||
| 112 | - } | ||
| 113 | + cryp.ses = sess->ses; | ||
| 114 | + cryp.flags = 0; | ||
| 115 | + cryp.len = state->mac_len; | ||
| 116 | + cryp.src = state->mac_data; | ||
| 117 | + cryp.mac = md; | ||
| 118 | |||
| 119 | - memcpy(md, state->digest_res, ctx->digest->md_size); | ||
| 120 | + if (ioctl(state->d_fd, CIOCCRYPT, &cryp) < 0) { | ||
| 121 | + printf("cryptodev_digest_final: digest failed\n"); | ||
| 122 | + return (0); | ||
| 123 | + } | ||
| 124 | |||
| 125 | - return (ret); | ||
| 126 | + return (1); | ||
| 127 | } | ||
| 128 | |||
| 129 | static int cryptodev_digest_cleanup(EVP_MD_CTX *ctx) | ||
| 130 | @@ -1683,11 +1662,11 @@ static int cryptodev_digest_cleanup(EVP_MD_CTX *ctx) | ||
| 131 | return (0); | ||
| 132 | } | ||
| 133 | |||
| 134 | - if (state->mac_data) { | ||
| 135 | + if (!(ctx->flags & EVP_MD_CTX_FLAG_ONESHOT)) { | ||
| 136 | OPENSSL_free(state->mac_data); | ||
| 137 | - state->mac_data = NULL; | ||
| 138 | - state->mac_len = 0; | ||
| 139 | } | ||
| 140 | + state->mac_data = NULL; | ||
| 141 | + state->mac_len = 0; | ||
| 142 | |||
| 143 | if (ioctl(state->d_fd, CIOCFSESSION, &sess->ses) < 0) { | ||
| 144 | printf("cryptodev_digest_cleanup: failed to close session\n"); | ||
| 145 | @@ -1695,6 +1674,7 @@ static int cryptodev_digest_cleanup(EVP_MD_CTX *ctx) | ||
| 146 | } else { | ||
| 147 | ret = 1; | ||
| 148 | } | ||
| 149 | + | ||
| 150 | put_dev_crypto(state->d_fd); | ||
| 151 | state->d_fd = -1; | ||
| 152 | |||
| 153 | -- | ||
| 154 | 2.7.0 | ||
| 155 | |||
diff --git a/recipes-connectivity/openssl/openssl-qoriq/qoriq/0027-cryptodev-put-all-digest-ioctls-into-a-single-functi.patch b/recipes-connectivity/openssl/openssl-qoriq/qoriq/0027-cryptodev-put-all-digest-ioctls-into-a-single-functi.patch new file mode 100644 index 000000000..46b3ced9c --- /dev/null +++ b/recipes-connectivity/openssl/openssl-qoriq/qoriq/0027-cryptodev-put-all-digest-ioctls-into-a-single-functi.patch | |||
| @@ -0,0 +1,108 @@ | |||
| 1 | From 2187b18ffe4851efcb6465ca02ac036d2fe031b8 Mon Sep 17 00:00:00 2001 | ||
| 2 | From: Cristian Stoica <cristian.stoica@nxp.com> | ||
| 3 | Date: Tue, 15 Dec 2015 12:23:13 +0200 | ||
| 4 | Subject: [PATCH 27/48] cryptodev: put all digest ioctls into a single function | ||
| 5 | |||
| 6 | Signed-off-by: Cristian Stoica <cristian.stoica@nxp.com> | ||
| 7 | --- | ||
| 8 | crypto/engine/eng_cryptodev.c | 44 +++++++++++++++++++------------------------ | ||
| 9 | 1 file changed, 19 insertions(+), 25 deletions(-) | ||
| 10 | |||
| 11 | diff --git a/crypto/engine/eng_cryptodev.c b/crypto/engine/eng_cryptodev.c | ||
| 12 | index 048e050..76faa35 100644 | ||
| 13 | --- a/crypto/engine/eng_cryptodev.c | ||
| 14 | +++ b/crypto/engine/eng_cryptodev.c | ||
| 15 | @@ -1577,13 +1577,6 @@ static int cryptodev_digest_init(EVP_MD_CTX *ctx) | ||
| 16 | sess->mackeylen = digest_key_length(ctx->digest->type); | ||
| 17 | sess->mac = digest; | ||
| 18 | |||
| 19 | - if (ioctl(state->d_fd, CIOCGSESSION, sess) < 0) { | ||
| 20 | - put_dev_crypto(state->d_fd); | ||
| 21 | - state->d_fd = -1; | ||
| 22 | - printf("cryptodev_digest_init: Open session failed\n"); | ||
| 23 | - return (0); | ||
| 24 | - } | ||
| 25 | - | ||
| 26 | return (1); | ||
| 27 | } | ||
| 28 | |||
| 29 | @@ -1623,6 +1616,7 @@ static int cryptodev_digest_update(EVP_MD_CTX *ctx, const void *data, | ||
| 30 | |||
| 31 | static int cryptodev_digest_final(EVP_MD_CTX *ctx, unsigned char *md) | ||
| 32 | { | ||
| 33 | + int ret = 1; | ||
| 34 | struct crypt_op cryp; | ||
| 35 | struct dev_crypto_state *state = ctx->md_data; | ||
| 36 | struct session_op *sess = &state->d_sess; | ||
| 37 | @@ -1632,6 +1626,11 @@ static int cryptodev_digest_final(EVP_MD_CTX *ctx, unsigned char *md) | ||
| 38 | return (0); | ||
| 39 | } | ||
| 40 | |||
| 41 | + if (ioctl(state->d_fd, CIOCGSESSION, sess) < 0) { | ||
| 42 | + printf("cryptodev_digest_init: Open session failed\n"); | ||
| 43 | + return (0); | ||
| 44 | + } | ||
| 45 | + | ||
| 46 | memset(&cryp, 0, sizeof(cryp)); | ||
| 47 | |||
| 48 | cryp.ses = sess->ses; | ||
| 49 | @@ -1642,43 +1641,38 @@ static int cryptodev_digest_final(EVP_MD_CTX *ctx, unsigned char *md) | ||
| 50 | |||
| 51 | if (ioctl(state->d_fd, CIOCCRYPT, &cryp) < 0) { | ||
| 52 | printf("cryptodev_digest_final: digest failed\n"); | ||
| 53 | - return (0); | ||
| 54 | + ret = 0; | ||
| 55 | } | ||
| 56 | |||
| 57 | - return (1); | ||
| 58 | + if (ioctl(state->d_fd, CIOCFSESSION, &sess->ses) < 0) { | ||
| 59 | + printf("cryptodev_digest_cleanup: failed to close session\n"); | ||
| 60 | + } | ||
| 61 | + | ||
| 62 | + return ret; | ||
| 63 | } | ||
| 64 | |||
| 65 | static int cryptodev_digest_cleanup(EVP_MD_CTX *ctx) | ||
| 66 | { | ||
| 67 | - int ret = 1; | ||
| 68 | struct dev_crypto_state *state = ctx->md_data; | ||
| 69 | struct session_op *sess = &state->d_sess; | ||
| 70 | |||
| 71 | - if (state == NULL) | ||
| 72 | + if (state == NULL) { | ||
| 73 | return 0; | ||
| 74 | - | ||
| 75 | - if (state->d_fd < 0) { | ||
| 76 | - printf("cryptodev_digest_cleanup: illegal input\n"); | ||
| 77 | - return (0); | ||
| 78 | } | ||
| 79 | |||
| 80 | if (!(ctx->flags & EVP_MD_CTX_FLAG_ONESHOT)) { | ||
| 81 | OPENSSL_free(state->mac_data); | ||
| 82 | } | ||
| 83 | - state->mac_data = NULL; | ||
| 84 | - state->mac_len = 0; | ||
| 85 | |||
| 86 | - if (ioctl(state->d_fd, CIOCFSESSION, &sess->ses) < 0) { | ||
| 87 | - printf("cryptodev_digest_cleanup: failed to close session\n"); | ||
| 88 | - ret = 0; | ||
| 89 | - } else { | ||
| 90 | - ret = 1; | ||
| 91 | + if (state->d_fd >= 0) { | ||
| 92 | + put_dev_crypto(state->d_fd); | ||
| 93 | + state->d_fd = -1; | ||
| 94 | } | ||
| 95 | |||
| 96 | - put_dev_crypto(state->d_fd); | ||
| 97 | - state->d_fd = -1; | ||
| 98 | + state->mac_data = NULL; | ||
| 99 | + state->mac_len = 0; | ||
| 100 | |||
| 101 | - return (ret); | ||
| 102 | + return 1; | ||
| 103 | } | ||
| 104 | |||
| 105 | static int cryptodev_digest_copy(EVP_MD_CTX *to, const EVP_MD_CTX *from) | ||
| 106 | -- | ||
| 107 | 2.7.0 | ||
| 108 | |||
diff --git a/recipes-connectivity/openssl/openssl-qoriq/qoriq/0028-cryptodev-fix-debug-print-messages.patch b/recipes-connectivity/openssl/openssl-qoriq/qoriq/0028-cryptodev-fix-debug-print-messages.patch new file mode 100644 index 000000000..03d1b96a3 --- /dev/null +++ b/recipes-connectivity/openssl/openssl-qoriq/qoriq/0028-cryptodev-fix-debug-print-messages.patch | |||
| @@ -0,0 +1,90 @@ | |||
| 1 | From 3dd41691dc8162ec26d188269934689ad834894c Mon Sep 17 00:00:00 2001 | ||
| 2 | From: Cristian Stoica <cristian.stoica@nxp.com> | ||
| 3 | Date: Tue, 15 Dec 2015 12:51:36 +0200 | ||
| 4 | Subject: [PATCH 28/48] cryptodev: fix debug print messages | ||
| 5 | |||
| 6 | Signed-off-by: Cristian Stoica <cristian.stoica@nxp.com> | ||
| 7 | --- | ||
| 8 | crypto/engine/eng_cryptodev.c | 18 +++++++++--------- | ||
| 9 | 1 file changed, 9 insertions(+), 9 deletions(-) | ||
| 10 | |||
| 11 | diff --git a/crypto/engine/eng_cryptodev.c b/crypto/engine/eng_cryptodev.c | ||
| 12 | index 76faa35..1585009 100644 | ||
| 13 | --- a/crypto/engine/eng_cryptodev.c | ||
| 14 | +++ b/crypto/engine/eng_cryptodev.c | ||
| 15 | @@ -1563,13 +1563,13 @@ static int cryptodev_digest_init(EVP_MD_CTX *ctx) | ||
| 16 | |||
| 17 | digest = digest_nid_to_cryptodev(ctx->digest->type); | ||
| 18 | if (digest == NID_undef) { | ||
| 19 | - printf("cryptodev_digest_init: Can't get digest \n"); | ||
| 20 | + printf("%s: Can't get digest\n", __func__); | ||
| 21 | return (0); | ||
| 22 | } | ||
| 23 | |||
| 24 | state->d_fd = get_dev_crypto(); | ||
| 25 | if (state->d_fd < 0) { | ||
| 26 | - printf("cryptodev_digest_init: Can't get Dev \n"); | ||
| 27 | + printf("%s: Can't get Dev\n", __func__); | ||
| 28 | return (0); | ||
| 29 | } | ||
| 30 | |||
| 31 | @@ -1586,7 +1586,7 @@ static int cryptodev_digest_update(EVP_MD_CTX *ctx, const void *data, | ||
| 32 | struct dev_crypto_state *state = ctx->md_data; | ||
| 33 | |||
| 34 | if (!data || !count) { | ||
| 35 | - printf("cryptodev_digest_update: illegal inputs \n"); | ||
| 36 | + printf("%s: illegal inputs\n", __func__); | ||
| 37 | return 0; | ||
| 38 | } | ||
| 39 | |||
| 40 | @@ -1603,7 +1603,7 @@ static int cryptodev_digest_update(EVP_MD_CTX *ctx, const void *data, | ||
| 41 | state->mac_data = | ||
| 42 | OPENSSL_realloc(state->mac_data, state->mac_len + count); | ||
| 43 | if (!state->mac_data) { | ||
| 44 | - printf("cryptodev_digest_update: realloc failed\n"); | ||
| 45 | + printf("%s: realloc failed\n", __func__); | ||
| 46 | return (0); | ||
| 47 | } | ||
| 48 | |||
| 49 | @@ -1622,12 +1622,12 @@ static int cryptodev_digest_final(EVP_MD_CTX *ctx, unsigned char *md) | ||
| 50 | struct session_op *sess = &state->d_sess; | ||
| 51 | |||
| 52 | if (!md || state->d_fd < 0) { | ||
| 53 | - printf("cryptodev_digest_final: illegal input\n"); | ||
| 54 | + printf("%s: illegal input\n", __func__); | ||
| 55 | return (0); | ||
| 56 | } | ||
| 57 | |||
| 58 | if (ioctl(state->d_fd, CIOCGSESSION, sess) < 0) { | ||
| 59 | - printf("cryptodev_digest_init: Open session failed\n"); | ||
| 60 | + printf("%s: Open session failed\n", __func__); | ||
| 61 | return (0); | ||
| 62 | } | ||
| 63 | |||
| 64 | @@ -1640,12 +1640,12 @@ static int cryptodev_digest_final(EVP_MD_CTX *ctx, unsigned char *md) | ||
| 65 | cryp.mac = md; | ||
| 66 | |||
| 67 | if (ioctl(state->d_fd, CIOCCRYPT, &cryp) < 0) { | ||
| 68 | - printf("cryptodev_digest_final: digest failed\n"); | ||
| 69 | + printf("%s: digest failed\n", __func__); | ||
| 70 | ret = 0; | ||
| 71 | } | ||
| 72 | |||
| 73 | if (ioctl(state->d_fd, CIOCFSESSION, &sess->ses) < 0) { | ||
| 74 | - printf("cryptodev_digest_cleanup: failed to close session\n"); | ||
| 75 | + printf("%s: failed to close session\n", __func__); | ||
| 76 | } | ||
| 77 | |||
| 78 | return ret; | ||
| 79 | @@ -1700,7 +1700,7 @@ static int cryptodev_digest_copy(EVP_MD_CTX *to, const EVP_MD_CTX *from) | ||
| 80 | if (ioctl(dstate->d_fd, CIOCGSESSION, sess) < 0) { | ||
| 81 | put_dev_crypto(dstate->d_fd); | ||
| 82 | dstate->d_fd = -1; | ||
| 83 | - printf("cryptodev_digest_init: Open session failed\n"); | ||
| 84 | + printf("%s: Open session failed\n", __func__); | ||
| 85 | return (0); | ||
| 86 | } | ||
| 87 | |||
| 88 | -- | ||
| 89 | 2.7.0 | ||
| 90 | |||
diff --git a/recipes-connectivity/openssl/openssl-qoriq/qoriq/0029-cryptodev-use-CIOCHASH-ioctl-for-digest-operations.patch b/recipes-connectivity/openssl/openssl-qoriq/qoriq/0029-cryptodev-use-CIOCHASH-ioctl-for-digest-operations.patch new file mode 100644 index 000000000..3dc2b9226 --- /dev/null +++ b/recipes-connectivity/openssl/openssl-qoriq/qoriq/0029-cryptodev-use-CIOCHASH-ioctl-for-digest-operations.patch | |||
| @@ -0,0 +1,91 @@ | |||
| 1 | From 3fe44ab50a87106af3349148e81ec8a1d524de82 Mon Sep 17 00:00:00 2001 | ||
| 2 | From: Cristian Stoica <cristian.stoica@nxp.com> | ||
| 3 | Date: Tue, 15 Dec 2015 15:43:28 +0200 | ||
| 4 | Subject: [PATCH 29/48] cryptodev: use CIOCHASH ioctl for digest operations | ||
| 5 | |||
| 6 | Signed-off-by: Cristian Stoica <cristian.stoica@nxp.com> | ||
| 7 | --- | ||
| 8 | crypto/engine/eng_cryptodev.c | 34 +++++++++++----------------------- | ||
| 9 | 1 file changed, 11 insertions(+), 23 deletions(-) | ||
| 10 | |||
| 11 | diff --git a/crypto/engine/eng_cryptodev.c b/crypto/engine/eng_cryptodev.c | ||
| 12 | index 1585009..dc27b55 100644 | ||
| 13 | --- a/crypto/engine/eng_cryptodev.c | ||
| 14 | +++ b/crypto/engine/eng_cryptodev.c | ||
| 15 | @@ -84,6 +84,7 @@ struct dev_crypto_state { | ||
| 16 | unsigned char *iv; | ||
| 17 | int ivlen; | ||
| 18 | # ifdef USE_CRYPTODEV_DIGESTS | ||
| 19 | + struct hash_op_data hash_op; | ||
| 20 | char dummy_mac_key[HASH_MAX_LEN]; | ||
| 21 | unsigned char digest_res[HASH_MAX_LEN]; | ||
| 22 | char *mac_data; | ||
| 23 | @@ -1556,7 +1557,7 @@ static int digest_key_length(int nid) | ||
| 24 | static int cryptodev_digest_init(EVP_MD_CTX *ctx) | ||
| 25 | { | ||
| 26 | struct dev_crypto_state *state = ctx->md_data; | ||
| 27 | - struct session_op *sess = &state->d_sess; | ||
| 28 | + struct hash_op_data *hash_op = &state->hash_op; | ||
| 29 | int digest; | ||
| 30 | |||
| 31 | memset(state, 0, sizeof(struct dev_crypto_state)); | ||
| 32 | @@ -1573,9 +1574,9 @@ static int cryptodev_digest_init(EVP_MD_CTX *ctx) | ||
| 33 | return (0); | ||
| 34 | } | ||
| 35 | |||
| 36 | - sess->mackey = state->dummy_mac_key; | ||
| 37 | - sess->mackeylen = digest_key_length(ctx->digest->type); | ||
| 38 | - sess->mac = digest; | ||
| 39 | + hash_op->mac_op = digest; | ||
| 40 | + hash_op->mackey = state->dummy_mac_key; | ||
| 41 | + hash_op->mackeylen = digest_key_length(ctx->digest->type); | ||
| 42 | |||
| 43 | return (1); | ||
| 44 | } | ||
| 45 | @@ -1617,37 +1618,24 @@ static int cryptodev_digest_update(EVP_MD_CTX *ctx, const void *data, | ||
| 46 | static int cryptodev_digest_final(EVP_MD_CTX *ctx, unsigned char *md) | ||
| 47 | { | ||
| 48 | int ret = 1; | ||
| 49 | - struct crypt_op cryp; | ||
| 50 | struct dev_crypto_state *state = ctx->md_data; | ||
| 51 | - struct session_op *sess = &state->d_sess; | ||
| 52 | + struct hash_op_data *hash_op = &state->hash_op; | ||
| 53 | |||
| 54 | if (!md || state->d_fd < 0) { | ||
| 55 | printf("%s: illegal input\n", __func__); | ||
| 56 | return (0); | ||
| 57 | } | ||
| 58 | |||
| 59 | - if (ioctl(state->d_fd, CIOCGSESSION, sess) < 0) { | ||
| 60 | - printf("%s: Open session failed\n", __func__); | ||
| 61 | - return (0); | ||
| 62 | - } | ||
| 63 | - | ||
| 64 | - memset(&cryp, 0, sizeof(cryp)); | ||
| 65 | + hash_op->flags = 0; | ||
| 66 | + hash_op->len = state->mac_len; | ||
| 67 | + hash_op->src = state->mac_data; | ||
| 68 | + hash_op->mac_result = md; | ||
| 69 | |||
| 70 | - cryp.ses = sess->ses; | ||
| 71 | - cryp.flags = 0; | ||
| 72 | - cryp.len = state->mac_len; | ||
| 73 | - cryp.src = state->mac_data; | ||
| 74 | - cryp.mac = md; | ||
| 75 | - | ||
| 76 | - if (ioctl(state->d_fd, CIOCCRYPT, &cryp) < 0) { | ||
| 77 | + if (ioctl(state->d_fd, CIOCHASH, hash_op) < 0) { | ||
| 78 | printf("%s: digest failed\n", __func__); | ||
| 79 | ret = 0; | ||
| 80 | } | ||
| 81 | |||
| 82 | - if (ioctl(state->d_fd, CIOCFSESSION, &sess->ses) < 0) { | ||
| 83 | - printf("%s: failed to close session\n", __func__); | ||
| 84 | - } | ||
| 85 | - | ||
| 86 | return ret; | ||
| 87 | } | ||
| 88 | |||
| 89 | -- | ||
| 90 | 2.7.0 | ||
| 91 | |||
diff --git a/recipes-connectivity/openssl/openssl-qoriq/qoriq/0030-cryptodev-reduce-duplicated-efforts-for-searching-in.patch b/recipes-connectivity/openssl/openssl-qoriq/qoriq/0030-cryptodev-reduce-duplicated-efforts-for-searching-in.patch new file mode 100644 index 000000000..995a593f8 --- /dev/null +++ b/recipes-connectivity/openssl/openssl-qoriq/qoriq/0030-cryptodev-reduce-duplicated-efforts-for-searching-in.patch | |||
| @@ -0,0 +1,106 @@ | |||
| 1 | From 12fad710349bb72b7f95ee30b40c2e6dfbb5d373 Mon Sep 17 00:00:00 2001 | ||
| 2 | From: Cristian Stoica <cristian.stoica@nxp.com> | ||
| 3 | Date: Wed, 13 Jan 2016 15:18:20 +0200 | ||
| 4 | Subject: [PATCH 30/48] cryptodev: reduce duplicated efforts for searching | ||
| 5 | inside digests table | ||
| 6 | |||
| 7 | Signed-off-by: Cristian Stoica <cristian.stoica@nxp.com> | ||
| 8 | --- | ||
| 9 | crypto/engine/eng_cryptodev.c | 44 ++++++++++++++++++------------------------- | ||
| 10 | 1 file changed, 18 insertions(+), 26 deletions(-) | ||
| 11 | |||
| 12 | diff --git a/crypto/engine/eng_cryptodev.c b/crypto/engine/eng_cryptodev.c | ||
| 13 | index dc27b55..30713e5 100644 | ||
| 14 | --- a/crypto/engine/eng_cryptodev.c | ||
| 15 | +++ b/crypto/engine/eng_cryptodev.c | ||
| 16 | @@ -1533,37 +1533,31 @@ cryptodev_engine_ciphers(ENGINE *e, const EVP_CIPHER **cipher, | ||
| 17 | |||
| 18 | # ifdef USE_CRYPTODEV_DIGESTS | ||
| 19 | |||
| 20 | -/* convert digest type to cryptodev */ | ||
| 21 | -static int digest_nid_to_cryptodev(int nid) | ||
| 22 | +static int digest_nid_to_id(int nid) | ||
| 23 | { | ||
| 24 | int i; | ||
| 25 | |||
| 26 | - for (i = 0; digests[i].id; i++) | ||
| 27 | - if (digests[i].nid == nid) | ||
| 28 | - return (digests[i].id); | ||
| 29 | - return (0); | ||
| 30 | -} | ||
| 31 | - | ||
| 32 | -static int digest_key_length(int nid) | ||
| 33 | -{ | ||
| 34 | - int i; | ||
| 35 | - | ||
| 36 | - for (i = 0; digests[i].id; i++) | ||
| 37 | - if (digests[i].nid == nid) | ||
| 38 | - return digests[i].keylen; | ||
| 39 | - return (0); | ||
| 40 | + for (i = 0;; i++) { | ||
| 41 | + if ((digests[i].nid == nid) || (digests[i].id == 0)) { | ||
| 42 | + break; | ||
| 43 | + } | ||
| 44 | + } | ||
| 45 | + return i; | ||
| 46 | } | ||
| 47 | |||
| 48 | static int cryptodev_digest_init(EVP_MD_CTX *ctx) | ||
| 49 | { | ||
| 50 | struct dev_crypto_state *state = ctx->md_data; | ||
| 51 | struct hash_op_data *hash_op = &state->hash_op; | ||
| 52 | - int digest; | ||
| 53 | + int id; | ||
| 54 | |||
| 55 | memset(state, 0, sizeof(struct dev_crypto_state)); | ||
| 56 | |||
| 57 | - digest = digest_nid_to_cryptodev(ctx->digest->type); | ||
| 58 | - if (digest == NID_undef) { | ||
| 59 | + id = digest_nid_to_id(ctx->digest->type); | ||
| 60 | + | ||
| 61 | + hash_op->mac_op = digests[id].id; | ||
| 62 | + hash_op->mackeylen = digests[id].keylen; | ||
| 63 | + if (hash_op->mac_op == 0) { | ||
| 64 | printf("%s: Can't get digest\n", __func__); | ||
| 65 | return (0); | ||
| 66 | } | ||
| 67 | @@ -1574,11 +1568,9 @@ static int cryptodev_digest_init(EVP_MD_CTX *ctx) | ||
| 68 | return (0); | ||
| 69 | } | ||
| 70 | |||
| 71 | - hash_op->mac_op = digest; | ||
| 72 | hash_op->mackey = state->dummy_mac_key; | ||
| 73 | - hash_op->mackeylen = digest_key_length(ctx->digest->type); | ||
| 74 | |||
| 75 | - return (1); | ||
| 76 | + return 1; | ||
| 77 | } | ||
| 78 | |||
| 79 | static int cryptodev_digest_update(EVP_MD_CTX *ctx, const void *data, | ||
| 80 | @@ -1668,7 +1660,7 @@ static int cryptodev_digest_copy(EVP_MD_CTX *to, const EVP_MD_CTX *from) | ||
| 81 | struct dev_crypto_state *fstate = from->md_data; | ||
| 82 | struct dev_crypto_state *dstate = to->md_data; | ||
| 83 | struct session_op *sess; | ||
| 84 | - int digest; | ||
| 85 | + int id; | ||
| 86 | |||
| 87 | if (dstate == NULL || fstate == NULL) | ||
| 88 | return 1; | ||
| 89 | @@ -1677,11 +1669,11 @@ static int cryptodev_digest_copy(EVP_MD_CTX *to, const EVP_MD_CTX *from) | ||
| 90 | |||
| 91 | sess = &dstate->d_sess; | ||
| 92 | |||
| 93 | - digest = digest_nid_to_cryptodev(to->digest->type); | ||
| 94 | + id = digest_nid_to_id(to->digest->type); | ||
| 95 | |||
| 96 | sess->mackey = dstate->dummy_mac_key; | ||
| 97 | - sess->mackeylen = digest_key_length(to->digest->type); | ||
| 98 | - sess->mac = digest; | ||
| 99 | + sess->mackeylen = digests[id].keylen; | ||
| 100 | + sess->mac = digests[id].id; | ||
| 101 | |||
| 102 | dstate->d_fd = get_dev_crypto(); | ||
| 103 | |||
| 104 | -- | ||
| 105 | 2.7.0 | ||
| 106 | |||
diff --git a/recipes-connectivity/openssl/openssl-qoriq/qoriq/0031-cryptodev-remove-not-used-local-variables.patch b/recipes-connectivity/openssl/openssl-qoriq/qoriq/0031-cryptodev-remove-not-used-local-variables.patch new file mode 100644 index 000000000..fc23e0c1b --- /dev/null +++ b/recipes-connectivity/openssl/openssl-qoriq/qoriq/0031-cryptodev-remove-not-used-local-variables.patch | |||
| @@ -0,0 +1,46 @@ | |||
| 1 | From 8cd09ffdfd7d9c25605401f1c0947b1b4acc6e57 Mon Sep 17 00:00:00 2001 | ||
| 2 | From: Cristian Stoica <cristian.stoica@nxp.com> | ||
| 3 | Date: Mon, 8 Feb 2016 16:00:22 +0200 | ||
| 4 | Subject: [PATCH 31/48] cryptodev: remove not used local variables | ||
| 5 | |||
| 6 | Signed-off-by: Cristian Stoica <cristian.stoica@nxp.com> | ||
| 7 | --- | ||
| 8 | crypto/engine/eng_cryptodev.c | 6 +----- | ||
| 9 | 1 file changed, 1 insertion(+), 5 deletions(-) | ||
| 10 | |||
| 11 | diff --git a/crypto/engine/eng_cryptodev.c b/crypto/engine/eng_cryptodev.c | ||
| 12 | index 30713e5..2734500 100644 | ||
| 13 | --- a/crypto/engine/eng_cryptodev.c | ||
| 14 | +++ b/crypto/engine/eng_cryptodev.c | ||
| 15 | @@ -1634,7 +1634,6 @@ static int cryptodev_digest_final(EVP_MD_CTX *ctx, unsigned char *md) | ||
| 16 | static int cryptodev_digest_cleanup(EVP_MD_CTX *ctx) | ||
| 17 | { | ||
| 18 | struct dev_crypto_state *state = ctx->md_data; | ||
| 19 | - struct session_op *sess = &state->d_sess; | ||
| 20 | |||
| 21 | if (state == NULL) { | ||
| 22 | return 0; | ||
| 23 | @@ -3939,7 +3938,6 @@ static int cryptodev_dh_keygen(DH *dh) | ||
| 24 | int ret = 1, q_len = 0; | ||
| 25 | unsigned char *q = NULL, *g = NULL, *s = NULL, *w = NULL; | ||
| 26 | BIGNUM *pub_key = NULL, *priv_key = NULL; | ||
| 27 | - int generate_new_key = 1; | ||
| 28 | |||
| 29 | if (dh->priv_key) | ||
| 30 | priv_key = dh->priv_key; | ||
| 31 | @@ -4061,11 +4059,9 @@ cryptodev_dh_compute_key_async(unsigned char *key, const BIGNUM *pub_key, | ||
| 32 | { | ||
| 33 | struct crypt_kop *kop = malloc(sizeof(struct crypt_kop)); | ||
| 34 | int ret = 1; | ||
| 35 | - int fd, p_len; | ||
| 36 | + int p_len; | ||
| 37 | unsigned char *padded_pub_key = NULL, *p = NULL; | ||
| 38 | |||
| 39 | - fd = *(int *)cookie->eng_handle; | ||
| 40 | - | ||
| 41 | memset(kop, 0, sizeof(struct crypt_kop)); | ||
| 42 | kop->crk_op = CRK_DH_COMPUTE_KEY; | ||
| 43 | /* inputs: dh->priv_key pub_key dh->p key */ | ||
| 44 | -- | ||
| 45 | 2.7.0 | ||
| 46 | |||
diff --git a/recipes-connectivity/openssl/openssl-qoriq/qoriq/0032-cryptodev-hide-not-used-variable-behind-ifndef.patch b/recipes-connectivity/openssl/openssl-qoriq/qoriq/0032-cryptodev-hide-not-used-variable-behind-ifndef.patch new file mode 100644 index 000000000..9ff4d361a --- /dev/null +++ b/recipes-connectivity/openssl/openssl-qoriq/qoriq/0032-cryptodev-hide-not-used-variable-behind-ifndef.patch | |||
| @@ -0,0 +1,27 @@ | |||
| 1 | From 335c80f847eacc573e10ba925b6a645963b16197 Mon Sep 17 00:00:00 2001 | ||
| 2 | From: Cristian Stoica <cristian.stoica@nxp.com> | ||
| 3 | Date: Mon, 8 Feb 2016 17:22:49 +0200 | ||
| 4 | Subject: [PATCH 32/48] cryptodev: hide not used variable behind #ifndef | ||
| 5 | |||
| 6 | Signed-off-by: Cristian Stoica <cristian.stoica@nxp.com> | ||
| 7 | --- | ||
| 8 | crypto/engine/eng_cryptodev.c | 2 ++ | ||
| 9 | 1 file changed, 2 insertions(+) | ||
| 10 | |||
| 11 | diff --git a/crypto/engine/eng_cryptodev.c b/crypto/engine/eng_cryptodev.c | ||
| 12 | index 2734500..5a68c76 100644 | ||
| 13 | --- a/crypto/engine/eng_cryptodev.c | ||
| 14 | +++ b/crypto/engine/eng_cryptodev.c | ||
| 15 | @@ -412,7 +412,9 @@ static int open_dev_crypto(void) | ||
| 16 | static int get_dev_crypto(void) | ||
| 17 | { | ||
| 18 | static int fd = -1; | ||
| 19 | +# ifndef CRIOGET_NOT_NEEDED | ||
| 20 | int retfd; | ||
| 21 | +# endif | ||
| 22 | |||
| 23 | if (fd == -1) | ||
| 24 | fd = open_dev_crypto(); | ||
| 25 | -- | ||
| 26 | 2.7.0 | ||
| 27 | |||
diff --git a/recipes-connectivity/openssl/openssl-qoriq/qoriq/0033-cryptodev-fix-function-declaration-typo.patch b/recipes-connectivity/openssl/openssl-qoriq/qoriq/0033-cryptodev-fix-function-declaration-typo.patch new file mode 100644 index 000000000..82ccebad5 --- /dev/null +++ b/recipes-connectivity/openssl/openssl-qoriq/qoriq/0033-cryptodev-fix-function-declaration-typo.patch | |||
| @@ -0,0 +1,26 @@ | |||
| 1 | From 03bdddf1495707119e4fa0eda385ecdccf66cbd8 Mon Sep 17 00:00:00 2001 | ||
| 2 | From: Cristian Stoica <cristian.stoica@nxp.com> | ||
| 3 | Date: Mon, 8 Feb 2016 16:08:25 +0200 | ||
| 4 | Subject: [PATCH 33/48] cryptodev: fix function declaration typo | ||
| 5 | |||
| 6 | Signed-off-by: Cristian Stoica <cristian.stoica@nxp.com> | ||
| 7 | --- | ||
| 8 | crypto/engine/engine.h | 2 +- | ||
| 9 | 1 file changed, 1 insertion(+), 1 deletion(-) | ||
| 10 | |||
| 11 | diff --git a/crypto/engine/engine.h b/crypto/engine/engine.h | ||
| 12 | index f83ee73..c8efbe1 100644 | ||
| 13 | --- a/crypto/engine/engine.h | ||
| 14 | +++ b/crypto/engine/engine.h | ||
| 15 | @@ -569,7 +569,7 @@ void ENGINE_set_async_map(ENGINE *e, int async_map); | ||
| 16 | int ENGINE_get_async_map(ENGINE *e); | ||
| 17 | int ENGINE_open_instance(ENGINE *e); | ||
| 18 | int ENGINE_close_instance(ENGINE *e, int fd); | ||
| 19 | -void ENGINE_set_init_instance(ENGINE *e, int(*engine_init_instance)(void)); | ||
| 20 | +void ENGINE_set_open_instance(ENGINE *e, int(*engine_open_instance)(void)); | ||
| 21 | void ENGINE_set_close_instance(ENGINE *e, int(*engine_close_instance)(int)); | ||
| 22 | void ENGINE_set_check_pkc_availability(ENGINE *e, | ||
| 23 | int (*check_pkc_availability)(int fd)); | ||
| 24 | -- | ||
| 25 | 2.7.0 | ||
| 26 | |||
diff --git a/recipes-connectivity/openssl/openssl-qoriq/qoriq/0034-cryptodev-fix-incorrect-function-signature.patch b/recipes-connectivity/openssl/openssl-qoriq/qoriq/0034-cryptodev-fix-incorrect-function-signature.patch new file mode 100644 index 000000000..84268c580 --- /dev/null +++ b/recipes-connectivity/openssl/openssl-qoriq/qoriq/0034-cryptodev-fix-incorrect-function-signature.patch | |||
| @@ -0,0 +1,26 @@ | |||
| 1 | From 7012cf33a00618749319b1903f48ee3a35f5887b Mon Sep 17 00:00:00 2001 | ||
| 2 | From: Cristian Stoica <cristian.stoica@nxp.com> | ||
| 3 | Date: Mon, 8 Feb 2016 16:12:54 +0200 | ||
| 4 | Subject: [PATCH 34/48] cryptodev: fix incorrect function signature | ||
| 5 | |||
| 6 | Signed-off-by: Cristian Stoica <cristian.stoica@nxp.com> | ||
| 7 | --- | ||
| 8 | crypto/engine/eng_cryptodev.c | 2 +- | ||
| 9 | 1 file changed, 1 insertion(+), 1 deletion(-) | ||
| 10 | |||
| 11 | diff --git a/crypto/engine/eng_cryptodev.c b/crypto/engine/eng_cryptodev.c | ||
| 12 | index 5a68c76..cec6938 100644 | ||
| 13 | --- a/crypto/engine/eng_cryptodev.c | ||
| 14 | +++ b/crypto/engine/eng_cryptodev.c | ||
| 15 | @@ -3148,7 +3148,7 @@ static ECDSA_SIG *cryptodev_ecdsa_do_sign(const unsigned char *dgst, | ||
| 16 | } | ||
| 17 | |||
| 18 | static int cryptodev_ecdsa_verify(const unsigned char *dgst, int dgst_len, | ||
| 19 | - ECDSA_SIG *sig, EC_KEY *eckey) | ||
| 20 | + const ECDSA_SIG *sig, EC_KEY *eckey) | ||
| 21 | { | ||
| 22 | BIGNUM *m = NULL, *p = NULL, *a = NULL, *b = NULL; | ||
| 23 | BIGNUM *x = NULL, *y = NULL, *w_x = NULL, *w_y = NULL; | ||
| 24 | -- | ||
| 25 | 2.7.0 | ||
| 26 | |||
diff --git a/recipes-connectivity/openssl/openssl-qoriq/qoriq/0035-cryptodev-fix-warnings-on-excess-elements-in-struct-.patch b/recipes-connectivity/openssl/openssl-qoriq/qoriq/0035-cryptodev-fix-warnings-on-excess-elements-in-struct-.patch new file mode 100644 index 000000000..0e90d82bd --- /dev/null +++ b/recipes-connectivity/openssl/openssl-qoriq/qoriq/0035-cryptodev-fix-warnings-on-excess-elements-in-struct-.patch | |||
| @@ -0,0 +1,110 @@ | |||
| 1 | From 82612e3c4161ed6e10379841b953a0f56e557be4 Mon Sep 17 00:00:00 2001 | ||
| 2 | From: Cristian Stoica <cristian.stoica@nxp.com> | ||
| 3 | Date: Mon, 8 Feb 2016 16:21:46 +0200 | ||
| 4 | Subject: [PATCH 35/48] cryptodev: fix warnings on excess elements in struct | ||
| 5 | initializer | ||
| 6 | |||
| 7 | The initialization data for these structures had either missing or excess | ||
| 8 | values and did not match the structure definitions. | ||
| 9 | |||
| 10 | Signed-off-by: Cristian Stoica <cristian.stoica@nxp.com> | ||
| 11 | --- | ||
| 12 | crypto/dh/dh.h | 6 +++--- | ||
| 13 | crypto/dsa/dsa.h | 11 ++++++----- | ||
| 14 | crypto/engine/eng_cryptodev.c | 11 ++++++----- | ||
| 15 | 3 files changed, 15 insertions(+), 13 deletions(-) | ||
| 16 | |||
| 17 | diff --git a/crypto/dh/dh.h b/crypto/dh/dh.h | ||
| 18 | index 31dd762..11c6c7d 100644 | ||
| 19 | --- a/crypto/dh/dh.h | ||
| 20 | +++ b/crypto/dh/dh.h | ||
| 21 | @@ -123,9 +123,9 @@ struct dh_method { | ||
| 22 | int (*bn_mod_exp) (const DH *dh, BIGNUM *r, const BIGNUM *a, | ||
| 23 | const BIGNUM *p, const BIGNUM *m, BN_CTX *ctx, | ||
| 24 | BN_MONT_CTX *m_ctx); | ||
| 25 | - int (*compute_key_async)(unsigned char *key,const BIGNUM *pub_key,DH *dh, | ||
| 26 | - struct pkc_cookie_s *cookie); | ||
| 27 | - int (*generate_key_async)(DH *dh, struct pkc_cookie_s *cookie); | ||
| 28 | + int (*compute_key_async) (unsigned char *key, const BIGNUM *pub_key, | ||
| 29 | + DH *dh, struct pkc_cookie_s * cookie); | ||
| 30 | + int (*generate_key_async) (DH *dh, struct pkc_cookie_s * cookie); | ||
| 31 | int (*init) (DH *dh); | ||
| 32 | int (*finish) (DH *dh); | ||
| 33 | int flags; | ||
| 34 | diff --git a/crypto/dsa/dsa.h b/crypto/dsa/dsa.h | ||
| 35 | index 8584731..ab52add 100644 | ||
| 36 | --- a/crypto/dsa/dsa.h | ||
| 37 | +++ b/crypto/dsa/dsa.h | ||
| 38 | @@ -139,10 +139,11 @@ struct dsa_method { | ||
| 39 | /* Can be null */ | ||
| 40 | int (*bn_mod_exp) (DSA *dsa, BIGNUM *r, BIGNUM *a, const BIGNUM *p, | ||
| 41 | const BIGNUM *m, BN_CTX *ctx, BN_MONT_CTX *m_ctx); | ||
| 42 | - int (*dsa_do_sign_async)(const unsigned char *dgst, int dlen, DSA *dsa, | ||
| 43 | - DSA_SIG *sig, struct pkc_cookie_s *cookie); | ||
| 44 | - int (*dsa_do_verify_async)(const unsigned char *dgst, int dgst_len, | ||
| 45 | - DSA_SIG *sig, DSA *dsa, struct pkc_cookie_s *cookie); | ||
| 46 | + int (*dsa_do_sign_async) (const unsigned char *dgst, int dlen, DSA *dsa, | ||
| 47 | + DSA_SIG *sig, struct pkc_cookie_s * cookie); | ||
| 48 | + int (*dsa_do_verify_async) (const unsigned char *dgst, int dgst_len, | ||
| 49 | + DSA_SIG *sig, DSA *dsa, | ||
| 50 | + struct pkc_cookie_s * cookie); | ||
| 51 | int (*init) (DSA *dsa); | ||
| 52 | int (*finish) (DSA *dsa); | ||
| 53 | int flags; | ||
| 54 | @@ -154,7 +155,7 @@ struct dsa_method { | ||
| 55 | BN_GENCB *cb); | ||
| 56 | /* If this is non-NULL, it is used to generate DSA keys */ | ||
| 57 | int (*dsa_keygen) (DSA *dsa); | ||
| 58 | - int (*dsa_keygen_async)(DSA *dsa, struct pkc_cookie_s *cookie); | ||
| 59 | + int (*dsa_keygen_async) (DSA *dsa, struct pkc_cookie_s * cookie); | ||
| 60 | }; | ||
| 61 | |||
| 62 | struct dsa_st { | ||
| 63 | diff --git a/crypto/engine/eng_cryptodev.c b/crypto/engine/eng_cryptodev.c | ||
| 64 | index cec6938..407ea62 100644 | ||
| 65 | --- a/crypto/engine/eng_cryptodev.c | ||
| 66 | +++ b/crypto/engine/eng_cryptodev.c | ||
| 67 | @@ -2892,11 +2892,13 @@ static DSA_METHOD cryptodev_dsa = { | ||
| 68 | NULL, | ||
| 69 | NULL, | ||
| 70 | NULL, | ||
| 71 | - NULL, | ||
| 72 | NULL, /* init */ | ||
| 73 | NULL, /* finish */ | ||
| 74 | 0, /* flags */ | ||
| 75 | - NULL /* app_data */ | ||
| 76 | + NULL, /* app_data */ | ||
| 77 | + NULL, | ||
| 78 | + NULL, | ||
| 79 | + NULL | ||
| 80 | }; | ||
| 81 | |||
| 82 | static ECDSA_METHOD cryptodev_ecdsa = { | ||
| 83 | @@ -2906,7 +2908,6 @@ static ECDSA_METHOD cryptodev_ecdsa = { | ||
| 84 | NULL, | ||
| 85 | NULL, | ||
| 86 | NULL, | ||
| 87 | - NULL, | ||
| 88 | 0, /* flags */ | ||
| 89 | NULL /* app_data */ | ||
| 90 | }; | ||
| 91 | @@ -4483,14 +4484,14 @@ static DH_METHOD cryptodev_dh = { | ||
| 92 | NULL, | ||
| 93 | NULL, | ||
| 94 | 0, /* flags */ | ||
| 95 | - NULL /* app_data */ | ||
| 96 | + NULL, /* app_data */ | ||
| 97 | + NULL, /* generate_params */ | ||
| 98 | }; | ||
| 99 | |||
| 100 | static ECDH_METHOD cryptodev_ecdh = { | ||
| 101 | "cryptodev ECDH method", | ||
| 102 | NULL, /* cryptodev_ecdh_compute_key */ | ||
| 103 | NULL, | ||
| 104 | - NULL, | ||
| 105 | 0, /* flags */ | ||
| 106 | NULL /* app_data */ | ||
| 107 | }; | ||
| 108 | -- | ||
| 109 | 2.7.0 | ||
| 110 | |||
diff --git a/recipes-connectivity/openssl/openssl-qoriq/qoriq/0036-cryptodev-fix-free-on-error-path.patch b/recipes-connectivity/openssl/openssl-qoriq/qoriq/0036-cryptodev-fix-free-on-error-path.patch new file mode 100644 index 000000000..94b9f0f69 --- /dev/null +++ b/recipes-connectivity/openssl/openssl-qoriq/qoriq/0036-cryptodev-fix-free-on-error-path.patch | |||
| @@ -0,0 +1,46 @@ | |||
| 1 | From 8ccc9b12954b7eb299020a1b15d9d1e5735779df Mon Sep 17 00:00:00 2001 | ||
| 2 | From: Cristian Stoica <cristian.stoica@nxp.com> | ||
| 3 | Date: Mon, 8 Feb 2016 16:36:33 +0200 | ||
| 4 | Subject: [PATCH 36/48] cryptodev: fix free on error path | ||
| 5 | |||
| 6 | This was most likely a typo that escaped code review | ||
| 7 | |||
| 8 | Signed-off-by: Cristian Stoica <cristian.stoica@nxp.com> | ||
| 9 | --- | ||
| 10 | crypto/ecdsa/ecs_locl.h | 4 ++-- | ||
| 11 | crypto/engine/eng_cryptodev.c | 2 +- | ||
| 12 | 2 files changed, 3 insertions(+), 3 deletions(-) | ||
| 13 | |||
| 14 | diff --git a/crypto/ecdsa/ecs_locl.h b/crypto/ecdsa/ecs_locl.h | ||
| 15 | index 9b28c04..c3843c6 100644 | ||
| 16 | --- a/crypto/ecdsa/ecs_locl.h | ||
| 17 | +++ b/crypto/ecdsa/ecs_locl.h | ||
| 18 | @@ -74,10 +74,10 @@ struct ecdsa_method { | ||
| 19 | BIGNUM **r); | ||
| 20 | int (*ecdsa_do_verify) (const unsigned char *dgst, int dgst_len, | ||
| 21 | const ECDSA_SIG *sig, EC_KEY *eckey); | ||
| 22 | - int (*ecdsa_do_sign_async)(const unsigned char *dgst, int dgst_len, | ||
| 23 | + int (*ecdsa_do_sign_async)(const unsigned char *dgst, int dgst_len, | ||
| 24 | const BIGNUM *inv, const BIGNUM *rp, EC_KEY *eckey, | ||
| 25 | ECDSA_SIG *sig, struct pkc_cookie_s *cookie); | ||
| 26 | - int (*ecdsa_do_verify_async)(const unsigned char *dgst, int dgst_len, | ||
| 27 | + int (*ecdsa_do_verify_async)(const unsigned char *dgst, int dgst_len, | ||
| 28 | const ECDSA_SIG *sig, EC_KEY *eckey, struct pkc_cookie_s *cookie); | ||
| 29 | # if 0 | ||
| 30 | int (*init) (EC_KEY *eckey); | ||
| 31 | diff --git a/crypto/engine/eng_cryptodev.c b/crypto/engine/eng_cryptodev.c | ||
| 32 | index 407ea62..1b1fdc7 100644 | ||
| 33 | --- a/crypto/engine/eng_cryptodev.c | ||
| 34 | +++ b/crypto/engine/eng_cryptodev.c | ||
| 35 | @@ -3424,7 +3424,7 @@ static int cryptodev_ecdsa_do_sign_async(const unsigned char *dgst, | ||
| 36 | if (!(sig->r = BN_new()) || !kop) | ||
| 37 | goto err; | ||
| 38 | if ((sig->s = BN_new()) == NULL) { | ||
| 39 | - BN_free(r); | ||
| 40 | + BN_free(sig->r); | ||
| 41 | goto err; | ||
| 42 | } | ||
| 43 | |||
| 44 | -- | ||
| 45 | 2.7.0 | ||
| 46 | |||
diff --git a/recipes-connectivity/openssl/openssl-qoriq/qoriq/0037-cryptodev-fix-return-value-on-error.patch b/recipes-connectivity/openssl/openssl-qoriq/qoriq/0037-cryptodev-fix-return-value-on-error.patch new file mode 100644 index 000000000..2e9567b3e --- /dev/null +++ b/recipes-connectivity/openssl/openssl-qoriq/qoriq/0037-cryptodev-fix-return-value-on-error.patch | |||
| @@ -0,0 +1,28 @@ | |||
| 1 | From b3d3b86063e65b84ce53f4653295e3f6a83d5794 Mon Sep 17 00:00:00 2001 | ||
| 2 | From: Cristian Stoica <cristian.stoica@nxp.com> | ||
| 3 | Date: Mon, 8 Feb 2016 16:55:32 +0200 | ||
| 4 | Subject: [PATCH 37/48] cryptodev: fix return value on error | ||
| 5 | |||
| 6 | Even though we're on error path, the operation is taken care of on | ||
| 7 | software; return success (ret is 1) | ||
| 8 | |||
| 9 | Signed-off-by: Cristian Stoica <cristian.stoica@nxp.com> | ||
| 10 | --- | ||
| 11 | crypto/engine/eng_cryptodev.c | 1 - | ||
| 12 | 1 file changed, 1 deletion(-) | ||
| 13 | |||
| 14 | diff --git a/crypto/engine/eng_cryptodev.c b/crypto/engine/eng_cryptodev.c | ||
| 15 | index 1b1fdc7..8cd3aa3 100644 | ||
| 16 | --- a/crypto/engine/eng_cryptodev.c | ||
| 17 | +++ b/crypto/engine/eng_cryptodev.c | ||
| 18 | @@ -2755,7 +2755,6 @@ cryptodev_dsa_do_sign_async(const unsigned char *dgst, int dlen, DSA *dsa, | ||
| 19 | sig->s = dsaret->s; | ||
| 20 | /* Call user callback immediately */ | ||
| 21 | cookie->pkc_callback(cookie, 0); | ||
| 22 | - ret = dsaret; | ||
| 23 | } | ||
| 24 | return ret; | ||
| 25 | } | ||
| 26 | -- | ||
| 27 | 2.7.0 | ||
| 28 | |||
diff --git a/recipes-connectivity/openssl/openssl-qoriq/qoriq/0038-cryptodev-match-types-with-cryptodev.h.patch b/recipes-connectivity/openssl/openssl-qoriq/qoriq/0038-cryptodev-match-types-with-cryptodev.h.patch new file mode 100644 index 000000000..6e083bad9 --- /dev/null +++ b/recipes-connectivity/openssl/openssl-qoriq/qoriq/0038-cryptodev-match-types-with-cryptodev.h.patch | |||
| @@ -0,0 +1,29 @@ | |||
| 1 | From dcc3254b6dbb8627dd710fa58585542b98c80394 Mon Sep 17 00:00:00 2001 | ||
| 2 | From: Cristian Stoica <cristian.stoica@nxp.com> | ||
| 3 | Date: Mon, 8 Feb 2016 17:11:43 +0200 | ||
| 4 | Subject: [PATCH 38/48] cryptodev: match types with cryptodev.h | ||
| 5 | |||
| 6 | Signed-off-by: Cristian Stoica <cristian.stoica@nxp.com> | ||
| 7 | --- | ||
| 8 | crypto/engine/eng_cryptodev.c | 4 ++-- | ||
| 9 | 1 file changed, 2 insertions(+), 2 deletions(-) | ||
| 10 | |||
| 11 | diff --git a/crypto/engine/eng_cryptodev.c b/crypto/engine/eng_cryptodev.c | ||
| 12 | index 8cd3aa3..4613d2d 100644 | ||
| 13 | --- a/crypto/engine/eng_cryptodev.c | ||
| 14 | +++ b/crypto/engine/eng_cryptodev.c | ||
| 15 | @@ -85,9 +85,9 @@ struct dev_crypto_state { | ||
| 16 | int ivlen; | ||
| 17 | # ifdef USE_CRYPTODEV_DIGESTS | ||
| 18 | struct hash_op_data hash_op; | ||
| 19 | - char dummy_mac_key[HASH_MAX_LEN]; | ||
| 20 | + unsigned char dummy_mac_key[HASH_MAX_LEN]; | ||
| 21 | unsigned char digest_res[HASH_MAX_LEN]; | ||
| 22 | - char *mac_data; | ||
| 23 | + unsigned char *mac_data; | ||
| 24 | int mac_len; | ||
| 25 | # endif | ||
| 26 | }; | ||
| 27 | -- | ||
| 28 | 2.7.0 | ||
| 29 | |||
diff --git a/recipes-connectivity/openssl/openssl-qoriq/qoriq/0039-cryptodev-explicitly-discard-const-qualifier.patch b/recipes-connectivity/openssl/openssl-qoriq/qoriq/0039-cryptodev-explicitly-discard-const-qualifier.patch new file mode 100644 index 000000000..916c47e9d --- /dev/null +++ b/recipes-connectivity/openssl/openssl-qoriq/qoriq/0039-cryptodev-explicitly-discard-const-qualifier.patch | |||
| @@ -0,0 +1,30 @@ | |||
| 1 | From 605210c8ae9241cad6c4ec071f5193bf3e83b2d4 Mon Sep 17 00:00:00 2001 | ||
| 2 | From: Cristian Stoica <cristian.stoica@nxp.com> | ||
| 3 | Date: Mon, 8 Feb 2016 17:15:25 +0200 | ||
| 4 | Subject: [PATCH 39/48] cryptodev: explicitly discard const qualifier | ||
| 5 | |||
| 6 | The const qualifier is discarded by the assignment as a result of how | ||
| 7 | the variables are defined. This patch drops the const qualifier | ||
| 8 | explicitly to avoid build errors. | ||
| 9 | |||
| 10 | Signed-off-by: Cristian Stoica <cristian.stoica@nxp.com> | ||
| 11 | --- | ||
| 12 | crypto/engine/eng_cryptodev.c | 2 +- | ||
| 13 | 1 file changed, 1 insertion(+), 1 deletion(-) | ||
| 14 | |||
| 15 | diff --git a/crypto/engine/eng_cryptodev.c b/crypto/engine/eng_cryptodev.c | ||
| 16 | index 4613d2d..2791ca3 100644 | ||
| 17 | --- a/crypto/engine/eng_cryptodev.c | ||
| 18 | +++ b/crypto/engine/eng_cryptodev.c | ||
| 19 | @@ -1592,7 +1592,7 @@ static int cryptodev_digest_update(EVP_MD_CTX *ctx, const void *data, | ||
| 20 | * cryptodev calls and accumulating small amounts of data | ||
| 21 | */ | ||
| 22 | if (ctx->flags & EVP_MD_CTX_FLAG_ONESHOT) { | ||
| 23 | - state->mac_data = data; | ||
| 24 | + state->mac_data = (void *)data; | ||
| 25 | state->mac_len = count; | ||
| 26 | } else { | ||
| 27 | state->mac_data = | ||
| 28 | -- | ||
| 29 | 2.7.0 | ||
| 30 | |||
diff --git a/recipes-connectivity/openssl/openssl-qoriq/qoriq/0040-cryptodev-replace-caddr_t-with-void.patch b/recipes-connectivity/openssl/openssl-qoriq/qoriq/0040-cryptodev-replace-caddr_t-with-void.patch new file mode 100644 index 000000000..2c61d9b88 --- /dev/null +++ b/recipes-connectivity/openssl/openssl-qoriq/qoriq/0040-cryptodev-replace-caddr_t-with-void.patch | |||
| @@ -0,0 +1,95 @@ | |||
| 1 | From 45429e5ea075867f9219a6fcb233677d062a4451 Mon Sep 17 00:00:00 2001 | ||
| 2 | From: Cristian Stoica <cristian.stoica@nxp.com> | ||
| 3 | Date: Tue, 9 Feb 2016 11:28:23 +0200 | ||
| 4 | Subject: [PATCH 40/48] cryptodev: replace caddr_t with void * | ||
| 5 | |||
| 6 | This avoids warnings such as "pointer targets in assignment differ in | ||
| 7 | signedness" when compiling the code | ||
| 8 | |||
| 9 | Signed-off-by: Cristian Stoica <cristian.stoica@nxp.com> | ||
| 10 | --- | ||
| 11 | crypto/engine/eng_cryptodev.c | 22 +++++++++++----------- | ||
| 12 | 1 file changed, 11 insertions(+), 11 deletions(-) | ||
| 13 | |||
| 14 | diff --git a/crypto/engine/eng_cryptodev.c b/crypto/engine/eng_cryptodev.c | ||
| 15 | index 2791ca3..f172173 100644 | ||
| 16 | --- a/crypto/engine/eng_cryptodev.c | ||
| 17 | +++ b/crypto/engine/eng_cryptodev.c | ||
| 18 | @@ -460,8 +460,8 @@ static int get_cryptodev_ciphers(const int **cnids) | ||
| 19 | return (0); | ||
| 20 | } | ||
| 21 | memset(&sess, 0, sizeof(sess)); | ||
| 22 | - sess.key = (caddr_t) "123456789abcdefghijklmno"; | ||
| 23 | - sess.mackey = (caddr_t) "123456789ABCDEFGHIJKLMNO"; | ||
| 24 | + sess.key = (void *)"123456789abcdefghijklmno"; | ||
| 25 | + sess.mackey = (void *)"123456789ABCDEFGHIJKLMNO"; | ||
| 26 | |||
| 27 | for (i = 0; ciphers[i].id && count < CRYPTO_ALGORITHM_MAX; i++) { | ||
| 28 | if (ciphers[i].nid == NID_undef) | ||
| 29 | @@ -501,7 +501,7 @@ static int get_cryptodev_digests(const int **cnids) | ||
| 30 | return (0); | ||
| 31 | } | ||
| 32 | memset(&sess, 0, sizeof(sess)); | ||
| 33 | - sess.mackey = (caddr_t) "123456789abcdefghijklmno"; | ||
| 34 | + sess.mackey = (void *)"123456789abcdefghijklmno"; | ||
| 35 | for (i = 0; digests[i].id && count < CRYPTO_ALGORITHM_MAX; i++) { | ||
| 36 | if (digests[i].nid == NID_undef) | ||
| 37 | continue; | ||
| 38 | @@ -633,14 +633,14 @@ cryptodev_cipher(EVP_CIPHER_CTX *ctx, unsigned char *out, | ||
| 39 | cryp.ses = sess->ses; | ||
| 40 | cryp.flags = 0; | ||
| 41 | cryp.len = inl; | ||
| 42 | - cryp.src = (caddr_t) in; | ||
| 43 | - cryp.dst = (caddr_t) out; | ||
| 44 | + cryp.src = (void *)in; | ||
| 45 | + cryp.dst = (void *)out; | ||
| 46 | cryp.mac = 0; | ||
| 47 | |||
| 48 | cryp.op = ctx->encrypt ? COP_ENCRYPT : COP_DECRYPT; | ||
| 49 | |||
| 50 | if (ctx->cipher->iv_len) { | ||
| 51 | - cryp.iv = (caddr_t) ctx->iv; | ||
| 52 | + cryp.iv = (void *)ctx->iv; | ||
| 53 | if (!ctx->encrypt) { | ||
| 54 | iiv = in + inl - ctx->cipher->iv_len; | ||
| 55 | memcpy(save_iv, iiv, ctx->cipher->iv_len); | ||
| 56 | @@ -701,15 +701,15 @@ static int cryptodev_aead_cipher(EVP_CIPHER_CTX *ctx, unsigned char *out, | ||
| 57 | } | ||
| 58 | cryp.ses = sess->ses; | ||
| 59 | cryp.len = state->len; | ||
| 60 | - cryp.src = (caddr_t) in; | ||
| 61 | - cryp.dst = (caddr_t) out; | ||
| 62 | + cryp.src = (void *)in; | ||
| 63 | + cryp.dst = (void *)out; | ||
| 64 | cryp.auth_src = state->aad; | ||
| 65 | cryp.auth_len = state->aad_len; | ||
| 66 | |||
| 67 | cryp.op = ctx->encrypt ? COP_ENCRYPT : COP_DECRYPT; | ||
| 68 | |||
| 69 | if (ctx->cipher->iv_len) { | ||
| 70 | - cryp.iv = (caddr_t) ctx->iv; | ||
| 71 | + cryp.iv = (void *)ctx->iv; | ||
| 72 | if (!ctx->encrypt) { | ||
| 73 | iiv = in + len - ctx->cipher->iv_len; | ||
| 74 | memcpy(save_iv, iiv, ctx->cipher->iv_len); | ||
| 75 | @@ -761,7 +761,7 @@ cryptodev_init_key(EVP_CIPHER_CTX *ctx, const unsigned char *key, | ||
| 76 | if ((state->d_fd = get_dev_crypto()) < 0) | ||
| 77 | return (0); | ||
| 78 | |||
| 79 | - sess->key = (caddr_t) key; | ||
| 80 | + sess->key = (void *)key; | ||
| 81 | sess->keylen = ctx->key_len; | ||
| 82 | sess->cipher = cipher; | ||
| 83 | |||
| 84 | @@ -804,7 +804,7 @@ static int cryptodev_init_aead_key(EVP_CIPHER_CTX *ctx, | ||
| 85 | |||
| 86 | memset(sess, 0, sizeof(struct session_op)); | ||
| 87 | |||
| 88 | - sess->key = (caddr_t) key; | ||
| 89 | + sess->key = (void *)key; | ||
| 90 | sess->keylen = ctx->key_len; | ||
| 91 | sess->cipher = cipher; | ||
| 92 | |||
| 93 | -- | ||
| 94 | 2.7.0 | ||
| 95 | |||
diff --git a/recipes-connectivity/openssl/openssl-qoriq/qoriq/0041-cryptodev-check-for-errors-inside-cryptodev_rsa_mod_.patch b/recipes-connectivity/openssl/openssl-qoriq/qoriq/0041-cryptodev-check-for-errors-inside-cryptodev_rsa_mod_.patch new file mode 100644 index 000000000..552504548 --- /dev/null +++ b/recipes-connectivity/openssl/openssl-qoriq/qoriq/0041-cryptodev-check-for-errors-inside-cryptodev_rsa_mod_.patch | |||
| @@ -0,0 +1,49 @@ | |||
| 1 | From f10d471839dff079a23d79d1b4ecb3e3e6529283 Mon Sep 17 00:00:00 2001 | ||
| 2 | From: Cristian Stoica <cristian.stoica@nxp.com> | ||
| 3 | Date: Mon, 8 Feb 2016 17:04:25 +0200 | ||
| 4 | Subject: [PATCH 41/48] cryptodev: check for errors inside | ||
| 5 | cryptodev_rsa_mod_exp | ||
| 6 | |||
| 7 | Signed-off-by: Cristian Stoica <cristian.stoica@nxp.com> | ||
| 8 | --- | ||
| 9 | crypto/engine/eng_cryptodev.c | 24 ++++++++++++++++++------ | ||
| 10 | 1 file changed, 18 insertions(+), 6 deletions(-) | ||
| 11 | |||
| 12 | diff --git a/crypto/engine/eng_cryptodev.c b/crypto/engine/eng_cryptodev.c | ||
| 13 | index f172173..695848d 100644 | ||
| 14 | --- a/crypto/engine/eng_cryptodev.c | ||
| 15 | +++ b/crypto/engine/eng_cryptodev.c | ||
| 16 | @@ -2054,12 +2054,24 @@ cryptodev_rsa_mod_exp(BIGNUM *r0, const BIGNUM *I, RSA *rsa, BN_CTX *ctx) | ||
| 17 | kop.crk_status = 0; | ||
| 18 | kop.crk_op = CRK_MOD_EXP_CRT; | ||
| 19 | f_len = BN_num_bytes(rsa->n); | ||
| 20 | - spcf_bn2bin_ex(I, &f, &f_len); | ||
| 21 | - spcf_bn2bin(rsa->p, &p, &p_len); | ||
| 22 | - spcf_bn2bin(rsa->q, &q, &q_len); | ||
| 23 | - spcf_bn2bin_ex(rsa->dmp1, &dp, &p_len); | ||
| 24 | - spcf_bn2bin_ex(rsa->iqmp, &c, &p_len); | ||
| 25 | - spcf_bn2bin_ex(rsa->dmq1, &dq, &q_len); | ||
| 26 | + if (spcf_bn2bin_ex(I, &f, &f_len) != 0) { | ||
| 27 | + goto err; | ||
| 28 | + } | ||
| 29 | + if (spcf_bn2bin(rsa->p, &p, &p_len) != 0) { | ||
| 30 | + goto err; | ||
| 31 | + } | ||
| 32 | + if (spcf_bn2bin(rsa->q, &q, &q_len) != 0) { | ||
| 33 | + goto err; | ||
| 34 | + } | ||
| 35 | + if (spcf_bn2bin_ex(rsa->dmp1, &dp, &p_len) != 0) { | ||
| 36 | + goto err; | ||
| 37 | + } | ||
| 38 | + if (spcf_bn2bin_ex(rsa->iqmp, &c, &p_len) != 0) { | ||
| 39 | + goto err; | ||
| 40 | + } | ||
| 41 | + if (spcf_bn2bin_ex(rsa->dmq1, &dq, &q_len) != 0) { | ||
| 42 | + goto err; | ||
| 43 | + } | ||
| 44 | /* inputs: rsa->p rsa->q I rsa->dmp1 rsa->dmq1 rsa->iqmp */ | ||
| 45 | kop.crk_param[0].crp_p = p; | ||
| 46 | kop.crk_param[0].crp_nbits = p_len * 8; | ||
| 47 | -- | ||
| 48 | 2.7.0 | ||
| 49 | |||
diff --git a/recipes-connectivity/openssl/openssl-qoriq/qoriq/0042-cryptodev-check-for-errors-inside-cryptodev_rsa_mod_.patch b/recipes-connectivity/openssl/openssl-qoriq/qoriq/0042-cryptodev-check-for-errors-inside-cryptodev_rsa_mod_.patch new file mode 100644 index 000000000..218accb18 --- /dev/null +++ b/recipes-connectivity/openssl/openssl-qoriq/qoriq/0042-cryptodev-check-for-errors-inside-cryptodev_rsa_mod_.patch | |||
| @@ -0,0 +1,69 @@ | |||
| 1 | From 402a2e4da471728fa537462d7a13aa35955cd6d8 Mon Sep 17 00:00:00 2001 | ||
| 2 | From: Cristian Stoica <cristian.stoica@nxp.com> | ||
| 3 | Date: Tue, 9 Feb 2016 11:47:52 +0200 | ||
| 4 | Subject: [PATCH 42/48] cryptodev: check for errors inside | ||
| 5 | cryptodev_rsa_mod_exp_async | ||
| 6 | |||
| 7 | Signed-off-by: Cristian Stoica <cristian.stoica@nxp.com> | ||
| 8 | --- | ||
| 9 | crypto/engine/eng_cryptodev.c | 33 +++++++++++++++++++++++++-------- | ||
| 10 | 1 file changed, 25 insertions(+), 8 deletions(-) | ||
| 11 | |||
| 12 | diff --git a/crypto/engine/eng_cryptodev.c b/crypto/engine/eng_cryptodev.c | ||
| 13 | index 695848d..8e84972 100644 | ||
| 14 | --- a/crypto/engine/eng_cryptodev.c | ||
| 15 | +++ b/crypto/engine/eng_cryptodev.c | ||
| 16 | @@ -2109,25 +2109,42 @@ static int | ||
| 17 | cryptodev_rsa_mod_exp_async(BIGNUM *r0, const BIGNUM *I, RSA *rsa, | ||
| 18 | BN_CTX *ctx, struct pkc_cookie_s *cookie) | ||
| 19 | { | ||
| 20 | - struct crypt_kop *kop = malloc(sizeof(struct crypt_kop)); | ||
| 21 | + struct crypt_kop *kop; | ||
| 22 | int ret = 1, f_len, p_len, q_len; | ||
| 23 | unsigned char *f = NULL, *p = NULL, *q = NULL, *dp = NULL, *dq = | ||
| 24 | NULL, *c = NULL; | ||
| 25 | |||
| 26 | - if (!rsa->p || !rsa->q || !rsa->dmp1 || !rsa->dmq1 || !rsa->iqmp || !kop) { | ||
| 27 | + if (!rsa->p || !rsa->q || !rsa->dmp1 || !rsa->dmq1 || !rsa->iqmp) { | ||
| 28 | return (0); | ||
| 29 | } | ||
| 30 | |||
| 31 | + kop = malloc(sizeof(struct crypt_kop)); | ||
| 32 | + if (kop == NULL) { | ||
| 33 | + goto err; | ||
| 34 | + } | ||
| 35 | + | ||
| 36 | kop->crk_oparams = 0; | ||
| 37 | kop->crk_status = 0; | ||
| 38 | kop->crk_op = CRK_MOD_EXP_CRT; | ||
| 39 | f_len = BN_num_bytes(rsa->n); | ||
| 40 | - spcf_bn2bin_ex(I, &f, &f_len); | ||
| 41 | - spcf_bn2bin(rsa->p, &p, &p_len); | ||
| 42 | - spcf_bn2bin(rsa->q, &q, &q_len); | ||
| 43 | - spcf_bn2bin_ex(rsa->dmp1, &dp, &p_len); | ||
| 44 | - spcf_bn2bin_ex(rsa->iqmp, &c, &p_len); | ||
| 45 | - spcf_bn2bin_ex(rsa->dmq1, &dq, &q_len); | ||
| 46 | + if (spcf_bn2bin_ex(I, &f, &f_len) != 0) { | ||
| 47 | + goto err; | ||
| 48 | + } | ||
| 49 | + if (spcf_bn2bin(rsa->p, &p, &p_len) != 0) { | ||
| 50 | + goto err; | ||
| 51 | + } | ||
| 52 | + if (spcf_bn2bin(rsa->q, &q, &q_len) != 0) { | ||
| 53 | + goto err; | ||
| 54 | + } | ||
| 55 | + if (spcf_bn2bin_ex(rsa->dmp1, &dp, &p_len) != 0) { | ||
| 56 | + goto err; | ||
| 57 | + } | ||
| 58 | + if (spcf_bn2bin_ex(rsa->iqmp, &c, &p_len) != 0) { | ||
| 59 | + goto err; | ||
| 60 | + } | ||
| 61 | + if (spcf_bn2bin_ex(rsa->dmq1, &dq, &q_len) != 0) { | ||
| 62 | + goto err; | ||
| 63 | + } | ||
| 64 | /* inputs: rsa->p rsa->q I rsa->dmp1 rsa->dmq1 rsa->iqmp */ | ||
| 65 | kop->crk_param[0].crp_p = p; | ||
| 66 | kop->crk_param[0].crp_nbits = p_len * 8; | ||
| 67 | -- | ||
| 68 | 2.7.0 | ||
| 69 | |||
diff --git a/recipes-connectivity/openssl/openssl-qoriq/qoriq/0043-cryptodev-check-for-errors-inside-cryptodev_dh_compu.patch b/recipes-connectivity/openssl/openssl-qoriq/qoriq/0043-cryptodev-check-for-errors-inside-cryptodev_dh_compu.patch new file mode 100644 index 000000000..931141de6 --- /dev/null +++ b/recipes-connectivity/openssl/openssl-qoriq/qoriq/0043-cryptodev-check-for-errors-inside-cryptodev_dh_compu.patch | |||
| @@ -0,0 +1,52 @@ | |||
| 1 | From c8a5f714d35c3bd63d2511ad69e0661a7d1d5dcd Mon Sep 17 00:00:00 2001 | ||
| 2 | From: Cristian Stoica <cristian.stoica@nxp.com> | ||
| 3 | Date: Tue, 9 Feb 2016 11:53:22 +0200 | ||
| 4 | Subject: [PATCH 43/48] cryptodev: check for errors inside | ||
| 5 | cryptodev_dh_compute_key | ||
| 6 | |||
| 7 | Signed-off-by: Cristian Stoica <cristian.stoica@nxp.com> | ||
| 8 | --- | ||
| 9 | crypto/engine/eng_cryptodev.c | 15 +++++++++++---- | ||
| 10 | 1 file changed, 11 insertions(+), 4 deletions(-) | ||
| 11 | |||
| 12 | diff --git a/crypto/engine/eng_cryptodev.c b/crypto/engine/eng_cryptodev.c | ||
| 13 | index 8e84972..55b2047 100644 | ||
| 14 | --- a/crypto/engine/eng_cryptodev.c | ||
| 15 | +++ b/crypto/engine/eng_cryptodev.c | ||
| 16 | @@ -4043,11 +4043,15 @@ cryptodev_dh_compute_key(unsigned char *key, const BIGNUM *pub_key, DH *dh) | ||
| 17 | memset(&kop, 0, sizeof kop); | ||
| 18 | kop.crk_op = CRK_DH_COMPUTE_KEY; | ||
| 19 | /* inputs: dh->priv_key pub_key dh->p key */ | ||
| 20 | - spcf_bn2bin(dh->p, &p, &p_len); | ||
| 21 | - spcf_bn2bin_ex(pub_key, &padded_pub_key, &p_len); | ||
| 22 | - if (bn2crparam(dh->priv_key, &kop.crk_param[0])) | ||
| 23 | + if (spcf_bn2bin(dh->p, &p, &p_len) != 0) { | ||
| 24 | goto sw_try; | ||
| 25 | - | ||
| 26 | + } | ||
| 27 | + if (spcf_bn2bin_ex(pub_key, &padded_pub_key, &p_len) != 0) { | ||
| 28 | + goto sw_try; | ||
| 29 | + } | ||
| 30 | + if (bn2crparam(dh->priv_key, &kop.crk_param[0]) != 0) { | ||
| 31 | + goto sw_try; | ||
| 32 | + } | ||
| 33 | kop.crk_param[1].crp_p = padded_pub_key; | ||
| 34 | kop.crk_param[1].crp_nbits = p_len * 8; | ||
| 35 | kop.crk_param[2].crp_p = p; | ||
| 36 | @@ -4074,10 +4078,13 @@ cryptodev_dh_compute_key(unsigned char *key, const BIGNUM *pub_key, DH *dh) | ||
| 37 | kop.crk_param[3].crp_p = NULL; | ||
| 38 | zapparams(&kop); | ||
| 39 | return (dhret); | ||
| 40 | + | ||
| 41 | sw_try: | ||
| 42 | { | ||
| 43 | const DH_METHOD *meth = DH_OpenSSL(); | ||
| 44 | |||
| 45 | + free(p); | ||
| 46 | + free(padded_pub_key); | ||
| 47 | dhret = (meth->compute_key) (key, pub_key, dh); | ||
| 48 | } | ||
| 49 | return (dhret); | ||
| 50 | -- | ||
| 51 | 2.7.0 | ||
| 52 | |||
diff --git a/recipes-connectivity/openssl/openssl-qoriq/qoriq/0044-cryptodev-check-for-errors-inside-cryptodev_dh_compu.patch b/recipes-connectivity/openssl/openssl-qoriq/qoriq/0044-cryptodev-check-for-errors-inside-cryptodev_dh_compu.patch new file mode 100644 index 000000000..be9964358 --- /dev/null +++ b/recipes-connectivity/openssl/openssl-qoriq/qoriq/0044-cryptodev-check-for-errors-inside-cryptodev_dh_compu.patch | |||
| @@ -0,0 +1,76 @@ | |||
| 1 | From 42a1c45091ab7996c4411f3dd74539c908c63208 Mon Sep 17 00:00:00 2001 | ||
| 2 | From: Cristian Stoica <cristian.stoica@nxp.com> | ||
| 3 | Date: Tue, 9 Feb 2016 11:53:33 +0200 | ||
| 4 | Subject: [PATCH 44/48] cryptodev: check for errors inside | ||
| 5 | cryptodev_dh_compute_key_async | ||
| 6 | |||
| 7 | Signed-off-by: Cristian Stoica <cristian.stoica@nxp.com> | ||
| 8 | --- | ||
| 9 | crypto/engine/eng_cryptodev.c | 29 +++++++++++++++++++++-------- | ||
| 10 | 1 file changed, 21 insertions(+), 8 deletions(-) | ||
| 11 | |||
| 12 | diff --git a/crypto/engine/eng_cryptodev.c b/crypto/engine/eng_cryptodev.c | ||
| 13 | index 55b2047..e0f9d4b 100644 | ||
| 14 | --- a/crypto/engine/eng_cryptodev.c | ||
| 15 | +++ b/crypto/engine/eng_cryptodev.c | ||
| 16 | @@ -4095,19 +4095,28 @@ static int | ||
| 17 | cryptodev_dh_compute_key_async(unsigned char *key, const BIGNUM *pub_key, | ||
| 18 | DH *dh, struct pkc_cookie_s *cookie) | ||
| 19 | { | ||
| 20 | - struct crypt_kop *kop = malloc(sizeof(struct crypt_kop)); | ||
| 21 | + struct crypt_kop *kop; | ||
| 22 | int ret = 1; | ||
| 23 | int p_len; | ||
| 24 | unsigned char *padded_pub_key = NULL, *p = NULL; | ||
| 25 | |||
| 26 | + kop = malloc(sizeof(struct crypt_kop)); | ||
| 27 | + if (kop == NULL) { | ||
| 28 | + goto err; | ||
| 29 | + } | ||
| 30 | + | ||
| 31 | memset(kop, 0, sizeof(struct crypt_kop)); | ||
| 32 | kop->crk_op = CRK_DH_COMPUTE_KEY; | ||
| 33 | /* inputs: dh->priv_key pub_key dh->p key */ | ||
| 34 | - spcf_bn2bin(dh->p, &p, &p_len); | ||
| 35 | - spcf_bn2bin_ex(pub_key, &padded_pub_key, &p_len); | ||
| 36 | - | ||
| 37 | - if (bn2crparam(dh->priv_key, &kop->crk_param[0])) | ||
| 38 | + if (spcf_bn2bin(dh->p, &p, &p_len) != 0) { | ||
| 39 | + goto err; | ||
| 40 | + } | ||
| 41 | + if (spcf_bn2bin_ex(pub_key, &padded_pub_key, &p_len) != 0) { | ||
| 42 | goto err; | ||
| 43 | + } | ||
| 44 | + if (bn2crparam(dh->priv_key, &kop->crk_param[0]) != 0) { | ||
| 45 | + goto err; | ||
| 46 | + } | ||
| 47 | kop->crk_param[1].crp_p = padded_pub_key; | ||
| 48 | kop->crk_param[1].crp_nbits = p_len * 8; | ||
| 49 | kop->crk_param[2].crp_p = p; | ||
| 50 | @@ -4119,16 +4128,20 @@ cryptodev_dh_compute_key_async(unsigned char *key, const BIGNUM *pub_key, | ||
| 51 | kop->crk_param[3].crp_nbits = p_len * 8; | ||
| 52 | kop->crk_oparams = 1; | ||
| 53 | |||
| 54 | - if (cryptodev_asym_async(kop, 0, NULL, 0, NULL)) | ||
| 55 | + if (cryptodev_asym_async(kop, 0, NULL, 0, NULL)) { | ||
| 56 | goto err; | ||
| 57 | + } | ||
| 58 | |||
| 59 | return p_len; | ||
| 60 | err: | ||
| 61 | { | ||
| 62 | const DH_METHOD *meth = DH_OpenSSL(); | ||
| 63 | - | ||
| 64 | - if (kop) | ||
| 65 | + free(p); | ||
| 66 | + free(padded_pub_key); | ||
| 67 | + if (kop) { | ||
| 68 | free(kop); | ||
| 69 | + } | ||
| 70 | + | ||
| 71 | ret = (meth->compute_key) (key, pub_key, dh); | ||
| 72 | /* Call user cookie handler */ | ||
| 73 | cookie->pkc_callback(cookie, 0); | ||
| 74 | -- | ||
| 75 | 2.7.0 | ||
| 76 | |||
diff --git a/recipes-connectivity/openssl/openssl-qoriq/qoriq/0045-cryptodev-change-signature-for-conversion-functions.patch b/recipes-connectivity/openssl/openssl-qoriq/qoriq/0045-cryptodev-change-signature-for-conversion-functions.patch new file mode 100644 index 000000000..11f1a5411 --- /dev/null +++ b/recipes-connectivity/openssl/openssl-qoriq/qoriq/0045-cryptodev-change-signature-for-conversion-functions.patch | |||
| @@ -0,0 +1,38 @@ | |||
| 1 | From 528e4965e536d31cdccb11abe5e04db28a1008a8 Mon Sep 17 00:00:00 2001 | ||
| 2 | From: Cristian Stoica <cristian.stoica@nxp.com> | ||
| 3 | Date: Tue, 9 Feb 2016 12:11:32 +0200 | ||
| 4 | Subject: [PATCH 45/48] cryptodev: change signature for conversion functions | ||
| 5 | |||
| 6 | These functions are called with const BIGNUMs, so we change the | ||
| 7 | signatures to avoid compilation warnings | ||
| 8 | |||
| 9 | Signed-off-by: Cristian Stoica <cristian.stoica@nxp.com> | ||
| 10 | --- | ||
| 11 | crypto/engine/eng_cryptodev.c | 4 ++-- | ||
| 12 | 1 file changed, 2 insertions(+), 2 deletions(-) | ||
| 13 | |||
| 14 | diff --git a/crypto/engine/eng_cryptodev.c b/crypto/engine/eng_cryptodev.c | ||
| 15 | index e0f9d4b..3024a68 100644 | ||
| 16 | --- a/crypto/engine/eng_cryptodev.c | ||
| 17 | +++ b/crypto/engine/eng_cryptodev.c | ||
| 18 | @@ -145,7 +145,7 @@ const EVP_CIPHER cryptodev_tls12_aes_256_cbc_hmac_sha1; | ||
| 19 | const EVP_CIPHER cryptodev_tls12_aes_128_cbc_hmac_sha256; | ||
| 20 | const EVP_CIPHER cryptodev_tls12_aes_256_cbc_hmac_sha256; | ||
| 21 | |||
| 22 | -inline int spcf_bn2bin(BIGNUM *bn, unsigned char **bin, int *bin_len) | ||
| 23 | +inline int spcf_bn2bin(const BIGNUM *bn, unsigned char **bin, int *bin_len) | ||
| 24 | { | ||
| 25 | int len; | ||
| 26 | unsigned char *p; | ||
| 27 | @@ -167,7 +167,7 @@ inline int spcf_bn2bin(BIGNUM *bn, unsigned char **bin, int *bin_len) | ||
| 28 | return 0; | ||
| 29 | } | ||
| 30 | |||
| 31 | -inline int spcf_bn2bin_ex(BIGNUM *bn, unsigned char **bin, int *bin_len) | ||
| 32 | +inline int spcf_bn2bin_ex(const BIGNUM *bn, unsigned char **bin, int *bin_len) | ||
| 33 | { | ||
| 34 | int len; | ||
| 35 | unsigned char *p; | ||
| 36 | -- | ||
| 37 | 2.7.0 | ||
| 38 | |||
diff --git a/recipes-connectivity/openssl/openssl-qoriq/qoriq/0046-cryptodev-add-explicit-cast-for-known-BIGNUM-values.patch b/recipes-connectivity/openssl/openssl-qoriq/qoriq/0046-cryptodev-add-explicit-cast-for-known-BIGNUM-values.patch new file mode 100644 index 000000000..e7a5aa32f --- /dev/null +++ b/recipes-connectivity/openssl/openssl-qoriq/qoriq/0046-cryptodev-add-explicit-cast-for-known-BIGNUM-values.patch | |||
| @@ -0,0 +1,26 @@ | |||
| 1 | From b27823ac9f460c96a72d9003e2e134c1288ac85f Mon Sep 17 00:00:00 2001 | ||
| 2 | From: Cristian Stoica <cristian.stoica@nxp.com> | ||
| 3 | Date: Tue, 9 Feb 2016 12:13:59 +0200 | ||
| 4 | Subject: [PATCH 46/48] cryptodev: add explicit cast for known BIGNUM values | ||
| 5 | |||
| 6 | Signed-off-by: Cristian Stoica <cristian.stoica@nxp.com> | ||
| 7 | --- | ||
| 8 | crypto/engine/eng_cryptodev.c | 2 +- | ||
| 9 | 1 file changed, 1 insertion(+), 1 deletion(-) | ||
| 10 | |||
| 11 | diff --git a/crypto/engine/eng_cryptodev.c b/crypto/engine/eng_cryptodev.c | ||
| 12 | index 3024a68..539be62 100644 | ||
| 13 | --- a/crypto/engine/eng_cryptodev.c | ||
| 14 | +++ b/crypto/engine/eng_cryptodev.c | ||
| 15 | @@ -4014,7 +4014,7 @@ static int cryptodev_dh_keygen(DH *dh) | ||
| 16 | } | ||
| 17 | |||
| 18 | /* pub_key is or prime length while priv key is of length of order */ | ||
| 19 | - if (cryptodev_asym(&kop, q_len, w, q_len, s)) | ||
| 20 | + if (cryptodev_asym(&kop, q_len, (BIGNUM *)w, q_len, (BIGNUM *)s)) | ||
| 21 | goto sw_try; | ||
| 22 | |||
| 23 | dh->pub_key = BN_bin2bn(w, q_len, pub_key); | ||
| 24 | -- | ||
| 25 | 2.7.0 | ||
| 26 | |||
diff --git a/recipes-connectivity/openssl/openssl-qoriq/qoriq/0047-cryptodev-treat-all-build-warnings-as-errors.patch b/recipes-connectivity/openssl/openssl-qoriq/qoriq/0047-cryptodev-treat-all-build-warnings-as-errors.patch new file mode 100644 index 000000000..2163998bd --- /dev/null +++ b/recipes-connectivity/openssl/openssl-qoriq/qoriq/0047-cryptodev-treat-all-build-warnings-as-errors.patch | |||
| @@ -0,0 +1,28 @@ | |||
| 1 | From 596735ad86a3dae987e19c21ef22259179966fc6 Mon Sep 17 00:00:00 2001 | ||
| 2 | From: Cristian Stoica <cristian.stoica@nxp.com> | ||
| 3 | Date: Mon, 8 Feb 2016 15:15:02 +0200 | ||
| 4 | Subject: [PATCH 47/48] cryptodev: treat all build warnings as errors | ||
| 5 | |||
| 6 | This patch has the purpose of maintaining a higher level of code quality. | ||
| 7 | |||
| 8 | Signed-off-by: Cristian Stoica <cristian.stoica@nxp.com> | ||
| 9 | --- | ||
| 10 | crypto/engine/Makefile | 2 +- | ||
| 11 | 1 file changed, 1 insertion(+), 1 deletion(-) | ||
| 12 | |||
| 13 | diff --git a/crypto/engine/Makefile b/crypto/engine/Makefile | ||
| 14 | index 426388e..010f21d 100644 | ||
| 15 | --- a/crypto/engine/Makefile | ||
| 16 | +++ b/crypto/engine/Makefile | ||
| 17 | @@ -10,7 +10,7 @@ CFLAG=-g | ||
| 18 | MAKEFILE= Makefile | ||
| 19 | AR= ar r | ||
| 20 | |||
| 21 | -CFLAGS= $(INCLUDES) $(CFLAG) | ||
| 22 | +CFLAGS= -Wall -Werror $(INCLUDES) $(CFLAG) | ||
| 23 | |||
| 24 | GENERAL=Makefile | ||
| 25 | TEST= enginetest.c | ||
| 26 | -- | ||
| 27 | 2.7.0 | ||
| 28 | |||
diff --git a/recipes-connectivity/openssl/openssl-qoriq/qoriq/0048-fix-maclen-is-used-uninitialized-warning-on-some-com.patch b/recipes-connectivity/openssl/openssl-qoriq/qoriq/0048-fix-maclen-is-used-uninitialized-warning-on-some-com.patch new file mode 100644 index 000000000..d7b84e6ab --- /dev/null +++ b/recipes-connectivity/openssl/openssl-qoriq/qoriq/0048-fix-maclen-is-used-uninitialized-warning-on-some-com.patch | |||
| @@ -0,0 +1,29 @@ | |||
| 1 | From 116bd4f6f1ee5acdb997d414902d9646b24df1be Mon Sep 17 00:00:00 2001 | ||
| 2 | From: Cristian Stoica <cristian.stoica@nxp.com> | ||
| 3 | Date: Wed, 6 Apr 2016 15:22:58 +0300 | ||
| 4 | Subject: [PATCH 48/48] fix 'maclen is used uninitialized' warning on some | ||
| 5 | compilers | ||
| 6 | |||
| 7 | Signed-off-by: Cristian Stoica <cristian.stoica@nxp.com> | ||
| 8 | --- | ||
| 9 | crypto/engine/eng_cryptodev.c | 4 ++++ | ||
| 10 | 1 file changed, 4 insertions(+) | ||
| 11 | |||
| 12 | diff --git a/crypto/engine/eng_cryptodev.c b/crypto/engine/eng_cryptodev.c | ||
| 13 | index 539be62..35b71b0 100644 | ||
| 14 | --- a/crypto/engine/eng_cryptodev.c | ||
| 15 | +++ b/crypto/engine/eng_cryptodev.c | ||
| 16 | @@ -905,6 +905,10 @@ static int cryptodev_cbc_hmac_sha1_ctrl(EVP_CIPHER_CTX *ctx, int type, | ||
| 17 | maclen = SHA256_DIGEST_LENGTH; | ||
| 18 | aad_needs_fix = true; | ||
| 19 | break; | ||
| 20 | + default: | ||
| 21 | + fprintf(stderr, "%s: unsupported NID: %d\n", | ||
| 22 | + __func__, ctx->cipher->nid); | ||
| 23 | + return -1; | ||
| 24 | } | ||
| 25 | |||
| 26 | /* Correct length for AAD Length field */ | ||
| 27 | -- | ||
| 28 | 2.7.0 | ||
| 29 | |||
