diff options
author | miod <> | 2014-11-09 19:17:13 +0000 |
---|---|---|
committer | miod <> | 2014-11-09 19:17:13 +0000 |
commit | 12455d6eff265f95b0a7e20595630321799f50a2 (patch) | |
tree | 8f4747a1df4b007feca32e262b38052339c686c1 /src/lib | |
parent | a3c50c7d270773c83559454fd2b75ec6e04f43ab (diff) | |
download | openbsd-12455d6eff265f95b0a7e20595630321799f50a2.tar.gz openbsd-12455d6eff265f95b0a7e20595630321799f50a2.tar.bz2 openbsd-12455d6eff265f95b0a7e20595630321799f50a2.zip |
GOST crypto algorithms (well, most of them), ported from the removed GOST
engine to regular EVP citizens, contributed by Dmitry Eremin-Solenikov;
libcrypto bits only for now.
This is a verbatim import of Dmitry's work, and does not compile in this
state; the forthcoming commits will address these issues.
None of the GOST code is enabled in libcrypto yet, for it still gets
compiled with OPENSSL_NO_GOST defined. However, the public header gost.h
will be installed.
Diffstat (limited to 'src/lib')
75 files changed, 13110 insertions, 31 deletions
diff --git a/src/lib/libcrypto/asn1/ameth_lib.c b/src/lib/libcrypto/asn1/ameth_lib.c index e88496cc9d..168321618c 100644 --- a/src/lib/libcrypto/asn1/ameth_lib.c +++ b/src/lib/libcrypto/asn1/ameth_lib.c | |||
@@ -1,4 +1,4 @@ | |||
1 | /* $OpenBSD: ameth_lib.c,v 1.14 2014/07/13 16:03:09 beck Exp $ */ | 1 | /* $OpenBSD: ameth_lib.c,v 1.15 2014/11/09 19:17:13 miod Exp $ */ |
2 | /* Written by Dr Stephen N Henson (steve@openssl.org) for the OpenSSL | 2 | /* Written by Dr Stephen N Henson (steve@openssl.org) for the OpenSSL |
3 | * project 2006. | 3 | * project 2006. |
4 | */ | 4 | */ |
@@ -74,6 +74,8 @@ extern const EVP_PKEY_ASN1_METHOD rsa_asn1_meths[]; | |||
74 | extern const EVP_PKEY_ASN1_METHOD dsa_asn1_meths[]; | 74 | extern const EVP_PKEY_ASN1_METHOD dsa_asn1_meths[]; |
75 | extern const EVP_PKEY_ASN1_METHOD dh_asn1_meth; | 75 | extern const EVP_PKEY_ASN1_METHOD dh_asn1_meth; |
76 | extern const EVP_PKEY_ASN1_METHOD eckey_asn1_meth; | 76 | extern const EVP_PKEY_ASN1_METHOD eckey_asn1_meth; |
77 | extern const EVP_PKEY_ASN1_METHOD gostr01_asn1_meths[]; | ||
78 | extern const EVP_PKEY_ASN1_METHOD gostimit_asn1_meth; | ||
77 | extern const EVP_PKEY_ASN1_METHOD hmac_asn1_meth; | 79 | extern const EVP_PKEY_ASN1_METHOD hmac_asn1_meth; |
78 | extern const EVP_PKEY_ASN1_METHOD cmac_asn1_meth; | 80 | extern const EVP_PKEY_ASN1_METHOD cmac_asn1_meth; |
79 | 81 | ||
@@ -96,8 +98,16 @@ static const EVP_PKEY_ASN1_METHOD *standard_methods[] = { | |||
96 | #ifndef OPENSSL_NO_EC | 98 | #ifndef OPENSSL_NO_EC |
97 | &eckey_asn1_meth, | 99 | &eckey_asn1_meth, |
98 | #endif | 100 | #endif |
101 | #ifndef OPENSSL_NO_GOST | ||
102 | &gostr01_asn1_meths[0], | ||
103 | &gostimit_asn1_meth, | ||
104 | #endif | ||
99 | &hmac_asn1_meth, | 105 | &hmac_asn1_meth, |
100 | &cmac_asn1_meth | 106 | &cmac_asn1_meth, |
107 | #ifndef OPENSSL_NO_GOST | ||
108 | &gostr01_asn1_meths[1], | ||
109 | &gostr01_asn1_meths[2], | ||
110 | #endif | ||
101 | }; | 111 | }; |
102 | 112 | ||
103 | typedef int sk_cmp_fn_type(const char * const *a, const char * const *b); | 113 | typedef int sk_cmp_fn_type(const char * const *a, const char * const *b); |
diff --git a/src/lib/libcrypto/cms/cms_sd.c b/src/lib/libcrypto/cms/cms_sd.c index 70ad897bda..f4119f7a1c 100644 --- a/src/lib/libcrypto/cms/cms_sd.c +++ b/src/lib/libcrypto/cms/cms_sd.c | |||
@@ -1,4 +1,4 @@ | |||
1 | /* $OpenBSD: cms_sd.c,v 1.8 2014/07/12 16:03:37 miod Exp $ */ | 1 | /* $OpenBSD: cms_sd.c,v 1.9 2014/11/09 19:17:13 miod Exp $ */ |
2 | /* Written by Dr Stephen N Henson (steve@openssl.org) for the OpenSSL | 2 | /* Written by Dr Stephen N Henson (steve@openssl.org) for the OpenSSL |
3 | * project. | 3 | * project. |
4 | */ | 4 | */ |
@@ -920,6 +920,8 @@ CMS_add_standard_smimecap(STACK_OF(X509_ALGOR) **smcap) | |||
920 | { | 920 | { |
921 | if (!cms_add_cipher_smcap(smcap, NID_aes_256_cbc, -1) || | 921 | if (!cms_add_cipher_smcap(smcap, NID_aes_256_cbc, -1) || |
922 | !cms_add_digest_smcap(smcap, NID_id_GostR3411_94, -1) || | 922 | !cms_add_digest_smcap(smcap, NID_id_GostR3411_94, -1) || |
923 | !cms_add_digest_smcap(smcap, NID_id_tc26_gost3411_2012_256, -1) || | ||
924 | !cms_add_digest_smcap(smcap, NID_id_tc26_gost3411_2012_512, -1) || | ||
923 | !cms_add_cipher_smcap(smcap, NID_id_Gost28147_89, -1) || | 925 | !cms_add_cipher_smcap(smcap, NID_id_Gost28147_89, -1) || |
924 | !cms_add_cipher_smcap(smcap, NID_aes_192_cbc, -1) || | 926 | !cms_add_cipher_smcap(smcap, NID_aes_192_cbc, -1) || |
925 | !cms_add_cipher_smcap(smcap, NID_aes_128_cbc, -1) || | 927 | !cms_add_cipher_smcap(smcap, NID_aes_128_cbc, -1) || |
diff --git a/src/lib/libcrypto/crypto/Makefile b/src/lib/libcrypto/crypto/Makefile index cd32382081..0c4db18488 100644 --- a/src/lib/libcrypto/crypto/Makefile +++ b/src/lib/libcrypto/crypto/Makefile | |||
@@ -1,4 +1,4 @@ | |||
1 | # $OpenBSD: Makefile,v 1.46 2014/07/28 17:57:18 tedu Exp $ | 1 | # $OpenBSD: Makefile,v 1.47 2014/11/09 19:17:11 miod Exp $ |
2 | 2 | ||
3 | LIB= crypto | 3 | LIB= crypto |
4 | 4 | ||
@@ -154,6 +154,13 @@ SRCS+= evp_pkey.c evp_pbe.c p5_crpt.c p5_crpt2.c | |||
154 | SRCS+= e_old.c pmeth_lib.c pmeth_fn.c pmeth_gn.c m_sigver.c | 154 | SRCS+= e_old.c pmeth_lib.c pmeth_fn.c pmeth_gn.c m_sigver.c |
155 | SRCS+= e_aes_cbc_hmac_sha1.c e_rc4_hmac_md5.c | 155 | SRCS+= e_aes_cbc_hmac_sha1.c e_rc4_hmac_md5.c |
156 | SRCS+= e_chacha.c evp_aead.c e_chacha20poly1305.c | 156 | SRCS+= e_chacha.c evp_aead.c e_chacha20poly1305.c |
157 | #SRCS+= e_gost2814789.c m_gost2814789.c m_gostr341194.c m_streebog.c | ||
158 | |||
159 | # gost/ | ||
160 | #SRCS+= gost2814789.c gost89_keywrap.c gost89_params.c gost89imit_ameth.c | ||
161 | #SRCS+= gost89imit_pmeth.c gost_asn1.c gost_err.c gostr341001.c | ||
162 | #SRCS+= gostr341001_ameth.c gostr341001_key.c gostr341001_params.c | ||
163 | #SRCS+= gostr341001_pmeth.c gostr341194.c streebog.c | ||
157 | 164 | ||
158 | # hmac/ | 165 | # hmac/ |
159 | SRCS+= hmac.c hm_ameth.c hm_pmeth.c | 166 | SRCS+= hmac.c hm_ameth.c hm_pmeth.c |
@@ -285,6 +292,7 @@ SRCS+= v3_asid.c v3_addr.c | |||
285 | ${LCRYPTO_SRC}/engine \ | 292 | ${LCRYPTO_SRC}/engine \ |
286 | ${LCRYPTO_SRC}/err \ | 293 | ${LCRYPTO_SRC}/err \ |
287 | ${LCRYPTO_SRC}/evp \ | 294 | ${LCRYPTO_SRC}/evp \ |
295 | ${LCRYPTO_SRC}/gost \ | ||
288 | ${LCRYPTO_SRC}/hmac \ | 296 | ${LCRYPTO_SRC}/hmac \ |
289 | ${LCRYPTO_SRC}/idea \ | 297 | ${LCRYPTO_SRC}/idea \ |
290 | ${LCRYPTO_SRC}/krb5 \ | 298 | ${LCRYPTO_SRC}/krb5 \ |
@@ -346,6 +354,7 @@ HDRS=\ | |||
346 | crypto/engine/engine.h \ | 354 | crypto/engine/engine.h \ |
347 | crypto/err/err.h \ | 355 | crypto/err/err.h \ |
348 | crypto/evp/evp.h \ | 356 | crypto/evp/evp.h \ |
357 | crypto/gost/gost.h \ | ||
349 | crypto/hmac/hmac.h \ | 358 | crypto/hmac/hmac.h \ |
350 | crypto/idea/idea.h \ | 359 | crypto/idea/idea.h \ |
351 | crypto/krb5/krb5_asn.h \ | 360 | crypto/krb5/krb5_asn.h \ |
diff --git a/src/lib/libcrypto/ec/ec_curve.c b/src/lib/libcrypto/ec/ec_curve.c index 9d36d0bf22..0159dbe530 100644 --- a/src/lib/libcrypto/ec/ec_curve.c +++ b/src/lib/libcrypto/ec/ec_curve.c | |||
@@ -1,4 +1,4 @@ | |||
1 | /* $OpenBSD: ec_curve.c,v 1.7 2014/07/12 16:03:37 miod Exp $ */ | 1 | /* $OpenBSD: ec_curve.c,v 1.8 2014/11/09 19:17:13 miod Exp $ */ |
2 | /* | 2 | /* |
3 | * Written by Nils Larsch for the OpenSSL project. | 3 | * Written by Nils Larsch for the OpenSSL project. |
4 | */ | 4 | */ |
@@ -2766,6 +2766,315 @@ static const struct { | |||
2766 | } | 2766 | } |
2767 | }; | 2767 | }; |
2768 | 2768 | ||
2769 | #ifndef OPENSSL_NO_GOST | ||
2770 | static const struct { | ||
2771 | EC_CURVE_DATA h; | ||
2772 | unsigned char data[0 + 32 * 6]; | ||
2773 | } | ||
2774 | _EC_GOST_2001_Test = { | ||
2775 | { | ||
2776 | NID_X9_62_prime_field, 0, 32, 1 | ||
2777 | }, | ||
2778 | { /* no seed */ | ||
2779 | 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* p */ | ||
2780 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, | ||
2781 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, | ||
2782 | 0x04, 0x31, | ||
2783 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* a */ | ||
2784 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, | ||
2785 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, | ||
2786 | 0x00, 0x07, | ||
2787 | 0x5F, 0xBF, 0xF4, 0x98, 0xAA, 0x93, 0x8C, 0xE7, 0x39, 0xB8, /* b */ | ||
2788 | 0xE0, 0x22, 0xFB, 0xAF, 0xEF, 0x40, 0x56, 0x3F, 0x6E, 0x6A, | ||
2789 | 0x34, 0x72, 0xFC, 0x2A, 0x51, 0x4C, 0x0C, 0xE9, 0xDA, 0xE2, | ||
2790 | 0x3B, 0x7E, | ||
2791 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* x */ | ||
2792 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, | ||
2793 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, | ||
2794 | 0x00, 0x02, | ||
2795 | 0x08, 0xE2, 0xA8, 0xA0, 0xE6, 0x51, 0x47, 0xD4, 0xBD, 0x63, /* y */ | ||
2796 | 0x16, 0x03, 0x0E, 0x16, 0xD1, 0x9C, 0x85, 0xC9, 0x7F, 0x0A, | ||
2797 | 0x9C, 0xA2, 0x67, 0x12, 0x2B, 0x96, 0xAB, 0xBC, 0xEA, 0x7E, | ||
2798 | 0x8F, 0xC8, | ||
2799 | 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* order */ | ||
2800 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x50, 0xFE, 0x8A, 0x18, | ||
2801 | 0x92, 0x97, 0x61, 0x54, 0xC5, 0x9C, 0xFC, 0x19, 0x3A, 0xCC, | ||
2802 | 0xF5, 0xB3, | ||
2803 | } | ||
2804 | }; | ||
2805 | |||
2806 | static const struct { | ||
2807 | EC_CURVE_DATA h; | ||
2808 | unsigned char data[0 + 32 * 6]; | ||
2809 | } | ||
2810 | _EC_GOST_2001_CryptoPro_A = { | ||
2811 | { | ||
2812 | NID_X9_62_prime_field, 0, 32, 1 | ||
2813 | }, | ||
2814 | { /* no seed */ | ||
2815 | 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, /* p */ | ||
2816 | 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, | ||
2817 | 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, | ||
2818 | 0xFD, 0x97, | ||
2819 | 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, /* a */ | ||
2820 | 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, | ||
2821 | 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, | ||
2822 | 0xFD, 0x94, | ||
2823 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* b */ | ||
2824 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, | ||
2825 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, | ||
2826 | 0x00, 0xA6, | ||
2827 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* x */ | ||
2828 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, | ||
2829 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, | ||
2830 | 0x00, 0x01, | ||
2831 | 0x8D, 0x91, 0xE4, 0x71, 0xE0, 0x98, 0x9C, 0xDA, 0x27, 0xDF, /* y */ | ||
2832 | 0x50, 0x5A, 0x45, 0x3F, 0x2B, 0x76, 0x35, 0x29, 0x4F, 0x2D, | ||
2833 | 0xDF, 0x23, 0xE3, 0xB1, 0x22, 0xAC, 0xC9, 0x9C, 0x9E, 0x9F, | ||
2834 | 0x1E, 0x14, | ||
2835 | 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, /* order */ | ||
2836 | 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0x6C, 0x61, 0x10, 0x70, | ||
2837 | 0x99, 0x5A, 0xD1, 0x00, 0x45, 0x84, 0x1B, 0x09, 0xB7, 0x61, | ||
2838 | 0xB8, 0x93, | ||
2839 | } | ||
2840 | }; | ||
2841 | |||
2842 | static const struct { | ||
2843 | EC_CURVE_DATA h; | ||
2844 | unsigned char data[0 + 32 * 6]; | ||
2845 | } | ||
2846 | _EC_GOST_2001_CryptoPro_B = { | ||
2847 | { | ||
2848 | NID_X9_62_prime_field, 0, 32, 1 | ||
2849 | }, | ||
2850 | { /* no seed */ | ||
2851 | 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* p */ | ||
2852 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, | ||
2853 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, | ||
2854 | 0x0C, 0x99, | ||
2855 | 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* a */ | ||
2856 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, | ||
2857 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, | ||
2858 | 0x0C, 0x96, | ||
2859 | 0x3E, 0x1A, 0xF4, 0x19, 0xA2, 0x69, 0xA5, 0xF8, 0x66, 0xA7, /* b */ | ||
2860 | 0xD3, 0xC2, 0x5C, 0x3D, 0xF8, 0x0A, 0xE9, 0x79, 0x25, 0x93, | ||
2861 | 0x73, 0xFF, 0x2B, 0x18, 0x2F, 0x49, 0xD4, 0xCE, 0x7E, 0x1B, | ||
2862 | 0xBC, 0x8B, | ||
2863 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* x */ | ||
2864 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, | ||
2865 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, | ||
2866 | 0x00, 0x01, | ||
2867 | 0x3F, 0xA8, 0x12, 0x43, 0x59, 0xF9, 0x66, 0x80, 0xB8, 0x3D, /* y */ | ||
2868 | 0x1C, 0x3E, 0xB2, 0xC0, 0x70, 0xE5, 0xC5, 0x45, 0xC9, 0x85, | ||
2869 | 0x8D, 0x03, 0xEC, 0xFB, 0x74, 0x4B, 0xF8, 0xD7, 0x17, 0x71, | ||
2870 | 0x7E, 0xFC, | ||
2871 | 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* order */ | ||
2872 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x5F, 0x70, 0x0C, 0xFF, | ||
2873 | 0xF1, 0xA6, 0x24, 0xE5, 0xE4, 0x97, 0x16, 0x1B, 0xCC, 0x8A, | ||
2874 | 0x19, 0x8F, | ||
2875 | } | ||
2876 | }; | ||
2877 | |||
2878 | static const struct { | ||
2879 | EC_CURVE_DATA h; | ||
2880 | unsigned char data[0 + 32 * 6]; | ||
2881 | } | ||
2882 | _EC_GOST_2001_CryptoPro_C = { | ||
2883 | { | ||
2884 | NID_X9_62_prime_field, 0, 32, 1 | ||
2885 | }, | ||
2886 | { /* no seed */ | ||
2887 | 0x9B, 0x9F, 0x60, 0x5F, 0x5A, 0x85, 0x81, 0x07, 0xAB, 0x1E, /* p */ | ||
2888 | 0xC8, 0x5E, 0x6B, 0x41, 0xC8, 0xAA, 0xCF, 0x84, 0x6E, 0x86, | ||
2889 | 0x78, 0x90, 0x51, 0xD3, 0x79, 0x98, 0xF7, 0xB9, 0x02, 0x2D, | ||
2890 | 0x75, 0x9B, | ||
2891 | 0x9B, 0x9F, 0x60, 0x5F, 0x5A, 0x85, 0x81, 0x07, 0xAB, 0x1E, /* a */ | ||
2892 | 0xC8, 0x5E, 0x6B, 0x41, 0xC8, 0xAA, 0xCF, 0x84, 0x6E, 0x86, | ||
2893 | 0x78, 0x90, 0x51, 0xD3, 0x79, 0x98, 0xF7, 0xB9, 0x02, 0x2D, | ||
2894 | 0x75, 0x98, | ||
2895 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* b */ | ||
2896 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, | ||
2897 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, | ||
2898 | 0x80, 0x5A, | ||
2899 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* x */ | ||
2900 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, | ||
2901 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, | ||
2902 | 0x00, 0x00, | ||
2903 | 0x41, 0xEC, 0xE5, 0x57, 0x43, 0x71, 0x1A, 0x8C, 0x3C, 0xBF, /* y */ | ||
2904 | 0x37, 0x83, 0xCD, 0x08, 0xC0, 0xEE, 0x4D, 0x4D, 0xC4, 0x40, | ||
2905 | 0xD4, 0x64, 0x1A, 0x8F, 0x36, 0x6E, 0x55, 0x0D, 0xFD, 0xB3, | ||
2906 | 0xBB, 0x67, | ||
2907 | 0x9B, 0x9F, 0x60, 0x5F, 0x5A, 0x85, 0x81, 0x07, 0xAB, 0x1E, /* order */ | ||
2908 | 0xC8, 0x5E, 0x6B, 0x41, 0xC8, 0xAA, 0x58, 0x2C, 0xA3, 0x51, | ||
2909 | 0x1E, 0xDD, 0xFB, 0x74, 0xF0, 0x2F, 0x3A, 0x65, 0x98, 0x98, | ||
2910 | 0x0B, 0xB9, | ||
2911 | } | ||
2912 | }; | ||
2913 | |||
2914 | static const struct { | ||
2915 | EC_CURVE_DATA h; | ||
2916 | unsigned char data[0 + 64 * 6]; | ||
2917 | } | ||
2918 | _EC_GOST_2012_Test = { | ||
2919 | { | ||
2920 | NID_X9_62_prime_field, 0, 64, 1 | ||
2921 | }, | ||
2922 | { /* no seed */ | ||
2923 | 0x45, 0x31, 0xac, 0xd1, 0xfe, 0x00, 0x23, 0xc7, 0x55, 0x0d, /* p */ | ||
2924 | 0x26, 0x7b, 0x6b, 0x2f, 0xee, 0x80, 0x92, 0x2b, 0x14, 0xb2, | ||
2925 | 0xff, 0xb9, 0x0f, 0x04, 0xd4, 0xeb, 0x7c, 0x09, 0xb5, 0xd2, | ||
2926 | 0xd1, 0x5d, 0xf1, 0xd8, 0x52, 0x74, 0x1a, 0xf4, 0x70, 0x4a, | ||
2927 | 0x04, 0x58, 0x04, 0x7e, 0x80, 0xe4, 0x54, 0x6d, 0x35, 0xb8, | ||
2928 | 0x33, 0x6f, 0xac, 0x22, 0x4d, 0xd8, 0x16, 0x64, 0xbb, 0xf5, | ||
2929 | 0x28, 0xbe, 0x63, 0x73, | ||
2930 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* a */ | ||
2931 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, | ||
2932 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, | ||
2933 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, | ||
2934 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, | ||
2935 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, | ||
2936 | 0x00, 0x00, 0x00, 0x07, | ||
2937 | 0x1c, 0xff, 0x08, 0x06, 0xa3, 0x11, 0x16, 0xda, 0x29, 0xd8, /* b */ | ||
2938 | 0xcf, 0xa5, 0x4e, 0x57, 0xeb, 0x74, 0x8b, 0xc5, 0xf3, 0x77, | ||
2939 | 0xe4, 0x94, 0x00, 0xfd, 0xd7, 0x88, 0xb6, 0x49, 0xec, 0xa1, | ||
2940 | 0xac, 0x43, 0x61, 0x83, 0x40, 0x13, 0xb2, 0xad, 0x73, 0x22, | ||
2941 | 0x48, 0x0a, 0x89, 0xca, 0x58, 0xe0, 0xcf, 0x74, 0xbc, 0x9e, | ||
2942 | 0x54, 0x0c, 0x2a, 0xdd, 0x68, 0x97, 0xfa, 0xd0, 0xa3, 0x08, | ||
2943 | 0x4f, 0x30, 0x2a, 0xdc, | ||
2944 | 0x24, 0xd1, 0x9c, 0xc6, 0x45, 0x72, 0xee, 0x30, 0xf3, 0x96, /* x */ | ||
2945 | 0xbf, 0x6e, 0xbb, 0xfd, 0x7a, 0x6c, 0x52, 0x13, 0xb3, 0xb3, | ||
2946 | 0xd7, 0x05, 0x7c, 0xc8, 0x25, 0xf9, 0x10, 0x93, 0xa6, 0x8c, | ||
2947 | 0xd7, 0x62, 0xfd, 0x60, 0x61, 0x12, 0x62, 0xcd, 0x83, 0x8d, | ||
2948 | 0xc6, 0xb6, 0x0a, 0xa7, 0xee, 0xe8, 0x04, 0xe2, 0x8b, 0xc8, | ||
2949 | 0x49, 0x97, 0x7f, 0xac, 0x33, 0xb4, 0xb5, 0x30, 0xf1, 0xb1, | ||
2950 | 0x20, 0x24, 0x8a, 0x9a, | ||
2951 | 0x2b, 0xb3, 0x12, 0xa4, 0x3b, 0xd2, 0xce, 0x6e, 0x0d, 0x02, /* y */ | ||
2952 | 0x06, 0x13, 0xc8, 0x57, 0xac, 0xdd, 0xcf, 0xbf, 0x06, 0x1e, | ||
2953 | 0x91, 0xe5, 0xf2, 0xc3, 0xf3, 0x24, 0x47, 0xc2, 0x59, 0xf3, | ||
2954 | 0x9b, 0x2c, 0x83, 0xab, 0x15, 0x6d, 0x77, 0xf1, 0x49, 0x6b, | ||
2955 | 0xf7, 0xeb, 0x33, 0x51, 0xe1, 0xee, 0x4e, 0x43, 0xdc, 0x1a, | ||
2956 | 0x18, 0xb9, 0x1b, 0x24, 0x64, 0x0b, 0x6d, 0xbb, 0x92, 0xcb, | ||
2957 | 0x1a, 0xdd, 0x37, 0x1e, | ||
2958 | 0x45, 0x31, 0xac, 0xd1, 0xfe, 0x00, 0x23, 0xc7, 0x55, 0x0d, /* order */ | ||
2959 | 0x26, 0x7b, 0x6b, 0x2f, 0xee, 0x80, 0x92, 0x2b, 0x14, 0xb2, | ||
2960 | 0xff, 0xb9, 0x0f, 0x04, 0xd4, 0xeb, 0x7c, 0x09, 0xb5, 0xd2, | ||
2961 | 0xd1, 0x5d, 0xa8, 0x2f, 0x2d, 0x7e, 0xcb, 0x1d, 0xba, 0xc7, | ||
2962 | 0x19, 0x90, 0x5c, 0x5e, 0xec, 0xc4, 0x23, 0xf1, 0xd8, 0x6e, | ||
2963 | 0x25, 0xed, 0xbe, 0x23, 0xc5, 0x95, 0xd6, 0x44, 0xaa, 0xf1, | ||
2964 | 0x87, 0xe6, 0xe6, 0xdf, | ||
2965 | } | ||
2966 | }; | ||
2967 | |||
2968 | static const struct { | ||
2969 | EC_CURVE_DATA h; | ||
2970 | unsigned char data[0 + 64 * 6]; | ||
2971 | } | ||
2972 | _EC_GOST_2012_TC26_A = { | ||
2973 | { | ||
2974 | NID_X9_62_prime_field, 0, 64, 1 | ||
2975 | }, | ||
2976 | { /* no seed */ | ||
2977 | 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, /* p */ | ||
2978 | 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, | ||
2979 | 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, | ||
2980 | 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, | ||
2981 | 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, | ||
2982 | 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, | ||
2983 | 0xff, 0xff, 0xfd, 0xc7, | ||
2984 | 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, /* a */ | ||
2985 | 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, | ||
2986 | 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, | ||
2987 | 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, | ||
2988 | 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, | ||
2989 | 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, | ||
2990 | 0xff, 0xff, 0xfd, 0xc4, | ||
2991 | 0xe8, 0xc2, 0x50, 0x5d, 0xed, 0xfc, 0x86, 0xdd, 0xc1, 0xbd, /* b */ | ||
2992 | 0x0b, 0x2b, 0x66, 0x67, 0xf1, 0xda, 0x34, 0xb8, 0x25, 0x74, | ||
2993 | 0x76, 0x1c, 0xb0, 0xe8, 0x79, 0xbd, 0x08, 0x1c, 0xfd, 0x0b, | ||
2994 | 0x62, 0x65, 0xee, 0x3c, 0xb0, 0x90, 0xf3, 0x0d, 0x27, 0x61, | ||
2995 | 0x4c, 0xb4, 0x57, 0x40, 0x10, 0xda, 0x90, 0xdd, 0x86, 0x2e, | ||
2996 | 0xf9, 0xd4, 0xeb, 0xee, 0x47, 0x61, 0x50, 0x31, 0x90, 0x78, | ||
2997 | 0x5a, 0x71, 0xc7, 0x60, | ||
2998 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* x */ | ||
2999 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, | ||
3000 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, | ||
3001 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, | ||
3002 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, | ||
3003 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, | ||
3004 | 0x00, 0x00, 0x00, 0x03, | ||
3005 | 0x75, 0x03, 0xcf, 0xe8, 0x7a, 0x83, 0x6a, 0xe3, 0xa6, 0x1b, /* y */ | ||
3006 | 0x88, 0x16, 0xe2, 0x54, 0x50, 0xe6, 0xce, 0x5e, 0x1c, 0x93, | ||
3007 | 0xac, 0xf1, 0xab, 0xc1, 0x77, 0x80, 0x64, 0xfd, 0xcb, 0xef, | ||
3008 | 0xa9, 0x21, 0xdf, 0x16, 0x26, 0xbe, 0x4f, 0xd0, 0x36, 0xe9, | ||
3009 | 0x3d, 0x75, 0xe6, 0xa5, 0x0e, 0x3a, 0x41, 0xe9, 0x80, 0x28, | ||
3010 | 0xfe, 0x5f, 0xc2, 0x35, 0xf5, 0xb8, 0x89, 0xa5, 0x89, 0xcb, | ||
3011 | 0x52, 0x15, 0xf2, 0xa4, | ||
3012 | 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, /* order */ | ||
3013 | 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, | ||
3014 | 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, | ||
3015 | 0xff, 0xff, 0x27, 0xe6, 0x95, 0x32, 0xf4, 0x8d, 0x89, 0x11, | ||
3016 | 0x6f, 0xf2, 0x2b, 0x8d, 0x4e, 0x05, 0x60, 0x60, 0x9b, 0x4b, | ||
3017 | 0x38, 0xab, 0xfa, 0xd2, 0xb8, 0x5d, 0xca, 0xcd, 0xb1, 0x41, | ||
3018 | 0x1f, 0x10, 0xb2, 0x75 | ||
3019 | } | ||
3020 | }; | ||
3021 | |||
3022 | static const struct { | ||
3023 | EC_CURVE_DATA h; | ||
3024 | unsigned char data[0 + 64 * 6]; | ||
3025 | } | ||
3026 | _EC_GOST_2012_TC26_B = { | ||
3027 | { | ||
3028 | NID_X9_62_prime_field, 0, 64, 1 | ||
3029 | }, | ||
3030 | { /* no seed */ | ||
3031 | 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* p */ | ||
3032 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, | ||
3033 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, | ||
3034 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, | ||
3035 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, | ||
3036 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, | ||
3037 | 0x00, 0x00, 0x00, 0x6f, | ||
3038 | 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* a */ | ||
3039 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, | ||
3040 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, | ||
3041 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, | ||
3042 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, | ||
3043 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, | ||
3044 | 0x00, 0x00, 0x00, 0x6c, | ||
3045 | 0x68, 0x7d, 0x1b, 0x45, 0x9d, 0xc8, 0x41, 0x45, 0x7e, 0x3e, /* b */ | ||
3046 | 0x06, 0xcf, 0x6f, 0x5e, 0x25, 0x17, 0xb9, 0x7c, 0x7d, 0x61, | ||
3047 | 0x4a, 0xf1, 0x38, 0xbc, 0xbf, 0x85, 0xdc, 0x80, 0x6c, 0x4b, | ||
3048 | 0x28, 0x9f, 0x3e, 0x96, 0x5d, 0x2d, 0xb1, 0x41, 0x6d, 0x21, | ||
3049 | 0x7f, 0x8b, 0x27, 0x6f, 0xad, 0x1a, 0xb6, 0x9c, 0x50, 0xf7, | ||
3050 | 0x8b, 0xee, 0x1f, 0xa3, 0x10, 0x6e, 0xfb, 0x8c, 0xcb, 0xc7, | ||
3051 | 0xc5, 0x14, 0x01, 0x16, | ||
3052 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* x */ | ||
3053 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, | ||
3054 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, | ||
3055 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, | ||
3056 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, | ||
3057 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, | ||
3058 | 0x00, 0x00, 0x00, 0x02, | ||
3059 | 0x1a, 0x8f, 0x7e, 0xda, 0x38, 0x9b, 0x09, 0x4c, 0x2c, 0x07, /* y */ | ||
3060 | 0x1e, 0x36, 0x47, 0xa8, 0x94, 0x0f, 0x3c, 0x12, 0x3b, 0x69, | ||
3061 | 0x75, 0x78, 0xc2, 0x13, 0xbe, 0x6d, 0xd9, 0xe6, 0xc8, 0xec, | ||
3062 | 0x73, 0x35, 0xdc, 0xb2, 0x28, 0xfd, 0x1e, 0xdf, 0x4a, 0x39, | ||
3063 | 0x15, 0x2c, 0xbc, 0xaa, 0xf8, 0xc0, 0x39, 0x88, 0x28, 0x04, | ||
3064 | 0x10, 0x55, 0xf9, 0x4c, 0xee, 0xec, 0x7e, 0x21, 0x34, 0x07, | ||
3065 | 0x80, 0xfe, 0x41, 0xbd, | ||
3066 | 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* order */ | ||
3067 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, | ||
3068 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, | ||
3069 | 0x00, 0x01, 0x49, 0xa1, 0xec, 0x14, 0x25, 0x65, 0xa5, 0x45, | ||
3070 | 0xac, 0xfd, 0xb7, 0x7b, 0xd9, 0xd4, 0x0c, 0xfa, 0x8b, 0x99, | ||
3071 | 0x67, 0x12, 0x10, 0x1b, 0xea, 0x0e, 0xc6, 0x34, 0x6c, 0x54, | ||
3072 | 0x37, 0x4f, 0x25, 0xbd | ||
3073 | } | ||
3074 | }; | ||
3075 | |||
3076 | #endif | ||
3077 | |||
2769 | typedef struct _ec_list_element_st { | 3078 | typedef struct _ec_list_element_st { |
2770 | int nid; | 3079 | int nid; |
2771 | const EC_CURVE_DATA *data; | 3080 | const EC_CURVE_DATA *data; |
@@ -2890,7 +3199,18 @@ static const ec_list_element curve_list[] = { | |||
2890 | {NID_brainpoolP512r1, &_EC_brainpoolP512r1.h, 0, "RFC 5639 curve over a 512 bit prime field"}, | 3199 | {NID_brainpoolP512r1, &_EC_brainpoolP512r1.h, 0, "RFC 5639 curve over a 512 bit prime field"}, |
2891 | {NID_brainpoolP512t1, &_EC_brainpoolP512t1.h, 0, "RFC 5639 curve over a 512 bit prime field"}, | 3200 | {NID_brainpoolP512t1, &_EC_brainpoolP512t1.h, 0, "RFC 5639 curve over a 512 bit prime field"}, |
2892 | /* ANSSI */ | 3201 | /* ANSSI */ |
2893 | {NID_FRP256v1, &_EC_FRP256v1.h, 0, "FRP256v1"} | 3202 | {NID_FRP256v1, &_EC_FRP256v1.h, 0, "FRP256v1"}, |
3203 | #ifndef OPENSSL_NO_GOST | ||
3204 | /* GOST R 34.10-2001 */ | ||
3205 | {NID_id_GostR3410_2001_TestParamSet, &_EC_GOST_2001_Test.h, 0, "GOST R 34.10-2001 Test Curve"}, | ||
3206 | {NID_id_GostR3410_2001_CryptoPro_A_ParamSet, &_EC_GOST_2001_CryptoPro_A.h, 0, "GOST R 34.10-2001 CryptoPro-A"}, | ||
3207 | {NID_id_GostR3410_2001_CryptoPro_B_ParamSet, &_EC_GOST_2001_CryptoPro_B.h, 0, "GOST R 34.10-2001 CryptoPro-B"}, | ||
3208 | {NID_id_GostR3410_2001_CryptoPro_C_ParamSet, &_EC_GOST_2001_CryptoPro_C.h, 0, "GOST R 34.10-2001 CryptoPro-C"}, | ||
3209 | {NID_id_GostR3410_2001_CryptoPro_XchA_ParamSet, &_EC_GOST_2001_CryptoPro_A.h, 0, "GOST R 34.10-2001 CryptoPro-XchA"}, | ||
3210 | {NID_id_GostR3410_2001_CryptoPro_XchB_ParamSet, &_EC_GOST_2001_CryptoPro_C.h, 0, "GOST R 34.10-2001 CryptoPro-XchB"}, | ||
3211 | {NID_id_tc26_gost_3410_2012_512_paramSetA, &_EC_GOST_2012_TC26_A.h, 0, "GOST R 34.10-2012 TC26-A"}, | ||
3212 | {NID_id_tc26_gost_3410_2012_512_paramSetB, &_EC_GOST_2012_TC26_B.h, 0, "GOST R 34.10-2012 TC26-A"}, | ||
3213 | #endif | ||
2894 | }; | 3214 | }; |
2895 | 3215 | ||
2896 | #define curve_list_length (sizeof(curve_list)/sizeof(ec_list_element)) | 3216 | #define curve_list_length (sizeof(curve_list)/sizeof(ec_list_element)) |
diff --git a/src/lib/libcrypto/err/err.c b/src/lib/libcrypto/err/err.c index 75a1d0181e..f06320247c 100644 --- a/src/lib/libcrypto/err/err.c +++ b/src/lib/libcrypto/err/err.c | |||
@@ -1,4 +1,4 @@ | |||
1 | /* $OpenBSD: err.c,v 1.40 2014/10/05 15:21:48 deraadt Exp $ */ | 1 | /* $OpenBSD: err.c,v 1.41 2014/11/09 19:17:13 miod Exp $ */ |
2 | /* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) | 2 | /* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) |
3 | * All rights reserved. | 3 | * All rights reserved. |
4 | * | 4 | * |
@@ -157,6 +157,7 @@ static ERR_STRING_DATA ERR_str_libraries[] = { | |||
157 | {ERR_PACK(ERR_LIB_FIPS,0,0), "FIPS routines"}, | 157 | {ERR_PACK(ERR_LIB_FIPS,0,0), "FIPS routines"}, |
158 | {ERR_PACK(ERR_LIB_CMS,0,0), "CMS routines"}, | 158 | {ERR_PACK(ERR_LIB_CMS,0,0), "CMS routines"}, |
159 | {ERR_PACK(ERR_LIB_HMAC,0,0), "HMAC routines"}, | 159 | {ERR_PACK(ERR_LIB_HMAC,0,0), "HMAC routines"}, |
160 | {ERR_PACK(ERR_LIB_GOST,0,0), "GOST routines"}, | ||
160 | {0, NULL}, | 161 | {0, NULL}, |
161 | }; | 162 | }; |
162 | 163 | ||
diff --git a/src/lib/libcrypto/err/err.h b/src/lib/libcrypto/err/err.h index ced340ea80..87bb96eec7 100644 --- a/src/lib/libcrypto/err/err.h +++ b/src/lib/libcrypto/err/err.h | |||
@@ -1,4 +1,4 @@ | |||
1 | /* $OpenBSD: err.h,v 1.21 2014/07/11 09:25:24 jsing Exp $ */ | 1 | /* $OpenBSD: err.h,v 1.22 2014/11/09 19:17:13 miod Exp $ */ |
2 | /* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) | 2 | /* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) |
3 | * All rights reserved. | 3 | * All rights reserved. |
4 | * | 4 | * |
@@ -195,6 +195,7 @@ typedef struct err_state_st { | |||
195 | #define ERR_LIB_TS 47 | 195 | #define ERR_LIB_TS 47 |
196 | #define ERR_LIB_HMAC 48 | 196 | #define ERR_LIB_HMAC 48 |
197 | #define ERR_LIB_JPAKE 49 | 197 | #define ERR_LIB_JPAKE 49 |
198 | #define ERR_LIB_GOST 50 | ||
198 | 199 | ||
199 | #define ERR_LIB_USER 128 | 200 | #define ERR_LIB_USER 128 |
200 | 201 | ||
@@ -231,6 +232,7 @@ typedef struct err_state_st { | |||
231 | #define TSerr(f,r) ERR_PUT_error(ERR_LIB_TS,(f),(r),__FILE__,__LINE__) | 232 | #define TSerr(f,r) ERR_PUT_error(ERR_LIB_TS,(f),(r),__FILE__,__LINE__) |
232 | #define HMACerr(f,r) ERR_PUT_error(ERR_LIB_HMAC,(f),(r),__FILE__,__LINE__) | 233 | #define HMACerr(f,r) ERR_PUT_error(ERR_LIB_HMAC,(f),(r),__FILE__,__LINE__) |
233 | #define JPAKEerr(f,r) ERR_PUT_error(ERR_LIB_JPAKE,(f),(r),__FILE__,__LINE__) | 234 | #define JPAKEerr(f,r) ERR_PUT_error(ERR_LIB_JPAKE,(f),(r),__FILE__,__LINE__) |
235 | #define GOSTerr(f,r) ERR_PUT_error(ERR_LIB_GOST,(f),(r),__FILE__,__LINE__) | ||
234 | 236 | ||
235 | #define ERR_PACK(l,f,r) (((((unsigned long)l)&0xffL)<<24L)| \ | 237 | #define ERR_PACK(l,f,r) (((((unsigned long)l)&0xffL)<<24L)| \ |
236 | ((((unsigned long)f)&0xfffL)<<12L)| \ | 238 | ((((unsigned long)f)&0xfffL)<<12L)| \ |
diff --git a/src/lib/libcrypto/err/err_all.c b/src/lib/libcrypto/err/err_all.c index 7362220824..c880f1fbf3 100644 --- a/src/lib/libcrypto/err/err_all.c +++ b/src/lib/libcrypto/err/err_all.c | |||
@@ -1,4 +1,4 @@ | |||
1 | /* $OpenBSD: err_all.c,v 1.18 2014/10/18 17:08:32 jsing Exp $ */ | 1 | /* $OpenBSD: err_all.c,v 1.19 2014/11/09 19:17:13 miod Exp $ */ |
2 | /* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) | 2 | /* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) |
3 | * All rights reserved. | 3 | * All rights reserved. |
4 | * | 4 | * |
@@ -105,6 +105,9 @@ | |||
105 | #ifndef OPENSSL_NO_RSA | 105 | #ifndef OPENSSL_NO_RSA |
106 | #include <openssl/rsa.h> | 106 | #include <openssl/rsa.h> |
107 | #endif | 107 | #endif |
108 | #ifndef OPENSSL_NO_GOST | ||
109 | #include <openssl/gost.h> | ||
110 | #endif | ||
108 | 111 | ||
109 | void | 112 | void |
110 | ERR_load_crypto_strings(void) | 113 | ERR_load_crypto_strings(void) |
@@ -157,5 +160,8 @@ ERR_load_crypto_strings(void) | |||
157 | #ifndef OPENSSL_NO_CMS | 160 | #ifndef OPENSSL_NO_CMS |
158 | ERR_load_CMS_strings(); | 161 | ERR_load_CMS_strings(); |
159 | #endif | 162 | #endif |
163 | #ifndef OPENSSL_NO_GOST | ||
164 | ERR_load_GOST_strings(); | ||
165 | #endif | ||
160 | #endif | 166 | #endif |
161 | } | 167 | } |
diff --git a/src/lib/libcrypto/err/openssl.ec b/src/lib/libcrypto/err/openssl.ec index c513734e94..dcebbba6c4 100644 --- a/src/lib/libcrypto/err/openssl.ec +++ b/src/lib/libcrypto/err/openssl.ec | |||
@@ -34,6 +34,7 @@ L STORE crypto/store/store.h crypto/store/str_err.c | |||
34 | L TS crypto/ts/ts.h crypto/ts/ts_err.c | 34 | L TS crypto/ts/ts.h crypto/ts/ts_err.c |
35 | L HMAC crypto/hmac/hmac.h crypto/hmac/hmac_err.c | 35 | L HMAC crypto/hmac/hmac.h crypto/hmac/hmac_err.c |
36 | L CMS crypto/cms/cms.h crypto/cms/cms_err.c | 36 | L CMS crypto/cms/cms.h crypto/cms/cms_err.c |
37 | L GOST crypto/gost/gost.h crypto/gost/gost_err.c | ||
37 | 38 | ||
38 | # additional header files to be scanned for function names | 39 | # additional header files to be scanned for function names |
39 | L NONE crypto/x509/x509_vfy.h NONE | 40 | L NONE crypto/x509/x509_vfy.h NONE |
diff --git a/src/lib/libcrypto/evp/c_allc.c b/src/lib/libcrypto/evp/c_allc.c index 657e14f86f..26a5cc6179 100644 --- a/src/lib/libcrypto/evp/c_allc.c +++ b/src/lib/libcrypto/evp/c_allc.c | |||
@@ -1,4 +1,4 @@ | |||
1 | /* $OpenBSD: c_allc.c,v 1.13 2014/07/11 08:44:48 jsing Exp $ */ | 1 | /* $OpenBSD: c_allc.c,v 1.14 2014/11/09 19:17:13 miod Exp $ */ |
2 | /* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) | 2 | /* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) |
3 | * All rights reserved. | 3 | * All rights reserved. |
4 | * | 4 | * |
@@ -225,4 +225,10 @@ OpenSSL_add_all_ciphers(void) | |||
225 | #ifndef OPENSSL_NO_CHACHA | 225 | #ifndef OPENSSL_NO_CHACHA |
226 | EVP_add_cipher(EVP_chacha20()); | 226 | EVP_add_cipher(EVP_chacha20()); |
227 | #endif | 227 | #endif |
228 | |||
229 | #ifndef OPENSSL_NO_GOST | ||
230 | EVP_add_cipher(EVP_gost2814789_ecb()); | ||
231 | EVP_add_cipher(EVP_gost2814789_cfb64()); | ||
232 | EVP_add_cipher(EVP_gost2814789_cnt()); | ||
233 | #endif | ||
228 | } | 234 | } |
diff --git a/src/lib/libcrypto/evp/c_alld.c b/src/lib/libcrypto/evp/c_alld.c index 8f59100caa..99da8acdae 100644 --- a/src/lib/libcrypto/evp/c_alld.c +++ b/src/lib/libcrypto/evp/c_alld.c | |||
@@ -1,4 +1,4 @@ | |||
1 | /* $OpenBSD: c_alld.c,v 1.11 2014/07/11 08:44:48 jsing Exp $ */ | 1 | /* $OpenBSD: c_alld.c,v 1.12 2014/11/09 19:17:13 miod Exp $ */ |
2 | /* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) | 2 | /* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) |
3 | * All rights reserved. | 3 | * All rights reserved. |
4 | * | 4 | * |
@@ -95,6 +95,12 @@ OpenSSL_add_all_digests(void) | |||
95 | EVP_add_digest(EVP_ecdsa()); | 95 | EVP_add_digest(EVP_ecdsa()); |
96 | #endif | 96 | #endif |
97 | #endif | 97 | #endif |
98 | #ifndef OPENSSL_NO_GOST | ||
99 | EVP_add_digest(EVP_gostr341194()); | ||
100 | EVP_add_digest(EVP_gost2814789imit()); | ||
101 | EVP_add_digest(EVP_streebog256()); | ||
102 | EVP_add_digest(EVP_streebog512()); | ||
103 | #endif | ||
98 | #if !defined(OPENSSL_NO_MDC2) && !defined(OPENSSL_NO_DES) | 104 | #if !defined(OPENSSL_NO_MDC2) && !defined(OPENSSL_NO_DES) |
99 | EVP_add_digest(EVP_mdc2()); | 105 | EVP_add_digest(EVP_mdc2()); |
100 | #endif | 106 | #endif |
diff --git a/src/lib/libcrypto/evp/e_gost2814789.c b/src/lib/libcrypto/evp/e_gost2814789.c new file mode 100644 index 0000000000..678c7af09d --- /dev/null +++ b/src/lib/libcrypto/evp/e_gost2814789.c | |||
@@ -0,0 +1,216 @@ | |||
1 | /* $OpenBSD: e_gost2814789.c,v 1.1 2014/11/09 19:17:13 miod Exp $ */ | ||
2 | /* | ||
3 | * Copyright (c) 2014 Dmitry Eremin-Solenikov <dbaryshkov@gmail.com> | ||
4 | * Copyright (c) 2005-2006 Cryptocom LTD | ||
5 | * | ||
6 | * Redistribution and use in source and binary forms, with or without | ||
7 | * modification, are permitted provided that the following conditions | ||
8 | * are met: | ||
9 | * | ||
10 | * 1. Redistributions of source code must retain the above copyright | ||
11 | * notice, this list of conditions and the following disclaimer. | ||
12 | * | ||
13 | * 2. Redistributions in binary form must reproduce the above copyright | ||
14 | * notice, this list of conditions and the following disclaimer in | ||
15 | * the documentation and/or other materials provided with the | ||
16 | * distribution. | ||
17 | * | ||
18 | * 3. All advertising materials mentioning features or use of this | ||
19 | * software must display the following acknowledgment: | ||
20 | * "This product includes software developed by the OpenSSL Project | ||
21 | * for use in the OpenSSL Toolkit. (http://www.openssl.org/)" | ||
22 | * | ||
23 | * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to | ||
24 | * endorse or promote products derived from this software without | ||
25 | * prior written permission. For written permission, please contact | ||
26 | * openssl-core@openssl.org. | ||
27 | * | ||
28 | * 5. Products derived from this software may not be called "OpenSSL" | ||
29 | * nor may "OpenSSL" appear in their names without prior written | ||
30 | * permission of the OpenSSL Project. | ||
31 | * | ||
32 | * 6. Redistributions of any form whatsoever must retain the following | ||
33 | * acknowledgment: | ||
34 | * "This product includes software developed by the OpenSSL Project | ||
35 | * for use in the OpenSSL Toolkit (http://www.openssl.org/)" | ||
36 | * | ||
37 | * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY | ||
38 | * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | ||
39 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR | ||
40 | * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR | ||
41 | * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, | ||
42 | * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT | ||
43 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; | ||
44 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | ||
45 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, | ||
46 | * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) | ||
47 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED | ||
48 | * OF THE POSSIBILITY OF SUCH DAMAGE. | ||
49 | * ==================================================================== | ||
50 | */ | ||
51 | #include <string.h> | ||
52 | |||
53 | #include <openssl/opensslconf.h> | ||
54 | |||
55 | #ifndef OPENSSL_NO_GOST | ||
56 | #include <openssl/evp.h> | ||
57 | #include <openssl/err.h> | ||
58 | #include <openssl/gost.h> | ||
59 | #include "evp_locl.h" | ||
60 | |||
61 | typedef struct { | ||
62 | GOST2814789_KEY ks; | ||
63 | int param_nid; | ||
64 | } EVP_GOST2814789_CTX; | ||
65 | |||
66 | static int gost2814789_ctl(EVP_CIPHER_CTX *ctx,int type,int arg,void *ptr) | ||
67 | { | ||
68 | EVP_GOST2814789_CTX *c = ctx->cipher_data; | ||
69 | |||
70 | switch (type) { | ||
71 | case EVP_CTRL_PBE_PRF_NID: | ||
72 | if (ptr) { | ||
73 | *((int *)ptr) = NID_id_HMACGostR3411_94; | ||
74 | return 1; | ||
75 | } else { | ||
76 | return 0; | ||
77 | } | ||
78 | case EVP_CTRL_INIT: | ||
79 | /* Default value to have any s-box set at all */ | ||
80 | c->param_nid = NID_id_Gost28147_89_CryptoPro_A_ParamSet; | ||
81 | return Gost2814789_set_sbox(&c->ks, c->param_nid); | ||
82 | case EVP_CTRL_GOST_SET_SBOX: | ||
83 | return Gost2814789_set_sbox(&c->ks, arg); | ||
84 | default: | ||
85 | return -1; | ||
86 | } | ||
87 | } | ||
88 | |||
89 | static int gost2814789_init_key(EVP_CIPHER_CTX *ctx, const unsigned char *key, | ||
90 | const unsigned char *iv, int enc) | ||
91 | { | ||
92 | EVP_GOST2814789_CTX *c = ctx->cipher_data; | ||
93 | |||
94 | return Gost2814789_set_key(&c->ks, key, ctx->key_len * 8); | ||
95 | } | ||
96 | |||
97 | int gost2814789_set_asn1_params(EVP_CIPHER_CTX * ctx, ASN1_TYPE * params) | ||
98 | { | ||
99 | int len = 0; | ||
100 | unsigned char *buf = NULL; | ||
101 | unsigned char *p = NULL; | ||
102 | EVP_GOST2814789_CTX *c = ctx->cipher_data; | ||
103 | GOST_CIPHER_PARAMS *gcp = GOST_CIPHER_PARAMS_new(); | ||
104 | ASN1_OCTET_STRING *os = NULL; | ||
105 | if (!gcp) { | ||
106 | GOSTerr(GOST_F_GOST89_SET_ASN1_PARAMETERS, ERR_R_MALLOC_FAILURE); | ||
107 | return 0; | ||
108 | } | ||
109 | if (!ASN1_OCTET_STRING_set(gcp->iv, ctx->iv, ctx->cipher->iv_len)) { | ||
110 | GOST_CIPHER_PARAMS_free(gcp); | ||
111 | GOSTerr(GOST_F_GOST89_SET_ASN1_PARAMETERS, ERR_R_ASN1_LIB); | ||
112 | return 0; | ||
113 | } | ||
114 | ASN1_OBJECT_free(gcp->enc_param_set); | ||
115 | gcp->enc_param_set = OBJ_nid2obj(c->param_nid); | ||
116 | |||
117 | len = i2d_GOST_CIPHER_PARAMS(gcp, NULL); | ||
118 | p = buf = malloc(len); | ||
119 | if (!buf) { | ||
120 | GOST_CIPHER_PARAMS_free(gcp); | ||
121 | GOSTerr(GOST_F_GOST89_SET_ASN1_PARAMETERS, ERR_R_MALLOC_FAILURE); | ||
122 | return 0; | ||
123 | } | ||
124 | i2d_GOST_CIPHER_PARAMS(gcp, &p); | ||
125 | GOST_CIPHER_PARAMS_free(gcp); | ||
126 | |||
127 | os = ASN1_OCTET_STRING_new(); | ||
128 | |||
129 | if (!os || !ASN1_OCTET_STRING_set(os, buf, len)) { | ||
130 | free(buf); | ||
131 | GOSTerr(GOST_F_GOST89_SET_ASN1_PARAMETERS, ERR_R_ASN1_LIB); | ||
132 | return 0; | ||
133 | } | ||
134 | free(buf); | ||
135 | |||
136 | ASN1_TYPE_set(params, V_ASN1_SEQUENCE, os); | ||
137 | return 1; | ||
138 | } | ||
139 | |||
140 | int gost2814789_get_asn1_params(EVP_CIPHER_CTX * ctx, ASN1_TYPE * params) | ||
141 | { | ||
142 | int ret = -1; | ||
143 | int len; | ||
144 | GOST_CIPHER_PARAMS *gcp = NULL; | ||
145 | EVP_GOST2814789_CTX *c = ctx->cipher_data; | ||
146 | unsigned char *p; | ||
147 | |||
148 | if (ASN1_TYPE_get(params) != V_ASN1_SEQUENCE) { | ||
149 | return ret; | ||
150 | } | ||
151 | |||
152 | p = params->value.sequence->data; | ||
153 | |||
154 | gcp = d2i_GOST_CIPHER_PARAMS(NULL, (const unsigned char **)&p, | ||
155 | params->value.sequence->length); | ||
156 | |||
157 | len = gcp->iv->length; | ||
158 | if (len != ctx->cipher->iv_len) { | ||
159 | GOST_CIPHER_PARAMS_free(gcp); | ||
160 | GOSTerr(GOST_F_GOST89_GET_ASN1_PARAMETERS, | ||
161 | GOST_R_INVALID_IV_LENGTH); | ||
162 | return -1; | ||
163 | } | ||
164 | |||
165 | if (!Gost2814789_set_sbox(&c->ks, OBJ_obj2nid(gcp->enc_param_set))) { | ||
166 | GOST_CIPHER_PARAMS_free(gcp); | ||
167 | return -1; | ||
168 | } | ||
169 | c->param_nid = OBJ_obj2nid(gcp->enc_param_set); | ||
170 | |||
171 | memcpy(ctx->oiv, gcp->iv->data, len); | ||
172 | memcpy(ctx->iv, gcp->iv->data, len); | ||
173 | |||
174 | GOST_CIPHER_PARAMS_free(gcp); | ||
175 | |||
176 | return 1; | ||
177 | } | ||
178 | |||
179 | BLOCK_CIPHER_func_ecb(gost2814789, Gost2814789, EVP_GOST2814789_CTX, ks) | ||
180 | BLOCK_CIPHER_func_cfb(gost2814789, Gost2814789, 64, EVP_GOST2814789_CTX, ks) | ||
181 | |||
182 | static int gost2814789_cnt_cipher(EVP_CIPHER_CTX * ctx, unsigned char *out, | ||
183 | const unsigned char *in, size_t inl) | ||
184 | { | ||
185 | EVP_GOST2814789_CTX *c = ctx->cipher_data; | ||
186 | |||
187 | while (inl >= EVP_MAXCHUNK) { | ||
188 | Gost2814789_cnt_encrypt(in, out, (long)EVP_MAXCHUNK, &c->ks, | ||
189 | ctx->iv, ctx->buf, &ctx->num); | ||
190 | inl -= EVP_MAXCHUNK; | ||
191 | in += EVP_MAXCHUNK; | ||
192 | out += EVP_MAXCHUNK; | ||
193 | } | ||
194 | |||
195 | if (inl) | ||
196 | Gost2814789_cnt_encrypt(in, out, inl, &c->ks, | ||
197 | ctx->iv, ctx->buf, &ctx->num); | ||
198 | return 1; | ||
199 | } | ||
200 | |||
201 | /* gost89 is CFB-64 */ | ||
202 | #define NID_gost89_cfb64 NID_id_Gost28147_89 | ||
203 | |||
204 | BLOCK_CIPHER_def_ecb(gost2814789, EVP_GOST2814789_CTX, NID_gost89, 8, 32, | ||
205 | EVP_CIPH_NO_PADDING | EVP_CIPH_CTRL_INIT, | ||
206 | gost2814789_init_key, NULL, gost2814789_set_asn1_params, | ||
207 | gost2814789_get_asn1_params, gost2814789_ctl) | ||
208 | BLOCK_CIPHER_def_cfb(gost2814789, EVP_GOST2814789_CTX, NID_gost89, 32, 8, 64, | ||
209 | EVP_CIPH_NO_PADDING | EVP_CIPH_CTRL_INIT, | ||
210 | gost2814789_init_key, NULL, gost2814789_set_asn1_params, | ||
211 | gost2814789_get_asn1_params, gost2814789_ctl) | ||
212 | BLOCK_CIPHER_def1(gost2814789, cnt, cnt, OFB, EVP_GOST2814789_CTX, NID_gost89, | ||
213 | 1, 32, 8, EVP_CIPH_NO_PADDING | EVP_CIPH_CTRL_INIT, | ||
214 | gost2814789_init_key, NULL, gost2814789_set_asn1_params, | ||
215 | gost2814789_get_asn1_params, gost2814789_ctl) | ||
216 | #endif | ||
diff --git a/src/lib/libcrypto/evp/evp.h b/src/lib/libcrypto/evp/evp.h index 9de7c3f9ef..6c1bf6c7cd 100644 --- a/src/lib/libcrypto/evp/evp.h +++ b/src/lib/libcrypto/evp/evp.h | |||
@@ -1,4 +1,4 @@ | |||
1 | /* $OpenBSD: evp.h,v 1.39 2014/07/11 15:28:27 tedu Exp $ */ | 1 | /* $OpenBSD: evp.h,v 1.40 2014/11/09 19:17:13 miod Exp $ */ |
2 | /* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) | 2 | /* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) |
3 | * All rights reserved. | 3 | * All rights reserved. |
4 | * | 4 | * |
@@ -107,8 +107,12 @@ | |||
107 | #define EVP_PKEY_DSA4 NID_dsaWithSHA1_2 | 107 | #define EVP_PKEY_DSA4 NID_dsaWithSHA1_2 |
108 | #define EVP_PKEY_DH NID_dhKeyAgreement | 108 | #define EVP_PKEY_DH NID_dhKeyAgreement |
109 | #define EVP_PKEY_EC NID_X9_62_id_ecPublicKey | 109 | #define EVP_PKEY_EC NID_X9_62_id_ecPublicKey |
110 | #define EVP_PKEY_GOSTR01 NID_id_GostR3410_2001 | ||
111 | #define EVP_PKEY_GOSTIMIT NID_id_Gost28147_89_MAC | ||
110 | #define EVP_PKEY_HMAC NID_hmac | 112 | #define EVP_PKEY_HMAC NID_hmac |
111 | #define EVP_PKEY_CMAC NID_cmac | 113 | #define EVP_PKEY_CMAC NID_cmac |
114 | #define EVP_PKEY_GOSTR12_256 NID_id_tc26_gost3410_2012_256 | ||
115 | #define EVP_PKEY_GOSTR12_512 NID_id_tc26_gost3410_2012_512 | ||
112 | 116 | ||
113 | #ifdef __cplusplus | 117 | #ifdef __cplusplus |
114 | extern "C" { | 118 | extern "C" { |
@@ -137,6 +141,9 @@ struct evp_pkey_st { | |||
137 | #ifndef OPENSSL_NO_EC | 141 | #ifndef OPENSSL_NO_EC |
138 | struct ec_key_st *ec; /* ECC */ | 142 | struct ec_key_st *ec; /* ECC */ |
139 | #endif | 143 | #endif |
144 | #ifndef OPENSSL_NO_GOST | ||
145 | struct gost_key_st *gost; /* GOST */ | ||
146 | #endif | ||
140 | } pkey; | 147 | } pkey; |
141 | int save_parameters; | 148 | int save_parameters; |
142 | STACK_OF(X509_ATTRIBUTE) *attributes; /* [ 0 ] */ | 149 | STACK_OF(X509_ATTRIBUTE) *attributes; /* [ 0 ] */ |
@@ -213,6 +220,8 @@ typedef int evp_verify_method(int type, const unsigned char *m, | |||
213 | 220 | ||
214 | #define EVP_MD_CTRL_DIGALGID 0x1 | 221 | #define EVP_MD_CTRL_DIGALGID 0x1 |
215 | #define EVP_MD_CTRL_MICALG 0x2 | 222 | #define EVP_MD_CTRL_MICALG 0x2 |
223 | #define EVP_MD_CTRL_SET_KEY 0x3 | ||
224 | #define EVP_MD_CTRL_GOST_SET_SBOX 0x4 | ||
216 | 225 | ||
217 | /* Minimum Algorithm specific ctrl value */ | 226 | /* Minimum Algorithm specific ctrl value */ |
218 | 227 | ||
@@ -381,6 +390,8 @@ struct evp_cipher_st { | |||
381 | #define EVP_CTRL_AEAD_SET_MAC_KEY 0x17 | 390 | #define EVP_CTRL_AEAD_SET_MAC_KEY 0x17 |
382 | /* Set the GCM invocation field, decrypt only */ | 391 | /* Set the GCM invocation field, decrypt only */ |
383 | #define EVP_CTRL_GCM_SET_IV_INV 0x18 | 392 | #define EVP_CTRL_GCM_SET_IV_INV 0x18 |
393 | /* Set the S-BOX NID for GOST ciphers */ | ||
394 | #define EVP_CTRL_GOST_SET_SBOX 0x19 | ||
384 | 395 | ||
385 | /* GCM TLS constants */ | 396 | /* GCM TLS constants */ |
386 | /* Length of fixed part of IV derived from PRF */ | 397 | /* Length of fixed part of IV derived from PRF */ |
@@ -451,6 +462,11 @@ typedef int (EVP_PBE_KEYGEN)(EVP_CIPHER_CTX *ctx, const char *pass, int passlen, | |||
451 | (char *)(eckey)) | 462 | (char *)(eckey)) |
452 | #endif | 463 | #endif |
453 | 464 | ||
465 | #ifndef OPENSSL_NO_GOST | ||
466 | #define EVP_PKEY_assign_GOST(pkey,gostkey) EVP_PKEY_assign((pkey),EVP_PKEY_GOSTR01,\ | ||
467 | (char *)(gostkey)) | ||
468 | #endif | ||
469 | |||
454 | /* Add some extra combinations */ | 470 | /* Add some extra combinations */ |
455 | #define EVP_get_digestbynid(a) EVP_get_digestbyname(OBJ_nid2sn(a)) | 471 | #define EVP_get_digestbynid(a) EVP_get_digestbyname(OBJ_nid2sn(a)) |
456 | #define EVP_get_digestbyobj(a) EVP_get_digestbynid(OBJ_obj2nid(a)) | 472 | #define EVP_get_digestbyobj(a) EVP_get_digestbynid(OBJ_obj2nid(a)) |
@@ -530,6 +546,7 @@ void EVP_MD_CTX_destroy(EVP_MD_CTX *ctx); | |||
530 | int EVP_MD_CTX_copy_ex(EVP_MD_CTX *out, const EVP_MD_CTX *in); | 546 | int EVP_MD_CTX_copy_ex(EVP_MD_CTX *out, const EVP_MD_CTX *in); |
531 | void EVP_MD_CTX_set_flags(EVP_MD_CTX *ctx, int flags); | 547 | void EVP_MD_CTX_set_flags(EVP_MD_CTX *ctx, int flags); |
532 | void EVP_MD_CTX_clear_flags(EVP_MD_CTX *ctx, int flags); | 548 | void EVP_MD_CTX_clear_flags(EVP_MD_CTX *ctx, int flags); |
549 | int EVP_MD_CTX_ctrl(EVP_MD_CTX *ctx, int type, int arg, void *ptr); | ||
533 | int EVP_MD_CTX_test_flags(const EVP_MD_CTX *ctx, int flags); | 550 | int EVP_MD_CTX_test_flags(const EVP_MD_CTX *ctx, int flags); |
534 | int EVP_DigestInit_ex(EVP_MD_CTX *ctx, const EVP_MD *type, ENGINE *impl); | 551 | int EVP_DigestInit_ex(EVP_MD_CTX *ctx, const EVP_MD *type, ENGINE *impl); |
535 | int EVP_DigestUpdate(EVP_MD_CTX *ctx, const void *d, size_t cnt); | 552 | int EVP_DigestUpdate(EVP_MD_CTX *ctx, const void *d, size_t cnt); |
@@ -665,6 +682,12 @@ const EVP_MD *EVP_ripemd160(void); | |||
665 | #ifndef OPENSSL_NO_WHIRLPOOL | 682 | #ifndef OPENSSL_NO_WHIRLPOOL |
666 | const EVP_MD *EVP_whirlpool(void); | 683 | const EVP_MD *EVP_whirlpool(void); |
667 | #endif | 684 | #endif |
685 | #ifndef OPENSSL_NO_GOST | ||
686 | const EVP_MD *EVP_gostr341194(void); | ||
687 | const EVP_MD *EVP_gost2814789imit(void); | ||
688 | const EVP_MD *EVP_streebog256(void); | ||
689 | const EVP_MD *EVP_streebog512(void); | ||
690 | #endif | ||
668 | const EVP_CIPHER *EVP_enc_null(void); /* does nothing :-) */ | 691 | const EVP_CIPHER *EVP_enc_null(void); /* does nothing :-) */ |
669 | #ifndef OPENSSL_NO_DES | 692 | #ifndef OPENSSL_NO_DES |
670 | const EVP_CIPHER *EVP_des_ecb(void); | 693 | const EVP_CIPHER *EVP_des_ecb(void); |
@@ -804,6 +827,12 @@ const EVP_CIPHER *EVP_camellia_256_ofb(void); | |||
804 | const EVP_CIPHER *EVP_chacha20(void); | 827 | const EVP_CIPHER *EVP_chacha20(void); |
805 | #endif | 828 | #endif |
806 | 829 | ||
830 | #ifndef OPENSSL_NO_GOST | ||
831 | const EVP_CIPHER *EVP_gost2814789_ecb(void); | ||
832 | const EVP_CIPHER *EVP_gost2814789_cfb64(void); | ||
833 | const EVP_CIPHER *EVP_gost2814789_cnt(void); | ||
834 | #endif | ||
835 | |||
807 | void OPENSSL_add_all_algorithms_noconf(void); | 836 | void OPENSSL_add_all_algorithms_noconf(void); |
808 | void OPENSSL_add_all_algorithms_conf(void); | 837 | void OPENSSL_add_all_algorithms_conf(void); |
809 | 838 | ||
@@ -871,6 +900,9 @@ struct ec_key_st; | |||
871 | int EVP_PKEY_set1_EC_KEY(EVP_PKEY *pkey, struct ec_key_st *key); | 900 | int EVP_PKEY_set1_EC_KEY(EVP_PKEY *pkey, struct ec_key_st *key); |
872 | struct ec_key_st *EVP_PKEY_get1_EC_KEY(EVP_PKEY *pkey); | 901 | struct ec_key_st *EVP_PKEY_get1_EC_KEY(EVP_PKEY *pkey); |
873 | #endif | 902 | #endif |
903 | #ifndef OPENSSL_NO_GOST | ||
904 | struct gost_key_st; | ||
905 | #endif | ||
874 | 906 | ||
875 | EVP_PKEY *EVP_PKEY_new(void); | 907 | EVP_PKEY *EVP_PKEY_new(void); |
876 | void EVP_PKEY_free(EVP_PKEY *pkey); | 908 | void EVP_PKEY_free(EVP_PKEY *pkey); |
@@ -1337,6 +1369,7 @@ void ERR_load_EVP_strings(void); | |||
1337 | #define EVP_F_EVP_DIGESTINIT_EX 128 | 1369 | #define EVP_F_EVP_DIGESTINIT_EX 128 |
1338 | #define EVP_F_EVP_ENCRYPTFINAL_EX 127 | 1370 | #define EVP_F_EVP_ENCRYPTFINAL_EX 127 |
1339 | #define EVP_F_EVP_MD_CTX_COPY_EX 110 | 1371 | #define EVP_F_EVP_MD_CTX_COPY_EX 110 |
1372 | #define EVP_F_EVP_MD_CTX_CTRL 195 | ||
1340 | #define EVP_F_EVP_MD_SIZE 162 | 1373 | #define EVP_F_EVP_MD_SIZE 162 |
1341 | #define EVP_F_EVP_OPENINIT 102 | 1374 | #define EVP_F_EVP_OPENINIT 102 |
1342 | #define EVP_F_EVP_PBE_ALG_ADD 115 | 1375 | #define EVP_F_EVP_PBE_ALG_ADD 115 |
diff --git a/src/lib/libcrypto/evp/m_gost2814789.c b/src/lib/libcrypto/evp/m_gost2814789.c new file mode 100644 index 0000000000..ff3f489e46 --- /dev/null +++ b/src/lib/libcrypto/evp/m_gost2814789.c | |||
@@ -0,0 +1,105 @@ | |||
1 | /* $OpenBSD: m_gost2814789.c,v 1.1 2014/11/09 19:17:13 miod Exp $ */ | ||
2 | /* | ||
3 | * Copyright (c) 2014 Dmitry Eremin-Solenikov <dbaryshkov@gmail.com> | ||
4 | * Copyright (c) 2005-2006 Cryptocom LTD | ||
5 | * | ||
6 | * Redistribution and use in source and binary forms, with or without | ||
7 | * modification, are permitted provided that the following conditions | ||
8 | * are met: | ||
9 | * | ||
10 | * 1. Redistributions of source code must retain the above copyright | ||
11 | * notice, this list of conditions and the following disclaimer. | ||
12 | * | ||
13 | * 2. Redistributions in binary form must reproduce the above copyright | ||
14 | * notice, this list of conditions and the following disclaimer in | ||
15 | * the documentation and/or other materials provided with the | ||
16 | * distribution. | ||
17 | * | ||
18 | * 3. All advertising materials mentioning features or use of this | ||
19 | * software must display the following acknowledgment: | ||
20 | * "This product includes software developed by the OpenSSL Project | ||
21 | * for use in the OpenSSL Toolkit. (http://www.openssl.org/)" | ||
22 | * | ||
23 | * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to | ||
24 | * endorse or promote products derived from this software without | ||
25 | * prior written permission. For written permission, please contact | ||
26 | * openssl-core@openssl.org. | ||
27 | * | ||
28 | * 5. Products derived from this software may not be called "OpenSSL" | ||
29 | * nor may "OpenSSL" appear in their names without prior written | ||
30 | * permission of the OpenSSL Project. | ||
31 | * | ||
32 | * 6. Redistributions of any form whatsoever must retain the following | ||
33 | * acknowledgment: | ||
34 | * "This product includes software developed by the OpenSSL Project | ||
35 | * for use in the OpenSSL Toolkit (http://www.openssl.org/)" | ||
36 | * | ||
37 | * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY | ||
38 | * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | ||
39 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR | ||
40 | * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR | ||
41 | * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, | ||
42 | * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT | ||
43 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; | ||
44 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | ||
45 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, | ||
46 | * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) | ||
47 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED | ||
48 | * OF THE POSSIBILITY OF SUCH DAMAGE. | ||
49 | * ==================================================================== | ||
50 | */ | ||
51 | #include <openssl/opensslconf.h> | ||
52 | |||
53 | #ifndef OPENSSL_NO_GOST | ||
54 | |||
55 | #include <openssl/evp.h> | ||
56 | #include <openssl/gost.h> | ||
57 | #include <openssl/objects.h> | ||
58 | |||
59 | static int init(EVP_MD_CTX *ctx) | ||
60 | { | ||
61 | return GOST2814789IMIT_Init(ctx->md_data, NID_id_Gost28147_89_CryptoPro_A_ParamSet); | ||
62 | } | ||
63 | |||
64 | static int update(EVP_MD_CTX *ctx, const void *data, size_t count) | ||
65 | { | ||
66 | return GOST2814789IMIT_Update(ctx->md_data, data, count); | ||
67 | } | ||
68 | |||
69 | static int final(EVP_MD_CTX *ctx, unsigned char *md) | ||
70 | { | ||
71 | return GOST2814789IMIT_Final(md, ctx->md_data); | ||
72 | } | ||
73 | |||
74 | static int md_ctrl(EVP_MD_CTX *ctx, int cmd, int p1, void *p2) | ||
75 | { | ||
76 | GOST2814789IMIT_CTX *gctx = ctx->md_data; | ||
77 | |||
78 | switch (cmd) { | ||
79 | case EVP_MD_CTRL_SET_KEY: | ||
80 | return Gost2814789_set_key(&gctx->cipher, p2, p1); | ||
81 | case EVP_MD_CTRL_GOST_SET_SBOX: | ||
82 | return Gost2814789_set_sbox(&gctx->cipher, p1); | ||
83 | } | ||
84 | return -2; | ||
85 | } | ||
86 | |||
87 | static const EVP_MD gost2814789imit_md = { | ||
88 | .type = NID_id_Gost28147_89_MAC, | ||
89 | .pkey_type = NID_undef, | ||
90 | .md_size = GOST2814789IMIT_LENGTH, | ||
91 | .flags = 0, | ||
92 | .init = init, | ||
93 | .update = update, | ||
94 | .final = final, | ||
95 | .block_size = GOST2814789IMIT_CBLOCK, | ||
96 | .ctx_size = sizeof(EVP_MD *) + sizeof(GOST2814789IMIT_CTX), | ||
97 | .md_ctrl = md_ctrl, | ||
98 | }; | ||
99 | |||
100 | const EVP_MD * | ||
101 | EVP_gost2814789imit(void) | ||
102 | { | ||
103 | return (&gost2814789imit_md); | ||
104 | } | ||
105 | #endif | ||
diff --git a/src/lib/libcrypto/evp/m_gostr341194.c b/src/lib/libcrypto/evp/m_gostr341194.c new file mode 100644 index 0000000000..380d92d508 --- /dev/null +++ b/src/lib/libcrypto/evp/m_gostr341194.c | |||
@@ -0,0 +1,93 @@ | |||
1 | /* $OpenBSD: m_gostr341194.c,v 1.1 2014/11/09 19:17:13 miod Exp $ */ | ||
2 | /* | ||
3 | * Copyright (c) 2014 Dmitry Eremin-Solenikov <dbaryshkov@gmail.com> | ||
4 | * Copyright (c) 2005-2006 Cryptocom LTD | ||
5 | * | ||
6 | * Redistribution and use in source and binary forms, with or without | ||
7 | * modification, are permitted provided that the following conditions | ||
8 | * are met: | ||
9 | * | ||
10 | * 1. Redistributions of source code must retain the above copyright | ||
11 | * notice, this list of conditions and the following disclaimer. | ||
12 | * | ||
13 | * 2. Redistributions in binary form must reproduce the above copyright | ||
14 | * notice, this list of conditions and the following disclaimer in | ||
15 | * the documentation and/or other materials provided with the | ||
16 | * distribution. | ||
17 | * | ||
18 | * 3. All advertising materials mentioning features or use of this | ||
19 | * software must display the following acknowledgment: | ||
20 | * "This product includes software developed by the OpenSSL Project | ||
21 | * for use in the OpenSSL Toolkit. (http://www.openssl.org/)" | ||
22 | * | ||
23 | * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to | ||
24 | * endorse or promote products derived from this software without | ||
25 | * prior written permission. For written permission, please contact | ||
26 | * openssl-core@openssl.org. | ||
27 | * | ||
28 | * 5. Products derived from this software may not be called "OpenSSL" | ||
29 | * nor may "OpenSSL" appear in their names without prior written | ||
30 | * permission of the OpenSSL Project. | ||
31 | * | ||
32 | * 6. Redistributions of any form whatsoever must retain the following | ||
33 | * acknowledgment: | ||
34 | * "This product includes software developed by the OpenSSL Project | ||
35 | * for use in the OpenSSL Toolkit (http://www.openssl.org/)" | ||
36 | * | ||
37 | * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY | ||
38 | * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | ||
39 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR | ||
40 | * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR | ||
41 | * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, | ||
42 | * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT | ||
43 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; | ||
44 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | ||
45 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, | ||
46 | * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) | ||
47 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED | ||
48 | * OF THE POSSIBILITY OF SUCH DAMAGE. | ||
49 | * ==================================================================== | ||
50 | */ | ||
51 | #include <stdio.h> | ||
52 | |||
53 | #include <openssl/opensslconf.h> | ||
54 | |||
55 | #ifndef OPENSSL_NO_GOST | ||
56 | |||
57 | #include <openssl/evp.h> | ||
58 | #include <openssl/gost.h> | ||
59 | #include <openssl/objects.h> | ||
60 | |||
61 | static int init(EVP_MD_CTX *ctx) | ||
62 | { | ||
63 | return GOSTR341194_Init(ctx->md_data, NID_id_GostR3411_94_CryptoProParamSet); | ||
64 | } | ||
65 | |||
66 | static int update(EVP_MD_CTX *ctx, const void *data, size_t count) | ||
67 | { | ||
68 | return GOSTR341194_Update(ctx->md_data, data, count); | ||
69 | } | ||
70 | |||
71 | static int final(EVP_MD_CTX *ctx, unsigned char *md) | ||
72 | { | ||
73 | return GOSTR341194_Final(md, ctx->md_data); | ||
74 | } | ||
75 | |||
76 | static const EVP_MD gostr341194_md = { | ||
77 | .type = NID_id_GostR3411_94, | ||
78 | .pkey_type = NID_undef, | ||
79 | .md_size = GOSTR341194_LENGTH, | ||
80 | .flags = EVP_MD_FLAG_PKEY_METHOD_SIGNATURE, | ||
81 | .init = init, | ||
82 | .update = update, | ||
83 | .final = final, | ||
84 | .block_size = GOSTR341194_CBLOCK, | ||
85 | .ctx_size = sizeof(EVP_MD *) + sizeof(GOSTR341194_CTX), | ||
86 | }; | ||
87 | |||
88 | const EVP_MD * | ||
89 | EVP_gostr341194(void) | ||
90 | { | ||
91 | return (&gostr341194_md); | ||
92 | } | ||
93 | #endif | ||
diff --git a/src/lib/libcrypto/evp/m_streebog.c b/src/lib/libcrypto/evp/m_streebog.c new file mode 100644 index 0000000000..cf4b159f43 --- /dev/null +++ b/src/lib/libcrypto/evp/m_streebog.c | |||
@@ -0,0 +1,125 @@ | |||
1 | /* $OpenBSD: m_streebog.c,v 1.1 2014/11/09 19:17:13 miod Exp $ */ | ||
2 | /* | ||
3 | * Copyright (c) 2014 Dmitry Eremin-Solenikov <dbaryshkov@gmail.com> | ||
4 | * Copyright (c) 2005-2006 Cryptocom LTD | ||
5 | * | ||
6 | * Redistribution and use in source and binary forms, with or without | ||
7 | * modification, are permitted provided that the following conditions | ||
8 | * are met: | ||
9 | * | ||
10 | * 1. Redistributions of source code must retain the above copyright | ||
11 | * notice, this list of conditions and the following disclaimer. | ||
12 | * | ||
13 | * 2. Redistributions in binary form must reproduce the above copyright | ||
14 | * notice, this list of conditions and the following disclaimer in | ||
15 | * the documentation and/or other materials provided with the | ||
16 | * distribution. | ||
17 | * | ||
18 | * 3. All advertising materials mentioning features or use of this | ||
19 | * software must display the following acknowledgment: | ||
20 | * "This product includes software developed by the OpenSSL Project | ||
21 | * for use in the OpenSSL Toolkit. (http://www.openssl.org/)" | ||
22 | * | ||
23 | * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to | ||
24 | * endorse or promote products derived from this software without | ||
25 | * prior written permission. For written permission, please contact | ||
26 | * openssl-core@openssl.org. | ||
27 | * | ||
28 | * 5. Products derived from this software may not be called "OpenSSL" | ||
29 | * nor may "OpenSSL" appear in their names without prior written | ||
30 | * permission of the OpenSSL Project. | ||
31 | * | ||
32 | * 6. Redistributions of any form whatsoever must retain the following | ||
33 | * acknowledgment: | ||
34 | * "This product includes software developed by the OpenSSL Project | ||
35 | * for use in the OpenSSL Toolkit (http://www.openssl.org/)" | ||
36 | * | ||
37 | * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY | ||
38 | * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | ||
39 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR | ||
40 | * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR | ||
41 | * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, | ||
42 | * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT | ||
43 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; | ||
44 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | ||
45 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, | ||
46 | * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) | ||
47 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED | ||
48 | * OF THE POSSIBILITY OF SUCH DAMAGE. | ||
49 | * ==================================================================== | ||
50 | */ | ||
51 | |||
52 | #include <openssl/opensslconf.h> | ||
53 | |||
54 | #ifndef OPENSSL_NO_GOST | ||
55 | |||
56 | #include <openssl/evp.h> | ||
57 | #include <openssl/gost.h> | ||
58 | #include <openssl/objects.h> | ||
59 | |||
60 | static int init256(EVP_MD_CTX *ctx) | ||
61 | { | ||
62 | return STREEBOG256_Init(ctx->md_data); | ||
63 | } | ||
64 | |||
65 | static int update256(EVP_MD_CTX *ctx, const void *data, size_t count) | ||
66 | { | ||
67 | return STREEBOG256_Update(ctx->md_data, data, count); | ||
68 | } | ||
69 | |||
70 | static int final256(EVP_MD_CTX *ctx, unsigned char *md) | ||
71 | { | ||
72 | return STREEBOG256_Final(md, ctx->md_data); | ||
73 | } | ||
74 | |||
75 | static int init512(EVP_MD_CTX *ctx) | ||
76 | { | ||
77 | return STREEBOG512_Init(ctx->md_data); | ||
78 | } | ||
79 | |||
80 | static int update512(EVP_MD_CTX *ctx, const void *data, size_t count) | ||
81 | { | ||
82 | return STREEBOG512_Update(ctx->md_data, data, count); | ||
83 | } | ||
84 | |||
85 | static int final512(EVP_MD_CTX *ctx, unsigned char *md) | ||
86 | { | ||
87 | return STREEBOG512_Final(md, ctx->md_data); | ||
88 | } | ||
89 | |||
90 | static const EVP_MD streebog256_md = { | ||
91 | .type = NID_id_tc26_gost3411_2012_256, | ||
92 | .pkey_type = NID_undef, | ||
93 | .md_size = STREEBOG256_LENGTH, | ||
94 | .flags = EVP_MD_FLAG_PKEY_METHOD_SIGNATURE, | ||
95 | .init = init256, | ||
96 | .update = update256, | ||
97 | .final = final256, | ||
98 | .block_size = STREEBOG_CBLOCK, | ||
99 | .ctx_size = sizeof(EVP_MD *) + sizeof(STREEBOG_CTX), | ||
100 | }; | ||
101 | |||
102 | static const EVP_MD streebog512_md = { | ||
103 | .type = NID_id_tc26_gost3411_2012_512, | ||
104 | .pkey_type = NID_undef, | ||
105 | .md_size = STREEBOG512_LENGTH, | ||
106 | .flags = EVP_MD_FLAG_PKEY_METHOD_SIGNATURE, | ||
107 | .init = init512, | ||
108 | .update = update512, | ||
109 | .final = final512, | ||
110 | .block_size = STREEBOG_CBLOCK, | ||
111 | .ctx_size = sizeof(EVP_MD *) + sizeof(STREEBOG_CTX), | ||
112 | }; | ||
113 | |||
114 | const EVP_MD * | ||
115 | EVP_streebog256(void) | ||
116 | { | ||
117 | return (&streebog256_md); | ||
118 | } | ||
119 | |||
120 | const EVP_MD * | ||
121 | EVP_streebog512(void) | ||
122 | { | ||
123 | return (&streebog512_md); | ||
124 | } | ||
125 | #endif | ||
diff --git a/src/lib/libcrypto/evp/pmeth_lib.c b/src/lib/libcrypto/evp/pmeth_lib.c index 12267a6d93..24cdfdd1d0 100644 --- a/src/lib/libcrypto/evp/pmeth_lib.c +++ b/src/lib/libcrypto/evp/pmeth_lib.c | |||
@@ -1,4 +1,4 @@ | |||
1 | /* $OpenBSD: pmeth_lib.c,v 1.9 2014/07/12 16:03:37 miod Exp $ */ | 1 | /* $OpenBSD: pmeth_lib.c,v 1.10 2014/11/09 19:17:13 miod Exp $ */ |
2 | /* Written by Dr Stephen N Henson (steve@openssl.org) for the OpenSSL | 2 | /* Written by Dr Stephen N Henson (steve@openssl.org) for the OpenSSL |
3 | * project 2006. | 3 | * project 2006. |
4 | */ | 4 | */ |
@@ -79,6 +79,7 @@ STACK_OF(EVP_PKEY_METHOD) *app_pkey_methods = NULL; | |||
79 | 79 | ||
80 | extern const EVP_PKEY_METHOD rsa_pkey_meth, dh_pkey_meth, dsa_pkey_meth; | 80 | extern const EVP_PKEY_METHOD rsa_pkey_meth, dh_pkey_meth, dsa_pkey_meth; |
81 | extern const EVP_PKEY_METHOD ec_pkey_meth, hmac_pkey_meth, cmac_pkey_meth; | 81 | extern const EVP_PKEY_METHOD ec_pkey_meth, hmac_pkey_meth, cmac_pkey_meth; |
82 | extern const EVP_PKEY_METHOD gostimit_pkey_meth, gostr01_pkey_meth; | ||
82 | 83 | ||
83 | static const EVP_PKEY_METHOD *standard_methods[] = { | 84 | static const EVP_PKEY_METHOD *standard_methods[] = { |
84 | #ifndef OPENSSL_NO_RSA | 85 | #ifndef OPENSSL_NO_RSA |
@@ -93,8 +94,12 @@ static const EVP_PKEY_METHOD *standard_methods[] = { | |||
93 | #ifndef OPENSSL_NO_EC | 94 | #ifndef OPENSSL_NO_EC |
94 | &ec_pkey_meth, | 95 | &ec_pkey_meth, |
95 | #endif | 96 | #endif |
97 | #ifndef OPENSSL_NO_GOST | ||
98 | &gostr01_pkey_meth, | ||
99 | &gostimit_pkey_meth, | ||
100 | #endif | ||
96 | &hmac_pkey_meth, | 101 | &hmac_pkey_meth, |
97 | &cmac_pkey_meth | 102 | &cmac_pkey_meth, |
98 | }; | 103 | }; |
99 | 104 | ||
100 | DECLARE_OBJ_BSEARCH_CMP_FN(const EVP_PKEY_METHOD *, const EVP_PKEY_METHOD *, | 105 | DECLARE_OBJ_BSEARCH_CMP_FN(const EVP_PKEY_METHOD *, const EVP_PKEY_METHOD *, |
diff --git a/src/lib/libcrypto/gost/gost.h b/src/lib/libcrypto/gost/gost.h new file mode 100644 index 0000000000..5296e7b9c2 --- /dev/null +++ b/src/lib/libcrypto/gost/gost.h | |||
@@ -0,0 +1,263 @@ | |||
1 | /* $OpenBSD: gost.h,v 1.1 2014/11/09 19:17:13 miod Exp $ */ | ||
2 | /* | ||
3 | * Copyright (c) 2014 Dmitry Eremin-Solenikov <dbaryshkov@gmail.com> | ||
4 | * Copyright (c) 2005-2006 Cryptocom LTD | ||
5 | * | ||
6 | * Redistribution and use in source and binary forms, with or without | ||
7 | * modification, are permitted provided that the following conditions | ||
8 | * are met: | ||
9 | * | ||
10 | * 1. Redistributions of source code must retain the above copyright | ||
11 | * notice, this list of conditions and the following disclaimer. | ||
12 | * | ||
13 | * 2. Redistributions in binary form must reproduce the above copyright | ||
14 | * notice, this list of conditions and the following disclaimer in | ||
15 | * the documentation and/or other materials provided with the | ||
16 | * distribution. | ||
17 | * | ||
18 | * 3. All advertising materials mentioning features or use of this | ||
19 | * software must display the following acknowledgment: | ||
20 | * "This product includes software developed by the OpenSSL Project | ||
21 | * for use in the OpenSSL Toolkit. (http://www.openssl.org/)" | ||
22 | * | ||
23 | * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to | ||
24 | * endorse or promote products derived from this software without | ||
25 | * prior written permission. For written permission, please contact | ||
26 | * openssl-core@openssl.org. | ||
27 | * | ||
28 | * 5. Products derived from this software may not be called "OpenSSL" | ||
29 | * nor may "OpenSSL" appear in their names without prior written | ||
30 | * permission of the OpenSSL Project. | ||
31 | * | ||
32 | * 6. Redistributions of any form whatsoever must retain the following | ||
33 | * acknowledgment: | ||
34 | * "This product includes software developed by the OpenSSL Project | ||
35 | * for use in the OpenSSL Toolkit (http://www.openssl.org/)" | ||
36 | * | ||
37 | * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY | ||
38 | * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | ||
39 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR | ||
40 | * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR | ||
41 | * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, | ||
42 | * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT | ||
43 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; | ||
44 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | ||
45 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, | ||
46 | * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) | ||
47 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED | ||
48 | * OF THE POSSIBILITY OF SUCH DAMAGE. | ||
49 | * ==================================================================== | ||
50 | */ | ||
51 | |||
52 | #ifndef HEADER_GOST_H | ||
53 | #define HEADER_GOST_H | ||
54 | |||
55 | #include <openssl/opensslconf.h> | ||
56 | |||
57 | #ifdef OPENSSL_NO_GOST | ||
58 | #error GOST is disabled. | ||
59 | #endif | ||
60 | |||
61 | #include <openssl/asn1t.h> | ||
62 | #include <openssl/ec.h> | ||
63 | |||
64 | #ifdef __cplusplus | ||
65 | extern "C" { | ||
66 | #endif | ||
67 | |||
68 | typedef struct gost2814789_key_st { | ||
69 | unsigned int key[8]; | ||
70 | unsigned int k87[256],k65[256],k43[256],k21[256]; | ||
71 | unsigned int count; | ||
72 | unsigned key_meshing : 1; | ||
73 | } GOST2814789_KEY; | ||
74 | |||
75 | int Gost2814789_set_sbox(GOST2814789_KEY *key, int nid); | ||
76 | int Gost2814789_set_key(GOST2814789_KEY *key, | ||
77 | const unsigned char *userKey, const int bits); | ||
78 | void Gost2814789_ecb_encrypt(const unsigned char *in, unsigned char *out, | ||
79 | GOST2814789_KEY *key, const int enc); | ||
80 | void Gost2814789_cfb64_encrypt(const unsigned char *in, unsigned char *out, | ||
81 | size_t length, GOST2814789_KEY *key, | ||
82 | unsigned char *ivec, int *num, const int enc); | ||
83 | void Gost2814789_cnt_encrypt(const unsigned char *in, unsigned char *out, | ||
84 | size_t length, GOST2814789_KEY *key, | ||
85 | unsigned char *ivec, unsigned char *cnt_buf, int *num); | ||
86 | |||
87 | typedef struct { | ||
88 | ASN1_OCTET_STRING *iv; | ||
89 | ASN1_OBJECT *enc_param_set; | ||
90 | } GOST_CIPHER_PARAMS; | ||
91 | |||
92 | DECLARE_ASN1_FUNCTIONS(GOST_CIPHER_PARAMS) | ||
93 | |||
94 | #define GOST2814789IMIT_LENGTH 4 | ||
95 | #define GOST2814789IMIT_CBLOCK 8 | ||
96 | #define GOST2814789IMIT_LONG unsigned int | ||
97 | |||
98 | typedef struct GOST2814789IMITstate_st { | ||
99 | GOST2814789IMIT_LONG Nl, Nh; | ||
100 | unsigned char data[GOST2814789IMIT_CBLOCK]; | ||
101 | unsigned int num; | ||
102 | |||
103 | GOST2814789_KEY cipher; | ||
104 | unsigned char mac[GOST2814789IMIT_CBLOCK]; | ||
105 | } GOST2814789IMIT_CTX; | ||
106 | |||
107 | /* Note, also removed second parameter and removed dctx->cipher setting */ | ||
108 | int GOST2814789IMIT_Init(GOST2814789IMIT_CTX *c, int nid); | ||
109 | int GOST2814789IMIT_Update(GOST2814789IMIT_CTX *c, const void *data, size_t len); | ||
110 | int GOST2814789IMIT_Final(unsigned char *md, GOST2814789IMIT_CTX *c); | ||
111 | void GOST2814789IMIT_Transform(GOST2814789IMIT_CTX *c, const unsigned char *data); | ||
112 | unsigned char *GOST2814789IMIT(const unsigned char *d, size_t n, | ||
113 | unsigned char *md, int nid, | ||
114 | const unsigned char *key, const unsigned char *iv); | ||
115 | |||
116 | #define GOSTR341194_LONG unsigned int | ||
117 | |||
118 | #define GOSTR341194_LENGTH 32 | ||
119 | #define GOSTR341194_CBLOCK 32 | ||
120 | #define GOSTR341194_LBLOCK (GOSTR341194_CBLOCK/4) | ||
121 | |||
122 | typedef struct GOSTR341194state_st { | ||
123 | GOSTR341194_LONG Nl, Nh; | ||
124 | GOSTR341194_LONG data[GOSTR341194_LBLOCK]; | ||
125 | unsigned int num; | ||
126 | |||
127 | GOST2814789_KEY cipher; | ||
128 | unsigned char H[GOSTR341194_CBLOCK]; | ||
129 | unsigned char S[GOSTR341194_CBLOCK]; | ||
130 | } GOSTR341194_CTX; | ||
131 | |||
132 | /* Note, also removed second parameter and removed dctx->cipher setting */ | ||
133 | int GOSTR341194_Init(GOSTR341194_CTX *c, int nid); | ||
134 | int GOSTR341194_Update(GOSTR341194_CTX *c, const void *data, size_t len); | ||
135 | int GOSTR341194_Final(unsigned char *md, GOSTR341194_CTX *c); | ||
136 | void GOSTR341194_Transform(GOSTR341194_CTX *c, const unsigned char *data); | ||
137 | unsigned char *GOSTR341194(const unsigned char *d, size_t n,unsigned char *md, int nid); | ||
138 | |||
139 | #if defined(_LP64) | ||
140 | #define STREEBOG_LONG64 unsigned long | ||
141 | #define U64(C) C##UL | ||
142 | #else | ||
143 | #define STREEBOG_LONG64 unsigned long long | ||
144 | #define U64(C) C##ULL | ||
145 | #endif | ||
146 | |||
147 | #define STREEBOG_LBLOCK 8 | ||
148 | #define STREEBOG_CBLOCK 64 | ||
149 | #define STREEBOG256_LENGTH 32 | ||
150 | #define STREEBOG512_LENGTH 64 | ||
151 | |||
152 | typedef struct STREEBOGstate_st { | ||
153 | STREEBOG_LONG64 data[STREEBOG_LBLOCK]; | ||
154 | unsigned int num; | ||
155 | unsigned int md_len; | ||
156 | STREEBOG_LONG64 h[STREEBOG_LBLOCK]; | ||
157 | STREEBOG_LONG64 N[STREEBOG_LBLOCK]; | ||
158 | STREEBOG_LONG64 Sigma[STREEBOG_LBLOCK]; | ||
159 | } STREEBOG_CTX; | ||
160 | |||
161 | int STREEBOG256_Init(STREEBOG_CTX *c); | ||
162 | int STREEBOG256_Update(STREEBOG_CTX *c, const void *data, size_t len); | ||
163 | int STREEBOG256_Final(unsigned char *md, STREEBOG_CTX *c); | ||
164 | void STREEBOG256_Transform(STREEBOG_CTX *c, const unsigned char *data); | ||
165 | unsigned char *STREEBOG256(const unsigned char *d, size_t n,unsigned char *md); | ||
166 | |||
167 | int STREEBOG512_Init(STREEBOG_CTX *c); | ||
168 | int STREEBOG512_Update(STREEBOG_CTX *c, const void *data, size_t len); | ||
169 | int STREEBOG512_Final(unsigned char *md, STREEBOG_CTX *c); | ||
170 | void STREEBOG512_Transform(STREEBOG_CTX *c, const unsigned char *data); | ||
171 | unsigned char *STREEBOG512(const unsigned char *d, size_t n,unsigned char *md); | ||
172 | |||
173 | typedef struct gost_key_st GOST_KEY; | ||
174 | GOST_KEY *GOST_KEY_new(void); | ||
175 | void GOST_KEY_free(GOST_KEY * r); | ||
176 | int GOST_KEY_check_key(const GOST_KEY * eckey); | ||
177 | int GOST_KEY_set_public_key_affine_coordinates(GOST_KEY * key, BIGNUM * x, BIGNUM * y); | ||
178 | const EC_GROUP * GOST_KEY_get0_group(const GOST_KEY * key); | ||
179 | int GOST_KEY_set_group(GOST_KEY * key, const EC_GROUP * group); | ||
180 | int GOST_KEY_get_digest(const GOST_KEY * key); | ||
181 | int GOST_KEY_set_digest(GOST_KEY * key, int digest_nid); | ||
182 | const BIGNUM * GOST_KEY_get0_private_key(const GOST_KEY * key); | ||
183 | int GOST_KEY_set_private_key(GOST_KEY * key, const BIGNUM * priv_key); | ||
184 | const EC_POINT * GOST_KEY_get0_public_key(const GOST_KEY * key); | ||
185 | int GOST_KEY_set_public_key(GOST_KEY * key, const EC_POINT * pub_key); | ||
186 | size_t GOST_KEY_get_size(const GOST_KEY * r); | ||
187 | |||
188 | /* Gost-specific pmeth control-function parameters */ | ||
189 | /* For GOST R34.10 parameters */ | ||
190 | #define EVP_PKEY_CTRL_GOST_PARAMSET (EVP_PKEY_ALG_CTRL+1) | ||
191 | #define EVP_PKEY_CTRL_GOST_SIG_FORMAT (EVP_PKEY_ALG_CTRL+2) | ||
192 | #define EVP_PKEY_CTRL_GOST_SET_DIGEST (EVP_PKEY_ALG_CTRL+3) | ||
193 | #define EVP_PKEY_CTRL_GOST_GET_DIGEST (EVP_PKEY_ALG_CTRL+4) | ||
194 | |||
195 | #define GOST_SIG_FORMAT_SR_BE 0 | ||
196 | #define GOST_SIG_FORMAT_RS_LE 1 | ||
197 | |||
198 | /* BEGIN ERROR CODES */ | ||
199 | /* The following lines are auto generated by the script mkerr.pl. Any changes | ||
200 | * made after this point may be overwritten when the script is next run. | ||
201 | */ | ||
202 | void ERR_load_GOST_strings(void); | ||
203 | |||
204 | /* Error codes for the GOST functions. */ | ||
205 | |||
206 | /* Function codes. */ | ||
207 | #define GOST_F_DECODE_GOST01_ALGOR_PARAMS 104 | ||
208 | #define GOST_F_ENCODE_GOST01_ALGOR_PARAMS 105 | ||
209 | #define GOST_F_GOST2001_COMPUTE_PUBLIC 106 | ||
210 | #define GOST_F_GOST2001_DO_SIGN 107 | ||
211 | #define GOST_F_GOST2001_DO_VERIFY 108 | ||
212 | #define GOST_F_GOST2001_KEYGEN 109 | ||
213 | #define GOST_F_GOST89_GET_ASN1_PARAMETERS 102 | ||
214 | #define GOST_F_GOST89_SET_ASN1_PARAMETERS 103 | ||
215 | #define GOST_F_GOST_KEY_CHECK_KEY 124 | ||
216 | #define GOST_F_GOST_KEY_NEW 125 | ||
217 | #define GOST_F_GOST_KEY_SET_PUBLIC_KEY_AFFINE_COORDINATES 126 | ||
218 | #define GOST_F_PARAM_COPY_GOST01 110 | ||
219 | #define GOST_F_PARAM_DECODE_GOST01 111 | ||
220 | #define GOST_F_PKEY_GOST01_CTRL 116 | ||
221 | #define GOST_F_PKEY_GOST01_DECRYPT 112 | ||
222 | #define GOST_F_PKEY_GOST01_DERIVE 113 | ||
223 | #define GOST_F_PKEY_GOST01_ENCRYPT 114 | ||
224 | #define GOST_F_PKEY_GOST01_PARAMGEN 115 | ||
225 | #define GOST_F_PKEY_GOST01_SIGN 123 | ||
226 | #define GOST_F_PKEY_GOST_MAC_CTRL 100 | ||
227 | #define GOST_F_PKEY_GOST_MAC_KEYGEN 101 | ||
228 | #define GOST_F_PRIV_DECODE_GOST01 117 | ||
229 | #define GOST_F_PUB_DECODE_GOST01 118 | ||
230 | #define GOST_F_PUB_ENCODE_GOST01 119 | ||
231 | #define GOST_F_PUB_PRINT_GOST01 120 | ||
232 | #define GOST_F_UNPACK_SIGNATURE_CP 121 | ||
233 | #define GOST_F_UNPACK_SIGNATURE_LE 122 | ||
234 | |||
235 | /* Reason codes. */ | ||
236 | #define GOST_R_BAD_KEY_PARAMETERS_FORMAT 104 | ||
237 | #define GOST_R_BAD_PKEY_PARAMETERS_FORMAT 105 | ||
238 | #define GOST_R_CANNOT_PACK_EPHEMERAL_KEY 106 | ||
239 | #define GOST_R_CTRL_CALL_FAILED 107 | ||
240 | #define GOST_R_ERROR_COMPUTING_SHARED_KEY 108 | ||
241 | #define GOST_R_ERROR_PARSING_KEY_TRANSPORT_INFO 109 | ||
242 | #define GOST_R_INCOMPATIBLE_ALGORITHMS 110 | ||
243 | #define GOST_R_INCOMPATIBLE_PEER_KEY 111 | ||
244 | #define GOST_R_INVALID_DIGEST_TYPE 100 | ||
245 | #define GOST_R_INVALID_IV_LENGTH 103 | ||
246 | #define GOST_R_INVALID_MAC_KEY_LENGTH 101 | ||
247 | #define GOST_R_KEY_IS_NOT_INITIALIZED 112 | ||
248 | #define GOST_R_KEY_PARAMETERS_MISSING 113 | ||
249 | #define GOST_R_MAC_KEY_NOT_SET 102 | ||
250 | #define GOST_R_NO_PARAMETERS_SET 115 | ||
251 | #define GOST_R_NO_PEER_KEY 116 | ||
252 | #define GOST_R_NO_PRIVATE_PART_OF_NON_EPHEMERAL_KEYPAIR 117 | ||
253 | #define GOST_R_PUBLIC_KEY_UNDEFINED 118 | ||
254 | #define GOST_R_RANDOM_GENERATOR_FAILURE 119 | ||
255 | #define GOST_R_RANDOM_NUMBER_GENERATOR_FAILED 120 | ||
256 | #define GOST_R_SIGNATURE_MISMATCH 121 | ||
257 | #define GOST_R_SIGNATURE_PARTS_GREATER_THAN_Q 122 | ||
258 | #define GOST_R_UKM_NOT_SET 123 | ||
259 | |||
260 | #ifdef __cplusplus | ||
261 | } | ||
262 | #endif | ||
263 | #endif | ||
diff --git a/src/lib/libcrypto/gost/gost2814789.c b/src/lib/libcrypto/gost/gost2814789.c new file mode 100644 index 0000000000..b80f692f10 --- /dev/null +++ b/src/lib/libcrypto/gost/gost2814789.c | |||
@@ -0,0 +1,453 @@ | |||
1 | /* $OpenBSD: gost2814789.c,v 1.1 2014/11/09 19:17:13 miod Exp $ */ | ||
2 | /* | ||
3 | * Copyright (c) 2014 Dmitry Eremin-Solenikov <dbaryshkov@gmail.com> | ||
4 | * Copyright (c) 2005-2006 Cryptocom LTD | ||
5 | * | ||
6 | * Redistribution and use in source and binary forms, with or without | ||
7 | * modification, are permitted provided that the following conditions | ||
8 | * are met: | ||
9 | * | ||
10 | * 1. Redistributions of source code must retain the above copyright | ||
11 | * notice, this list of conditions and the following disclaimer. | ||
12 | * | ||
13 | * 2. Redistributions in binary form must reproduce the above copyright | ||
14 | * notice, this list of conditions and the following disclaimer in | ||
15 | * the documentation and/or other materials provided with the | ||
16 | * distribution. | ||
17 | * | ||
18 | * 3. All advertising materials mentioning features or use of this | ||
19 | * software must display the following acknowledgment: | ||
20 | * "This product includes software developed by the OpenSSL Project | ||
21 | * for use in the OpenSSL Toolkit. (http://www.openssl.org/)" | ||
22 | * | ||
23 | * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to | ||
24 | * endorse or promote products derived from this software without | ||
25 | * prior written permission. For written permission, please contact | ||
26 | * openssl-core@openssl.org. | ||
27 | * | ||
28 | * 5. Products derived from this software may not be called "OpenSSL" | ||
29 | * nor may "OpenSSL" appear in their names without prior written | ||
30 | * permission of the OpenSSL Project. | ||
31 | * | ||
32 | * 6. Redistributions of any form whatsoever must retain the following | ||
33 | * acknowledgment: | ||
34 | * "This product includes software developed by the OpenSSL Project | ||
35 | * for use in the OpenSSL Toolkit (http://www.openssl.org/)" | ||
36 | * | ||
37 | * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY | ||
38 | * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | ||
39 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR | ||
40 | * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR | ||
41 | * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, | ||
42 | * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT | ||
43 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; | ||
44 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | ||
45 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, | ||
46 | * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) | ||
47 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED | ||
48 | * OF THE POSSIBILITY OF SUCH DAMAGE. | ||
49 | * ==================================================================== | ||
50 | */ | ||
51 | |||
52 | #include <string.h> | ||
53 | |||
54 | #include <openssl/opensslconf.h> | ||
55 | |||
56 | #ifndef OPENSSL_NO_GOST | ||
57 | #include <openssl/objects.h> | ||
58 | #include <openssl/gost.h> | ||
59 | |||
60 | #include "gost_locl.h" | ||
61 | |||
62 | static inline unsigned int f(const GOST2814789_KEY *c, unsigned int x) | ||
63 | { | ||
64 | return c->k87[(x>>24) & 255] | c->k65[(x>>16) & 255]| | ||
65 | c->k43[(x>> 8) & 255] | c->k21[(x ) & 255]; | ||
66 | } | ||
67 | |||
68 | void Gost2814789_encrypt(const unsigned char *in, unsigned char *out, | ||
69 | const GOST2814789_KEY *key) | ||
70 | { | ||
71 | unsigned int n1, n2; /* As named in the GOST */ | ||
72 | c2l(in, n1); | ||
73 | c2l(in, n2); | ||
74 | |||
75 | /* Instead of swapping halves, swap names each round */ | ||
76 | n2 ^= f(key, n1 + key->key[0]); n1 ^= f(key, n2 + key->key[1]); | ||
77 | n2 ^= f(key, n1 + key->key[2]); n1 ^= f(key, n2 + key->key[3]); | ||
78 | n2 ^= f(key, n1 + key->key[4]); n1 ^= f(key, n2 + key->key[5]); | ||
79 | n2 ^= f(key, n1 + key->key[6]); n1 ^= f(key, n2 + key->key[7]); | ||
80 | |||
81 | n2 ^= f(key, n1 + key->key[0]); n1 ^= f(key, n2 + key->key[1]); | ||
82 | n2 ^= f(key, n1 + key->key[2]); n1 ^= f(key, n2 + key->key[3]); | ||
83 | n2 ^= f(key, n1 + key->key[4]); n1 ^= f(key, n2 + key->key[5]); | ||
84 | n2 ^= f(key, n1 + key->key[6]); n1 ^= f(key, n2 + key->key[7]); | ||
85 | |||
86 | n2 ^= f(key, n1 + key->key[0]); n1 ^= f(key, n2 + key->key[1]); | ||
87 | n2 ^= f(key, n1 + key->key[2]); n1 ^= f(key, n2 + key->key[3]); | ||
88 | n2 ^= f(key, n1 + key->key[4]); n1 ^= f(key, n2 + key->key[5]); | ||
89 | n2 ^= f(key, n1 + key->key[6]); n1 ^= f(key, n2 + key->key[7]); | ||
90 | |||
91 | n2 ^= f(key, n1 + key->key[7]); n1 ^= f(key, n2 + key->key[6]); | ||
92 | n2 ^= f(key, n1 + key->key[5]); n1 ^= f(key, n2 + key->key[4]); | ||
93 | n2 ^= f(key, n1 + key->key[3]); n1 ^= f(key, n2 + key->key[2]); | ||
94 | n2 ^= f(key, n1 + key->key[1]); n1 ^= f(key, n2 + key->key[0]); | ||
95 | |||
96 | l2c(n2, out); | ||
97 | l2c(n1, out); | ||
98 | } | ||
99 | |||
100 | void Gost2814789_decrypt(const unsigned char *in, unsigned char *out, | ||
101 | const GOST2814789_KEY *key) | ||
102 | { | ||
103 | unsigned int n1, n2; /* As named in the GOST */ | ||
104 | c2l(in, n1); | ||
105 | c2l(in, n2); | ||
106 | |||
107 | /* Instead of swapping halves, swap names each round */ | ||
108 | n2 ^= f(key, n1 + key->key[0]); n1 ^= f(key, n2 + key->key[1]); | ||
109 | n2 ^= f(key, n1 + key->key[2]); n1 ^= f(key, n2 + key->key[3]); | ||
110 | n2 ^= f(key, n1 + key->key[4]); n1 ^= f(key, n2 + key->key[5]); | ||
111 | n2 ^= f(key, n1 + key->key[6]); n1 ^= f(key, n2 + key->key[7]); | ||
112 | |||
113 | n2 ^= f(key, n1 + key->key[7]); n1 ^= f(key, n2 + key->key[6]); | ||
114 | n2 ^= f(key, n1 + key->key[5]); n1 ^= f(key, n2 + key->key[4]); | ||
115 | n2 ^= f(key, n1 + key->key[3]); n1 ^= f(key, n2 + key->key[2]); | ||
116 | n2 ^= f(key, n1 + key->key[1]); n1 ^= f(key, n2 + key->key[0]); | ||
117 | |||
118 | n2 ^= f(key, n1 + key->key[7]); n1 ^= f(key, n2 + key->key[6]); | ||
119 | n2 ^= f(key, n1 + key->key[5]); n1 ^= f(key, n2 + key->key[4]); | ||
120 | n2 ^= f(key, n1 + key->key[3]); n1 ^= f(key, n2 + key->key[2]); | ||
121 | n2 ^= f(key, n1 + key->key[1]); n1 ^= f(key, n2 + key->key[0]); | ||
122 | |||
123 | n2 ^= f(key, n1 + key->key[7]); n1 ^= f(key, n2 + key->key[6]); | ||
124 | n2 ^= f(key, n1 + key->key[5]); n1 ^= f(key, n2 + key->key[4]); | ||
125 | n2 ^= f(key, n1 + key->key[3]); n1 ^= f(key, n2 + key->key[2]); | ||
126 | n2 ^= f(key, n1 + key->key[1]); n1 ^= f(key, n2 + key->key[0]); | ||
127 | |||
128 | l2c(n2, out); | ||
129 | l2c(n1, out); | ||
130 | } | ||
131 | |||
132 | static void Gost2814789_mac(const unsigned char *in, | ||
133 | unsigned char *mac, | ||
134 | GOST2814789_KEY *key) | ||
135 | { | ||
136 | unsigned int n1, n2; /* As named in the GOST */ | ||
137 | unsigned char *p; | ||
138 | int i; | ||
139 | |||
140 | for (i = 0; i < 8; i++) | ||
141 | mac[i] ^= in[i]; | ||
142 | |||
143 | p = mac; | ||
144 | c2l(p, n1); | ||
145 | c2l(p, n2); | ||
146 | |||
147 | /* Instead of swapping halves, swap names each round */ | ||
148 | n2 ^= f(key, n1 + key->key[0]); n1 ^= f(key, n2 + key->key[1]); | ||
149 | n2 ^= f(key, n1 + key->key[2]); n1 ^= f(key, n2 + key->key[3]); | ||
150 | n2 ^= f(key, n1 + key->key[4]); n1 ^= f(key, n2 + key->key[5]); | ||
151 | n2 ^= f(key, n1 + key->key[6]); n1 ^= f(key, n2 + key->key[7]); | ||
152 | |||
153 | n2 ^= f(key, n1 + key->key[0]); n1 ^= f(key, n2 + key->key[1]); | ||
154 | n2 ^= f(key, n1 + key->key[2]); n1 ^= f(key, n2 + key->key[3]); | ||
155 | n2 ^= f(key, n1 + key->key[4]); n1 ^= f(key, n2 + key->key[5]); | ||
156 | n2 ^= f(key, n1 + key->key[6]); n1 ^= f(key, n2 + key->key[7]); | ||
157 | |||
158 | p = mac; | ||
159 | l2c(n1, p); | ||
160 | l2c(n2, p); | ||
161 | } | ||
162 | |||
163 | |||
164 | void Gost2814789_ecb_encrypt(const unsigned char *in, unsigned char *out, | ||
165 | GOST2814789_KEY *key, const int enc) | ||
166 | { | ||
167 | if (key->key_meshing && key->count == 1024) { | ||
168 | Gost2814789_cryptopro_key_mesh(key); | ||
169 | key->count = 0; | ||
170 | } | ||
171 | |||
172 | if (enc) | ||
173 | Gost2814789_encrypt(in, out, key); | ||
174 | else | ||
175 | Gost2814789_decrypt(in, out, key); | ||
176 | } | ||
177 | |||
178 | static inline void Gost2814789_encrypt_mesh(unsigned char *iv, GOST2814789_KEY *key) | ||
179 | { | ||
180 | if (key->key_meshing && key->count == 1024) { | ||
181 | Gost2814789_cryptopro_key_mesh(key); | ||
182 | Gost2814789_encrypt(iv, iv, key); | ||
183 | key->count = 0; | ||
184 | } | ||
185 | Gost2814789_encrypt(iv, iv, key); | ||
186 | key->count += 8; | ||
187 | } | ||
188 | |||
189 | static inline void Gost2814789_mac_mesh(const unsigned char *data, | ||
190 | unsigned char *mac, | ||
191 | GOST2814789_KEY *key) | ||
192 | { | ||
193 | if (key->key_meshing && key->count == 1024) { | ||
194 | Gost2814789_cryptopro_key_mesh(key); | ||
195 | key->count = 0; | ||
196 | } | ||
197 | Gost2814789_mac(data, mac, key); | ||
198 | key->count += 8; | ||
199 | } | ||
200 | |||
201 | void Gost2814789_cfb64_encrypt(const unsigned char *in, unsigned char *out, | ||
202 | size_t len, GOST2814789_KEY *key, | ||
203 | unsigned char *ivec, int *num, const int enc) | ||
204 | { | ||
205 | unsigned int n; | ||
206 | size_t l = 0; | ||
207 | |||
208 | OPENSSL_assert(in && out && key && ivec && num); | ||
209 | |||
210 | n = *num; | ||
211 | |||
212 | if (enc) { | ||
213 | #if !defined(OPENSSL_SMALL_FOOTPRINT) | ||
214 | if (8%sizeof(size_t) == 0) do { /* always true actually */ | ||
215 | while (n && len) { | ||
216 | *(out++) = ivec[n] ^= *(in++); | ||
217 | --len; | ||
218 | n = (n+1) % 8; | ||
219 | } | ||
220 | #ifdef __STRICT_ALIGNMENT | ||
221 | if (((size_t)in|(size_t)out|(size_t)ivec)%sizeof(size_t) != 0) | ||
222 | break; | ||
223 | #endif | ||
224 | while (len>=8) { | ||
225 | Gost2814789_encrypt_mesh(ivec, key); | ||
226 | for (; n<8; n+=sizeof(size_t)) { | ||
227 | *(size_t*)(out+n) = | ||
228 | *(size_t*)(ivec+n) ^= *(size_t*)(in+n); | ||
229 | } | ||
230 | len -= 8; | ||
231 | out += 8; | ||
232 | in += 8; | ||
233 | n = 0; | ||
234 | } | ||
235 | if (len) { | ||
236 | Gost2814789_encrypt_mesh(ivec, key); | ||
237 | while (len--) { | ||
238 | out[n] = ivec[n] ^= in[n]; | ||
239 | ++n; | ||
240 | } | ||
241 | } | ||
242 | *num = n; | ||
243 | return; | ||
244 | } while (0); | ||
245 | /* the rest would be commonly eliminated by x86* compiler */ | ||
246 | #endif | ||
247 | while (l<len) { | ||
248 | if (n == 0) { | ||
249 | Gost2814789_encrypt_mesh(ivec, key); | ||
250 | } | ||
251 | out[l] = ivec[n] ^= in[l]; | ||
252 | ++l; | ||
253 | n = (n+1) % 8; | ||
254 | } | ||
255 | *num = n; | ||
256 | } else { | ||
257 | #if !defined(OPENSSL_SMALL_FOOTPRINT) | ||
258 | if (8%sizeof(size_t) == 0) do { /* always true actually */ | ||
259 | while (n && len) { | ||
260 | unsigned char c; | ||
261 | *(out++) = ivec[n] ^ (c = *(in++)); ivec[n] = c; | ||
262 | --len; | ||
263 | n = (n+1) % 8; | ||
264 | } | ||
265 | #ifdef __STRICT_ALIGNMENT | ||
266 | if (((size_t)in|(size_t)out|(size_t)ivec)%sizeof(size_t) != 0) | ||
267 | break; | ||
268 | #endif | ||
269 | while (len>=8) { | ||
270 | Gost2814789_encrypt_mesh(ivec, key); | ||
271 | for (; n<8; n+=sizeof(size_t)) { | ||
272 | size_t t = *(size_t*)(in+n); | ||
273 | *(size_t*)(out+n) = *(size_t*)(ivec+n) ^ t; | ||
274 | *(size_t*)(ivec+n) = t; | ||
275 | } | ||
276 | len -= 8; | ||
277 | out += 8; | ||
278 | in += 8; | ||
279 | n = 0; | ||
280 | } | ||
281 | if (len) { | ||
282 | Gost2814789_encrypt_mesh(ivec, key); | ||
283 | while (len--) { | ||
284 | unsigned char c; | ||
285 | out[n] = ivec[n] ^ (c = in[n]); ivec[n] = c; | ||
286 | ++n; | ||
287 | } | ||
288 | } | ||
289 | *num = n; | ||
290 | return; | ||
291 | } while (0); | ||
292 | /* the rest would be commonly eliminated by x86* compiler */ | ||
293 | #endif | ||
294 | while (l<len) { | ||
295 | unsigned char c; | ||
296 | if (n == 0) { | ||
297 | Gost2814789_encrypt_mesh(ivec, key); | ||
298 | } | ||
299 | out[l] = ivec[n] ^ (c = in[l]); ivec[n] = c; | ||
300 | ++l; | ||
301 | n = (n+1) % 8; | ||
302 | } | ||
303 | *num=n; | ||
304 | } | ||
305 | } | ||
306 | |||
307 | static inline void Gost2814789_cnt_next(unsigned char *ivec, | ||
308 | unsigned char *out, | ||
309 | GOST2814789_KEY *key) | ||
310 | { | ||
311 | unsigned char *p = ivec, *p2 = ivec; | ||
312 | unsigned int val, val2; | ||
313 | |||
314 | if (key->count == 0) | ||
315 | Gost2814789_encrypt(ivec, ivec, key); | ||
316 | |||
317 | if (key->key_meshing && key->count == 1024) { | ||
318 | Gost2814789_cryptopro_key_mesh(key); | ||
319 | Gost2814789_encrypt(ivec, ivec, key); | ||
320 | key->count = 0; | ||
321 | } | ||
322 | |||
323 | c2l(p, val); | ||
324 | val2 = val + 0x01010101; | ||
325 | l2c(val2, p2); | ||
326 | |||
327 | c2l(p, val); | ||
328 | val2 = val + 0x01010104; | ||
329 | if (val > val2) /* overflow */ | ||
330 | val2++; | ||
331 | l2c(val2, p2); | ||
332 | |||
333 | Gost2814789_encrypt(ivec, out, key); | ||
334 | key->count += 8; | ||
335 | } | ||
336 | |||
337 | void Gost2814789_cnt_encrypt(const unsigned char *in, unsigned char *out, | ||
338 | size_t len, GOST2814789_KEY *key, | ||
339 | unsigned char *ivec, unsigned char *cnt_buf, int *num) | ||
340 | { | ||
341 | unsigned int n; | ||
342 | size_t l=0; | ||
343 | |||
344 | OPENSSL_assert(in && out && key && cnt_buf && num); | ||
345 | |||
346 | n = *num; | ||
347 | |||
348 | #if !defined(OPENSSL_SMALL_FOOTPRINT) | ||
349 | if (8%sizeof(size_t) == 0) do { /* always true actually */ | ||
350 | while (n && len) { | ||
351 | *(out++) = *(in++) ^ cnt_buf[n]; | ||
352 | --len; | ||
353 | n = (n+1) % 8; | ||
354 | } | ||
355 | |||
356 | #ifdef __STRICT_ALIGNMENT | ||
357 | if (((size_t)in|(size_t)out|(size_t)ivec)%sizeof(size_t) != 0) | ||
358 | break; | ||
359 | #endif | ||
360 | while (len>=8) { | ||
361 | Gost2814789_cnt_next(ivec, cnt_buf, key); | ||
362 | for (; n<8; n+=sizeof(size_t)) | ||
363 | *(size_t *)(out+n) = | ||
364 | *(size_t *)(in+n) ^ *(size_t *)(cnt_buf+n); | ||
365 | len -= 8; | ||
366 | out += 8; | ||
367 | in += 8; | ||
368 | n = 0; | ||
369 | } | ||
370 | if (len) { | ||
371 | Gost2814789_cnt_next(ivec, cnt_buf, key); | ||
372 | while (len--) { | ||
373 | out[n] = in[n] ^ cnt_buf[n]; | ||
374 | ++n; | ||
375 | } | ||
376 | } | ||
377 | *num = n; | ||
378 | return; | ||
379 | } while(0); | ||
380 | /* the rest would be commonly eliminated by x86* compiler */ | ||
381 | #endif | ||
382 | while (l<len) { | ||
383 | if (n==0) | ||
384 | Gost2814789_cnt_next(ivec, cnt_buf, key); | ||
385 | out[l] = in[l] ^ cnt_buf[n]; | ||
386 | ++l; | ||
387 | n = (n+1) % 8; | ||
388 | } | ||
389 | |||
390 | *num=n; | ||
391 | } | ||
392 | |||
393 | int GOST2814789IMIT_Init(GOST2814789IMIT_CTX *c, int nid) | ||
394 | { | ||
395 | c->Nl = c->Nh = c->num = 0; | ||
396 | memset(c->mac, 0, 8); | ||
397 | return Gost2814789_set_sbox(&c->cipher, nid); | ||
398 | } | ||
399 | |||
400 | static void GOST2814789IMIT_block_data_order(GOST2814789IMIT_CTX *ctx, const void *p, size_t num) | ||
401 | { | ||
402 | int i; | ||
403 | for (i = 0; i < num; i++) { | ||
404 | Gost2814789_mac_mesh(p, ctx->mac, &ctx->cipher); | ||
405 | p += 8; | ||
406 | } | ||
407 | } | ||
408 | |||
409 | #define DATA_ORDER_IS_LITTLE_ENDIAN | ||
410 | |||
411 | #define HASH_CBLOCK GOST2814789IMIT_CBLOCK | ||
412 | #define HASH_LONG GOST2814789IMIT_LONG | ||
413 | #define HASH_CTX GOST2814789IMIT_CTX | ||
414 | #define HASH_UPDATE GOST2814789IMIT_Update | ||
415 | #define HASH_TRANSFORM GOST2814789IMIT_Transform | ||
416 | #define HASH_NO_FINAL 1 | ||
417 | #define HASH_BLOCK_DATA_ORDER GOST2814789IMIT_block_data_order | ||
418 | |||
419 | #include "md32_common.h" | ||
420 | |||
421 | int GOST2814789IMIT_Final(unsigned char *md, GOST2814789IMIT_CTX *c) | ||
422 | { | ||
423 | if (c->num) { | ||
424 | memset(c->data + c->num, 0, 8 - c->num); | ||
425 | Gost2814789_mac_mesh(c->data, c->mac, &c->cipher); | ||
426 | } | ||
427 | if (c->Nl <= 8 * 8 && c->Nl > 0 && c->Nh == 0) { | ||
428 | memset(c->data, 0, 8); | ||
429 | Gost2814789_mac_mesh(c->data, c->mac, &c->cipher); | ||
430 | } | ||
431 | memcpy(md, c->mac, 4); | ||
432 | return 1; | ||
433 | } | ||
434 | |||
435 | unsigned char *GOST2814789IMIT(const unsigned char *d, size_t n, | ||
436 | unsigned char *md, int nid, | ||
437 | const unsigned char *key, const unsigned char *iv) | ||
438 | { | ||
439 | GOST2814789IMIT_CTX c; | ||
440 | static unsigned char m[GOST2814789IMIT_LENGTH]; | ||
441 | |||
442 | if (md == NULL) | ||
443 | md = m; | ||
444 | GOST2814789IMIT_Init(&c, nid); | ||
445 | memcpy(c.mac, iv, 8); | ||
446 | Gost2814789_set_key(&c.cipher, key, 256); | ||
447 | GOST2814789IMIT_Update(&c, d, n); | ||
448 | GOST2814789IMIT_Final(md, &c); | ||
449 | OPENSSL_cleanse(&c, sizeof(c)); | ||
450 | return (md); | ||
451 | } | ||
452 | |||
453 | #endif | ||
diff --git a/src/lib/libcrypto/gost/gost89_keywrap.c b/src/lib/libcrypto/gost/gost89_keywrap.c new file mode 100644 index 0000000000..8f641b6cef --- /dev/null +++ b/src/lib/libcrypto/gost/gost89_keywrap.c | |||
@@ -0,0 +1,136 @@ | |||
1 | /* $OpenBSD: gost89_keywrap.c,v 1.1 2014/11/09 19:17:13 miod Exp $ */ | ||
2 | /* | ||
3 | * Copyright (c) 2014 Dmitry Eremin-Solenikov <dbaryshkov@gmail.com> | ||
4 | * Copyright (c) 2005-2006 Cryptocom LTD | ||
5 | * | ||
6 | * Redistribution and use in source and binary forms, with or without | ||
7 | * modification, are permitted provided that the following conditions | ||
8 | * are met: | ||
9 | * | ||
10 | * 1. Redistributions of source code must retain the above copyright | ||
11 | * notice, this list of conditions and the following disclaimer. | ||
12 | * | ||
13 | * 2. Redistributions in binary form must reproduce the above copyright | ||
14 | * notice, this list of conditions and the following disclaimer in | ||
15 | * the documentation and/or other materials provided with the | ||
16 | * distribution. | ||
17 | * | ||
18 | * 3. All advertising materials mentioning features or use of this | ||
19 | * software must display the following acknowledgment: | ||
20 | * "This product includes software developed by the OpenSSL Project | ||
21 | * for use in the OpenSSL Toolkit. (http://www.openssl.org/)" | ||
22 | * | ||
23 | * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to | ||
24 | * endorse or promote products derived from this software without | ||
25 | * prior written permission. For written permission, please contact | ||
26 | * openssl-core@openssl.org. | ||
27 | * | ||
28 | * 5. Products derived from this software may not be called "OpenSSL" | ||
29 | * nor may "OpenSSL" appear in their names without prior written | ||
30 | * permission of the OpenSSL Project. | ||
31 | * | ||
32 | * 6. Redistributions of any form whatsoever must retain the following | ||
33 | * acknowledgment: | ||
34 | * "This product includes software developed by the OpenSSL Project | ||
35 | * for use in the OpenSSL Toolkit (http://www.openssl.org/)" | ||
36 | * | ||
37 | * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY | ||
38 | * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | ||
39 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR | ||
40 | * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR | ||
41 | * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, | ||
42 | * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT | ||
43 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; | ||
44 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | ||
45 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, | ||
46 | * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) | ||
47 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED | ||
48 | * OF THE POSSIBILITY OF SUCH DAMAGE. | ||
49 | * ==================================================================== | ||
50 | */ | ||
51 | |||
52 | #include <string.h> | ||
53 | |||
54 | #include <openssl/opensslconf.h> | ||
55 | |||
56 | #ifndef OPENSSL_NO_GOST | ||
57 | |||
58 | #include <openssl/gost.h> | ||
59 | |||
60 | #include "gost_locl.h" | ||
61 | |||
62 | static void key_diversify_crypto_pro(GOST2814789_KEY * ctx, const unsigned char *inputKey, | ||
63 | const unsigned char *ukm, unsigned char *outputKey) | ||
64 | { | ||
65 | |||
66 | unsigned long k, s1, s2; | ||
67 | int i, mask; | ||
68 | unsigned char S[8]; | ||
69 | unsigned char *p; | ||
70 | memcpy(outputKey, inputKey, 32); | ||
71 | for (i = 0; i < 8; i++) { | ||
72 | /* Make array of integers from key */ | ||
73 | /* Compute IV S */ | ||
74 | s1 = 0, s2 = 0; | ||
75 | p = outputKey; | ||
76 | for (mask = 1; mask < 256; mask <<= 1) { | ||
77 | c2l(p, k); | ||
78 | if (mask & ukm[i]) { | ||
79 | s1 += k; | ||
80 | } else { | ||
81 | s2 += k; | ||
82 | } | ||
83 | } | ||
84 | p = S; | ||
85 | l2c (s1, p); | ||
86 | l2c (s2, p); | ||
87 | Gost2814789_set_key(ctx, outputKey, 256); | ||
88 | mask = 0; | ||
89 | Gost2814789_cfb64_encrypt(outputKey, outputKey, 32, ctx, S, &mask, 1); | ||
90 | } | ||
91 | } | ||
92 | |||
93 | int key_wrap_crypto_pro(int nid, const unsigned char *keyExchangeKey, | ||
94 | const unsigned char *ukm, const unsigned char *sessionKey, | ||
95 | unsigned char *wrappedKey) | ||
96 | { | ||
97 | GOST2814789_KEY ctx; | ||
98 | unsigned char kek_ukm[32]; | ||
99 | |||
100 | Gost2814789_set_sbox(&ctx, nid); | ||
101 | key_diversify_crypto_pro(&ctx, keyExchangeKey, ukm, kek_ukm); | ||
102 | Gost2814789_set_key(&ctx, kek_ukm, 256); | ||
103 | memcpy(wrappedKey, ukm, 8); | ||
104 | Gost2814789_encrypt(sessionKey + 0, wrappedKey + 8 + 0, &ctx); | ||
105 | Gost2814789_encrypt(sessionKey + 8, wrappedKey + 8 + 8, &ctx); | ||
106 | Gost2814789_encrypt(sessionKey + 16, wrappedKey + 8 + 16, &ctx); | ||
107 | Gost2814789_encrypt(sessionKey + 24, wrappedKey + 8 + 24, &ctx); | ||
108 | GOST2814789IMIT(sessionKey, 32, wrappedKey + 40, nid, kek_ukm, ukm); | ||
109 | return 1; | ||
110 | } | ||
111 | |||
112 | int key_unwrap_crypto_pro(int nid, const unsigned char *keyExchangeKey, | ||
113 | const unsigned char *wrappedKey, | ||
114 | unsigned char *sessionKey) | ||
115 | { | ||
116 | unsigned char kek_ukm[32], cek_mac[4]; | ||
117 | GOST2814789_KEY ctx; | ||
118 | |||
119 | Gost2814789_set_sbox(&ctx, nid); | ||
120 | /* First 8 bytes of wrapped Key is ukm */ | ||
121 | key_diversify_crypto_pro(&ctx, keyExchangeKey, wrappedKey, kek_ukm); | ||
122 | Gost2814789_set_key(&ctx, kek_ukm, 256); | ||
123 | Gost2814789_decrypt(wrappedKey + 8 + 0, sessionKey + 0, &ctx); | ||
124 | Gost2814789_decrypt(wrappedKey + 8 + 8, sessionKey + 8, &ctx); | ||
125 | Gost2814789_decrypt(wrappedKey + 8 + 16, sessionKey + 16, &ctx); | ||
126 | Gost2814789_decrypt(wrappedKey + 8 + 24, sessionKey + 24, &ctx); | ||
127 | |||
128 | GOST2814789IMIT(sessionKey, 32, cek_mac, nid, kek_ukm, wrappedKey); | ||
129 | if (memcmp(cek_mac, wrappedKey + 40, 4)) { | ||
130 | printf("IMIT Missmatch!\n"); | ||
131 | return 0; | ||
132 | } | ||
133 | return 1; | ||
134 | } | ||
135 | |||
136 | #endif | ||
diff --git a/src/lib/libcrypto/gost/gost89_params.c b/src/lib/libcrypto/gost/gost89_params.c new file mode 100644 index 0000000000..2b2607d24b --- /dev/null +++ b/src/lib/libcrypto/gost/gost89_params.c | |||
@@ -0,0 +1,241 @@ | |||
1 | /* $OpenBSD: gost89_params.c,v 1.1 2014/11/09 19:17:13 miod Exp $ */ | ||
2 | /* | ||
3 | * Copyright (c) 2014 Dmitry Eremin-Solenikov <dbaryshkov@gmail.com> | ||
4 | * Copyright (c) 2005-2006 Cryptocom LTD | ||
5 | * | ||
6 | * Redistribution and use in source and binary forms, with or without | ||
7 | * modification, are permitted provided that the following conditions | ||
8 | * are met: | ||
9 | * | ||
10 | * 1. Redistributions of source code must retain the above copyright | ||
11 | * notice, this list of conditions and the following disclaimer. | ||
12 | * | ||
13 | * 2. Redistributions in binary form must reproduce the above copyright | ||
14 | * notice, this list of conditions and the following disclaimer in | ||
15 | * the documentation and/or other materials provided with the | ||
16 | * distribution. | ||
17 | * | ||
18 | * 3. All advertising materials mentioning features or use of this | ||
19 | * software must display the following acknowledgment: | ||
20 | * "This product includes software developed by the OpenSSL Project | ||
21 | * for use in the OpenSSL Toolkit. (http://www.openssl.org/)" | ||
22 | * | ||
23 | * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to | ||
24 | * endorse or promote products derived from this software without | ||
25 | * prior written permission. For written permission, please contact | ||
26 | * openssl-core@openssl.org. | ||
27 | * | ||
28 | * 5. Products derived from this software may not be called "OpenSSL" | ||
29 | * nor may "OpenSSL" appear in their names without prior written | ||
30 | * permission of the OpenSSL Project. | ||
31 | * | ||
32 | * 6. Redistributions of any form whatsoever must retain the following | ||
33 | * acknowledgment: | ||
34 | * "This product includes software developed by the OpenSSL Project | ||
35 | * for use in the OpenSSL Toolkit (http://www.openssl.org/)" | ||
36 | * | ||
37 | * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY | ||
38 | * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | ||
39 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR | ||
40 | * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR | ||
41 | * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, | ||
42 | * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT | ||
43 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; | ||
44 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | ||
45 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, | ||
46 | * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) | ||
47 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED | ||
48 | * OF THE POSSIBILITY OF SUCH DAMAGE. | ||
49 | * ==================================================================== | ||
50 | */ | ||
51 | |||
52 | #include <stdlib.h> | ||
53 | |||
54 | #include <openssl/opensslconf.h> | ||
55 | |||
56 | #ifndef OPENSSL_NO_GOST | ||
57 | #include <openssl/objects.h> | ||
58 | #include <openssl/gost.h> | ||
59 | |||
60 | #include "gost_locl.h" | ||
61 | |||
62 | /* Substitution blocks from test examples for GOST R 34.11-94*/ | ||
63 | static const gost_subst_block GostR3411_94_TestParamSet = { | ||
64 | {0x1,0xF,0xD,0x0,0x5,0x7,0xA,0x4,0x9,0x2,0x3,0xE,0x6,0xB,0x8,0xC}, | ||
65 | {0xD,0xB,0x4,0x1,0x3,0xF,0x5,0x9,0x0,0xA,0xE,0x7,0x6,0x8,0x2,0xC}, | ||
66 | {0x4,0xB,0xA,0x0,0x7,0x2,0x1,0xD,0x3,0x6,0x8,0x5,0x9,0xC,0xF,0xE}, | ||
67 | {0x6,0xC,0x7,0x1,0x5,0xF,0xD,0x8,0x4,0xA,0x9,0xE,0x0,0x3,0xB,0x2}, | ||
68 | {0x7,0xD,0xA,0x1,0x0,0x8,0x9,0xF,0xE,0x4,0x6,0xC,0xB,0x2,0x5,0x3}, | ||
69 | {0x5,0x8,0x1,0xD,0xA,0x3,0x4,0x2,0xE,0xF,0xC,0x7,0x6,0x0,0x9,0xB}, | ||
70 | {0xE,0xB,0x4,0xC,0x6,0xD,0xF,0xA,0x2,0x3,0x8,0x1,0x0,0x7,0x5,0x9}, | ||
71 | {0x4,0xA,0x9,0x2,0xD,0x8,0x0,0xE,0x6,0xB,0x1,0xC,0x7,0xF,0x5,0x3} | ||
72 | }; | ||
73 | |||
74 | /* Substitution blocks for hash function 1.2.643.2.9.1.6.1 */ | ||
75 | static const gost_subst_block GostR3411_94_CryptoProParamSet = { | ||
76 | {0x1,0x3,0xA,0x9,0x5,0xB,0x4,0xF,0x8,0x6,0x7,0xE,0xD,0x0,0x2,0xC}, | ||
77 | {0xD,0xE,0x4,0x1,0x7,0x0,0x5,0xA,0x3,0xC,0x8,0xF,0x6,0x2,0x9,0xB}, | ||
78 | {0x7,0x6,0x2,0x4,0xD,0x9,0xF,0x0,0xA,0x1,0x5,0xB,0x8,0xE,0xC,0x3}, | ||
79 | {0x7,0x6,0x4,0xB,0x9,0xC,0x2,0xA,0x1,0x8,0x0,0xE,0xF,0xD,0x3,0x5}, | ||
80 | {0x4,0xA,0x7,0xC,0x0,0xF,0x2,0x8,0xE,0x1,0x6,0x5,0xD,0xB,0x9,0x3}, | ||
81 | {0x7,0xF,0xC,0xE,0x9,0x4,0x1,0x0,0x3,0xB,0x5,0x2,0x6,0xA,0x8,0xD}, | ||
82 | {0x5,0xF,0x4,0x0,0x2,0xD,0xB,0x9,0x1,0x7,0x6,0x3,0xC,0xE,0xA,0x8}, | ||
83 | {0xA,0x4,0x5,0x6,0x8,0x1,0x3,0x7,0xD,0xC,0xE,0x0,0x9,0x2,0xB,0xF} | ||
84 | }; | ||
85 | |||
86 | /* Test paramset from GOST 28147 */ | ||
87 | gost_subst_block Gost28147_TestParamSet = { | ||
88 | {0xC,0x6,0x5,0x2,0xB,0x0,0x9,0xD,0x3,0xE,0x7,0xA,0xF,0x4,0x1,0x8}, | ||
89 | {0x9,0xB,0xC,0x0,0x3,0x6,0x7,0x5,0x4,0x8,0xE,0xF,0x1,0xA,0x2,0xD}, | ||
90 | {0x8,0xF,0x6,0xB,0x1,0x9,0xC,0x5,0xD,0x3,0x7,0xA,0x0,0xE,0x2,0x4}, | ||
91 | {0x3,0xE,0x5,0x9,0x6,0x8,0x0,0xD,0xA,0xB,0x7,0xC,0x2,0x1,0xF,0x4}, | ||
92 | {0xE,0x9,0xB,0x2,0x5,0xF,0x7,0x1,0x0,0xD,0xC,0x6,0xA,0x4,0x3,0x8}, | ||
93 | {0xD,0x8,0xE,0xC,0x7,0x3,0x9,0xA,0x1,0x5,0x2,0x4,0x6,0xF,0x0,0xB}, | ||
94 | {0xC,0x9,0xF,0xE,0x8,0x1,0x3,0xA,0x2,0x7,0x4,0xD,0x6,0x0,0xB,0x5}, | ||
95 | {0x4,0x2,0xF,0x5,0x9,0x1,0x0,0x8,0xE,0x3,0xB,0xC,0xD,0x7,0xA,0x6} | ||
96 | }; | ||
97 | |||
98 | |||
99 | /* 1.2.643.2.2.31.1 */ | ||
100 | static const gost_subst_block Gost28147_CryptoProParamSetA = { | ||
101 | {0xB,0xA,0xF,0x5,0x0,0xC,0xE,0x8,0x6,0x2,0x3,0x9,0x1,0x7,0xD,0x4}, | ||
102 | {0x1,0xD,0x2,0x9,0x7,0xA,0x6,0x0,0x8,0xC,0x4,0x5,0xF,0x3,0xB,0xE}, | ||
103 | {0x3,0xA,0xD,0xC,0x1,0x2,0x0,0xB,0x7,0x5,0x9,0x4,0x8,0xF,0xE,0x6}, | ||
104 | {0xB,0x5,0x1,0x9,0x8,0xD,0xF,0x0,0xE,0x4,0x2,0x3,0xC,0x7,0xA,0x6}, | ||
105 | {0xE,0x7,0xA,0xC,0xD,0x1,0x3,0x9,0x0,0x2,0xB,0x4,0xF,0x8,0x5,0x6}, | ||
106 | {0xE,0x4,0x6,0x2,0xB,0x3,0xD,0x8,0xC,0xF,0x5,0xA,0x0,0x7,0x1,0x9}, | ||
107 | {0x3,0x7,0xE,0x9,0x8,0xA,0xF,0x0,0x5,0x2,0x6,0xC,0xB,0x4,0xD,0x1}, | ||
108 | {0x9,0x6,0x3,0x2,0x8,0xB,0x1,0x7,0xA,0x4,0xE,0xF,0xC,0x0,0xD,0x5} | ||
109 | }; | ||
110 | |||
111 | /* 1.2.643.2.2.31.2 */ | ||
112 | static const gost_subst_block Gost28147_CryptoProParamSetB = { | ||
113 | {0x0,0x4,0xB,0xE,0x8,0x3,0x7,0x1,0xA,0x2,0x9,0x6,0xF,0xD,0x5,0xC}, | ||
114 | {0x5,0x2,0xA,0xB,0x9,0x1,0xC,0x3,0x7,0x4,0xD,0x0,0x6,0xF,0x8,0xE}, | ||
115 | {0x8,0x3,0x2,0x6,0x4,0xD,0xE,0xB,0xC,0x1,0x7,0xF,0xA,0x0,0x9,0x5}, | ||
116 | {0x2,0x7,0xC,0xF,0x9,0x5,0xA,0xB,0x1,0x4,0x0,0xD,0x6,0x8,0xE,0x3}, | ||
117 | {0x7,0x5,0x0,0xD,0xB,0x6,0x1,0x2,0x3,0xA,0xC,0xF,0x4,0xE,0x9,0x8}, | ||
118 | {0xE,0xC,0x0,0xA,0x9,0x2,0xD,0xB,0x7,0x5,0x8,0xF,0x3,0x6,0x1,0x4}, | ||
119 | {0x0,0x1,0x2,0xA,0x4,0xD,0x5,0xC,0x9,0x7,0x3,0xF,0xB,0x8,0x6,0xE}, | ||
120 | {0x8,0x4,0xB,0x1,0x3,0x5,0x0,0x9,0x2,0xE,0xA,0xC,0xD,0x6,0x7,0xF} | ||
121 | }; | ||
122 | |||
123 | /* 1.2.643.2.2.31.3 */ | ||
124 | static const gost_subst_block Gost28147_CryptoProParamSetC = { | ||
125 | {0x7,0x4,0x0,0x5,0xA,0x2,0xF,0xE,0xC,0x6,0x1,0xB,0xD,0x9,0x3,0x8}, | ||
126 | {0xA,0x9,0x6,0x8,0xD,0xE,0x2,0x0,0xF,0x3,0x5,0xB,0x4,0x1,0xC,0x7}, | ||
127 | {0xC,0x9,0xB,0x1,0x8,0xE,0x2,0x4,0x7,0x3,0x6,0x5,0xA,0x0,0xF,0xD}, | ||
128 | {0x8,0xD,0xB,0x0,0x4,0x5,0x1,0x2,0x9,0x3,0xC,0xE,0x6,0xF,0xA,0x7}, | ||
129 | {0x3,0x6,0x0,0x1,0x5,0xD,0xA,0x8,0xB,0x2,0x9,0x7,0xE,0xF,0xC,0x4}, | ||
130 | {0x8,0x2,0x5,0x0,0x4,0x9,0xF,0xA,0x3,0x7,0xC,0xD,0x6,0xE,0x1,0xB}, | ||
131 | {0x0,0x1,0x7,0xD,0xB,0x4,0x5,0x2,0x8,0xE,0xF,0xC,0x9,0xA,0x6,0x3}, | ||
132 | {0x1,0xB,0xC,0x2,0x9,0xD,0x0,0xF,0x4,0x5,0x8,0xE,0xA,0x7,0x6,0x3} | ||
133 | }; | ||
134 | |||
135 | /* 1.2.643.2.2.31.4 */ | ||
136 | static const gost_subst_block Gost28147_CryptoProParamSetD = { | ||
137 | {0x1,0xA,0x6,0x8,0xF,0xB,0x0,0x4,0xC,0x3,0x5,0x9,0x7,0xD,0x2,0xE}, | ||
138 | {0x3,0x0,0x6,0xF,0x1,0xE,0x9,0x2,0xD,0x8,0xC,0x4,0xB,0xA,0x5,0x7}, | ||
139 | {0x8,0x0,0xF,0x3,0x2,0x5,0xE,0xB,0x1,0xA,0x4,0x7,0xC,0x9,0xD,0x6}, | ||
140 | {0x0,0xC,0x8,0x9,0xD,0x2,0xA,0xB,0x7,0x3,0x6,0x5,0x4,0xE,0xF,0x1}, | ||
141 | {0x1,0x5,0xE,0xC,0xA,0x7,0x0,0xD,0x6,0x2,0xB,0x4,0x9,0x3,0xF,0x8}, | ||
142 | {0x1,0xC,0xB,0x0,0xF,0xE,0x6,0x5,0xA,0xD,0x4,0x8,0x9,0x3,0x7,0x2}, | ||
143 | {0xB,0x6,0x3,0x4,0xC,0xF,0xE,0x2,0x7,0xD,0x8,0x0,0x5,0xA,0x9,0x1}, | ||
144 | {0xF,0xC,0x2,0xA,0x6,0x4,0x5,0x0,0x7,0x9,0xE,0xD,0x1,0xB,0x8,0x3} | ||
145 | }; | ||
146 | |||
147 | static const gost_subst_block Gost28147_TC26ParamSetZ = { | ||
148 | {0x1,0x7,0xe,0xd,0x0,0x5,0x8,0x3,0x4,0xf,0xa,0x6,0x9,0xc,0xb,0x2}, | ||
149 | {0x8,0xe,0x2,0x5,0x6,0x9,0x1,0xc,0xf,0x4,0xb,0x0,0xd,0xa,0x3,0x7}, | ||
150 | {0x5,0xd,0xf,0x6,0x9,0x2,0xc,0xa,0xb,0x7,0x8,0x1,0x4,0x3,0xe,0x0}, | ||
151 | {0x7,0xf,0x5,0xa,0x8,0x1,0x6,0xd,0x0,0x9,0x3,0xe,0xb,0x4,0x2,0xc}, | ||
152 | {0xc,0x8,0x2,0x1,0xd,0x4,0xf,0x6,0x7,0x0,0xa,0x5,0x3,0xe,0x9,0xb}, | ||
153 | {0xb,0x3,0x5,0x8,0x2,0xf,0xa,0xd,0xe,0x1,0x7,0x4,0xc,0x9,0x6,0x0}, | ||
154 | {0x6,0x8,0x2,0x3,0x9,0xa,0x5,0xc,0x1,0xe,0x4,0x7,0xb,0xd,0x0,0xf}, | ||
155 | {0xc,0x4,0x6,0x2,0xa,0x5,0xb,0x9,0xe,0x8,0xd,0x7,0x0,0x3,0xf,0x1} | ||
156 | }; | ||
157 | |||
158 | static const unsigned char CryptoProKeyMeshingKey[] = { | ||
159 | 0x69, 0x00, 0x72, 0x22, 0x64, 0xC9, 0x04, 0x23, | ||
160 | 0x8D, 0x3A, 0xDB, 0x96, 0x46, 0xE9, 0x2A, 0xC4, | ||
161 | 0x18, 0xFE, 0xAC, 0x94, 0x00, 0xED, 0x07, 0x12, | ||
162 | 0xC0, 0x86, 0xDC, 0xC2, 0xEF, 0x4C, 0xA9, 0x2B | ||
163 | }; | ||
164 | |||
165 | static const struct gost89_parameters_info { | ||
166 | int nid; | ||
167 | const gost_subst_block *sblock; | ||
168 | int key_meshing; | ||
169 | } gost_cipher_list[] = | ||
170 | { | ||
171 | {NID_id_Gost28147_89_CryptoPro_A_ParamSet,&Gost28147_CryptoProParamSetA,1}, | ||
172 | {NID_id_Gost28147_89_CryptoPro_B_ParamSet,&Gost28147_CryptoProParamSetB,1}, | ||
173 | {NID_id_Gost28147_89_CryptoPro_C_ParamSet,&Gost28147_CryptoProParamSetC,1}, | ||
174 | {NID_id_Gost28147_89_CryptoPro_D_ParamSet,&Gost28147_CryptoProParamSetD,1}, | ||
175 | {NID_id_tc26_gost_28147_param_Z,&Gost28147_TC26ParamSetZ,1}, | ||
176 | {NID_id_Gost28147_89_TestParamSet,&Gost28147_TestParamSet,0}, | ||
177 | {NID_id_GostR3411_94_TestParamSet,&GostR3411_94_TestParamSet,0}, | ||
178 | {NID_id_GostR3411_94_CryptoProParamSet,&GostR3411_94_CryptoProParamSet,0}, | ||
179 | {NID_undef,NULL,0} | ||
180 | }; | ||
181 | |||
182 | int Gost2814789_set_sbox(GOST2814789_KEY *key, int nid) | ||
183 | { | ||
184 | int i; | ||
185 | const gost_subst_block *b = NULL; | ||
186 | unsigned int t; | ||
187 | |||
188 | for (i = 0; gost_cipher_list[i].nid != NID_undef; i++) { | ||
189 | if (gost_cipher_list[i].nid != nid) | ||
190 | continue; | ||
191 | |||
192 | b = gost_cipher_list[i].sblock; | ||
193 | key->key_meshing = gost_cipher_list[i].key_meshing; | ||
194 | break; | ||
195 | } | ||
196 | |||
197 | if (!b) | ||
198 | return 0; | ||
199 | |||
200 | for (i = 0; i < 256; i++) { | ||
201 | t = (unsigned int)(b->k8[i >> 4] <<4 | b->k7 [i & 15]) << 24; | ||
202 | key->k87[i] = (t << 11) | (t >> 21); | ||
203 | t = (unsigned int)(b->k6[i >> 4] <<4 | b->k5 [i & 15]) << 16; | ||
204 | key->k65[i] = (t << 11) | (t >> 21); | ||
205 | t = (unsigned int)(b->k4[i >> 4] <<4 | b->k3 [i & 15]) << 8; | ||
206 | key->k43[i] = (t << 11) | (t >> 21); | ||
207 | t = (unsigned int)(b->k2[i >> 4] <<4 | b->k1 [i & 15]) << 0; | ||
208 | key->k21[i] = (t << 11) | (t >> 21); | ||
209 | } | ||
210 | |||
211 | return 1; | ||
212 | } | ||
213 | |||
214 | int Gost2814789_set_key(GOST2814789_KEY *key, | ||
215 | const unsigned char *userKey, const int bits) | ||
216 | { | ||
217 | int i; | ||
218 | |||
219 | if (bits != 256) | ||
220 | return 0; | ||
221 | |||
222 | for (i = 0; i < 8; i++) | ||
223 | c2l(userKey, key->key[i]); | ||
224 | |||
225 | key->count = 0; | ||
226 | |||
227 | return 1; | ||
228 | } | ||
229 | |||
230 | void Gost2814789_cryptopro_key_mesh(GOST2814789_KEY *key) | ||
231 | { | ||
232 | unsigned char newkey[32]; | ||
233 | |||
234 | Gost2814789_decrypt(CryptoProKeyMeshingKey + 0, newkey + 0, key); | ||
235 | Gost2814789_decrypt(CryptoProKeyMeshingKey + 8, newkey + 8, key); | ||
236 | Gost2814789_decrypt(CryptoProKeyMeshingKey + 16, newkey + 16, key); | ||
237 | Gost2814789_decrypt(CryptoProKeyMeshingKey + 24, newkey + 24, key); | ||
238 | |||
239 | Gost2814789_set_key(key, newkey, 256); | ||
240 | } | ||
241 | #endif | ||
diff --git a/src/lib/libcrypto/gost/gost89imit_ameth.c b/src/lib/libcrypto/gost/gost89imit_ameth.c new file mode 100644 index 0000000000..879c2b0ca0 --- /dev/null +++ b/src/lib/libcrypto/gost/gost89imit_ameth.c | |||
@@ -0,0 +1,88 @@ | |||
1 | /* $OpenBSD: gost89imit_ameth.c,v 1.1 2014/11/09 19:17:13 miod Exp $ */ | ||
2 | /* | ||
3 | * Copyright (c) 2014 Dmitry Eremin-Solenikov <dbaryshkov@gmail.com> | ||
4 | * Copyright (c) 2005-2006 Cryptocom LTD | ||
5 | * | ||
6 | * Redistribution and use in source and binary forms, with or without | ||
7 | * modification, are permitted provided that the following conditions | ||
8 | * are met: | ||
9 | * | ||
10 | * 1. Redistributions of source code must retain the above copyright | ||
11 | * notice, this list of conditions and the following disclaimer. | ||
12 | * | ||
13 | * 2. Redistributions in binary form must reproduce the above copyright | ||
14 | * notice, this list of conditions and the following disclaimer in | ||
15 | * the documentation and/or other materials provided with the | ||
16 | * distribution. | ||
17 | * | ||
18 | * 3. All advertising materials mentioning features or use of this | ||
19 | * software must display the following acknowledgment: | ||
20 | * "This product includes software developed by the OpenSSL Project | ||
21 | * for use in the OpenSSL Toolkit. (http://www.openssl.org/)" | ||
22 | * | ||
23 | * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to | ||
24 | * endorse or promote products derived from this software without | ||
25 | * prior written permission. For written permission, please contact | ||
26 | * openssl-core@openssl.org. | ||
27 | * | ||
28 | * 5. Products derived from this software may not be called "OpenSSL" | ||
29 | * nor may "OpenSSL" appear in their names without prior written | ||
30 | * permission of the OpenSSL Project. | ||
31 | * | ||
32 | * 6. Redistributions of any form whatsoever must retain the following | ||
33 | * acknowledgment: | ||
34 | * "This product includes software developed by the OpenSSL Project | ||
35 | * for use in the OpenSSL Toolkit (http://www.openssl.org/)" | ||
36 | * | ||
37 | * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY | ||
38 | * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | ||
39 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR | ||
40 | * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR | ||
41 | * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, | ||
42 | * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT | ||
43 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; | ||
44 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | ||
45 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, | ||
46 | * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) | ||
47 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED | ||
48 | * OF THE POSSIBILITY OF SUCH DAMAGE. | ||
49 | * ==================================================================== | ||
50 | */ | ||
51 | |||
52 | #include <openssl/opensslconf.h> | ||
53 | |||
54 | #ifndef OPENSSL_NO_GOST | ||
55 | #include <openssl/evp.h> | ||
56 | |||
57 | #include "asn1_locl.h" | ||
58 | |||
59 | static void mackey_free_gost(EVP_PKEY *pk) | ||
60 | { | ||
61 | if (pk->pkey.ptr) { | ||
62 | free(pk->pkey.ptr); | ||
63 | } | ||
64 | } | ||
65 | |||
66 | static int mac_ctrl_gost(EVP_PKEY *pkey, int op, long arg1, void *arg2) | ||
67 | { | ||
68 | switch (op) { | ||
69 | case ASN1_PKEY_CTRL_DEFAULT_MD_NID: | ||
70 | *(int *)arg2 = NID_id_Gost28147_89_MAC; | ||
71 | return 2; | ||
72 | } | ||
73 | return -2; | ||
74 | } | ||
75 | |||
76 | const EVP_PKEY_ASN1_METHOD gostimit_asn1_meth = { | ||
77 | .pkey_id = EVP_PKEY_GOSTIMIT, | ||
78 | .pkey_base_id = EVP_PKEY_GOSTIMIT, | ||
79 | .pkey_flags = ASN1_PKEY_SIGPARAM_NULL, | ||
80 | |||
81 | .pem_str = "GOST-MAC", | ||
82 | .info = "GOST 28147-89 MAC", | ||
83 | |||
84 | .pkey_free = mackey_free_gost, | ||
85 | .pkey_ctrl = mac_ctrl_gost, | ||
86 | }; | ||
87 | |||
88 | #endif | ||
diff --git a/src/lib/libcrypto/gost/gost89imit_pmeth.c b/src/lib/libcrypto/gost/gost89imit_pmeth.c new file mode 100644 index 0000000000..ec9c72372c --- /dev/null +++ b/src/lib/libcrypto/gost/gost89imit_pmeth.c | |||
@@ -0,0 +1,230 @@ | |||
1 | /* $OpenBSD: gost89imit_pmeth.c,v 1.1 2014/11/09 19:17:13 miod Exp $ */ | ||
2 | /* | ||
3 | * Copyright (c) 2014 Dmitry Eremin-Solenikov <dbaryshkov@gmail.com> | ||
4 | * Copyright (c) 2005-2006 Cryptocom LTD | ||
5 | * | ||
6 | * Redistribution and use in source and binary forms, with or without | ||
7 | * modification, are permitted provided that the following conditions | ||
8 | * are met: | ||
9 | * | ||
10 | * 1. Redistributions of source code must retain the above copyright | ||
11 | * notice, this list of conditions and the following disclaimer. | ||
12 | * | ||
13 | * 2. Redistributions in binary form must reproduce the above copyright | ||
14 | * notice, this list of conditions and the following disclaimer in | ||
15 | * the documentation and/or other materials provided with the | ||
16 | * distribution. | ||
17 | * | ||
18 | * 3. All advertising materials mentioning features or use of this | ||
19 | * software must display the following acknowledgment: | ||
20 | * "This product includes software developed by the OpenSSL Project | ||
21 | * for use in the OpenSSL Toolkit. (http://www.openssl.org/)" | ||
22 | * | ||
23 | * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to | ||
24 | * endorse or promote products derived from this software without | ||
25 | * prior written permission. For written permission, please contact | ||
26 | * openssl-core@openssl.org. | ||
27 | * | ||
28 | * 5. Products derived from this software may not be called "OpenSSL" | ||
29 | * nor may "OpenSSL" appear in their names without prior written | ||
30 | * permission of the OpenSSL Project. | ||
31 | * | ||
32 | * 6. Redistributions of any form whatsoever must retain the following | ||
33 | * acknowledgment: | ||
34 | * "This product includes software developed by the OpenSSL Project | ||
35 | * for use in the OpenSSL Toolkit (http://www.openssl.org/)" | ||
36 | * | ||
37 | * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY | ||
38 | * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | ||
39 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR | ||
40 | * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR | ||
41 | * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, | ||
42 | * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT | ||
43 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; | ||
44 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | ||
45 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, | ||
46 | * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) | ||
47 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED | ||
48 | * OF THE POSSIBILITY OF SUCH DAMAGE. | ||
49 | * ==================================================================== | ||
50 | */ | ||
51 | |||
52 | #include <string.h> | ||
53 | |||
54 | #include <openssl/opensslconf.h> | ||
55 | |||
56 | #ifndef OPENSSL_NO_GOST | ||
57 | #include <openssl/evp.h> | ||
58 | #include <openssl/err.h> | ||
59 | #include <openssl/gost.h> | ||
60 | #include <openssl/x509v3.h> /*For string_to_hex */ | ||
61 | |||
62 | #include "evp_locl.h" | ||
63 | #include "gost_locl.h" | ||
64 | |||
65 | struct gost_mac_pmeth_data { | ||
66 | EVP_MD *md; | ||
67 | unsigned char key[32]; | ||
68 | unsigned key_set : 1; | ||
69 | }; | ||
70 | |||
71 | static int pkey_gost_mac_init(EVP_PKEY_CTX *ctx) | ||
72 | { | ||
73 | struct gost_mac_pmeth_data *data; | ||
74 | |||
75 | data = calloc(1, sizeof(struct gost_mac_pmeth_data)); | ||
76 | if (!data) | ||
77 | return 0; | ||
78 | EVP_PKEY_CTX_set_data(ctx,data); | ||
79 | return 1; | ||
80 | } | ||
81 | |||
82 | static void pkey_gost_mac_cleanup (EVP_PKEY_CTX *ctx) | ||
83 | { | ||
84 | struct gost_mac_pmeth_data *data = EVP_PKEY_CTX_get_data(ctx); | ||
85 | free(data); | ||
86 | } | ||
87 | |||
88 | static int pkey_gost_mac_copy(EVP_PKEY_CTX *dst, EVP_PKEY_CTX *src) | ||
89 | { | ||
90 | struct gost_mac_pmeth_data *dst_data, *src_data; | ||
91 | |||
92 | if (!pkey_gost_mac_init(dst)) | ||
93 | return 0; | ||
94 | |||
95 | src_data = EVP_PKEY_CTX_get_data(src); | ||
96 | dst_data = EVP_PKEY_CTX_get_data(dst); | ||
97 | |||
98 | *dst_data = *src_data; | ||
99 | |||
100 | return 1; | ||
101 | } | ||
102 | |||
103 | static int pkey_gost_mac_keygen(EVP_PKEY_CTX *ctx, EVP_PKEY *pkey) | ||
104 | { | ||
105 | struct gost_mac_pmeth_data *data = EVP_PKEY_CTX_get_data(ctx); | ||
106 | unsigned char *keydata; | ||
107 | |||
108 | if (!data->key_set) { | ||
109 | GOSTerr(GOST_F_PKEY_GOST_MAC_KEYGEN, GOST_R_MAC_KEY_NOT_SET); | ||
110 | return 0; | ||
111 | } | ||
112 | |||
113 | keydata = malloc(32); | ||
114 | memcpy(keydata, data->key, 32); | ||
115 | EVP_PKEY_assign(pkey, NID_id_Gost28147_89_MAC, keydata); | ||
116 | |||
117 | return 1; | ||
118 | } | ||
119 | |||
120 | static int pkey_gost_mac_ctrl(EVP_PKEY_CTX *ctx, int type, int p1, void *p2) | ||
121 | { | ||
122 | struct gost_mac_pmeth_data *data = EVP_PKEY_CTX_get_data(ctx); | ||
123 | |||
124 | switch (type) { | ||
125 | case EVP_PKEY_CTRL_MD: | ||
126 | if (EVP_MD_type(p2) != NID_id_Gost28147_89_MAC) { | ||
127 | GOSTerr(GOST_F_PKEY_GOST_MAC_CTRL, GOST_R_INVALID_DIGEST_TYPE); | ||
128 | return 0; | ||
129 | } | ||
130 | data->md = p2; | ||
131 | return 1; | ||
132 | |||
133 | case EVP_PKEY_CTRL_SET_MAC_KEY: | ||
134 | if (p1 != 32) { | ||
135 | GOSTerr(GOST_F_PKEY_GOST_MAC_CTRL, GOST_R_INVALID_MAC_KEY_LENGTH); | ||
136 | return 0; | ||
137 | } | ||
138 | |||
139 | memcpy(data->key, p2, 32); | ||
140 | data->key_set = 1; | ||
141 | return 1; | ||
142 | |||
143 | case EVP_PKEY_CTRL_DIGESTINIT: | ||
144 | { | ||
145 | EVP_MD_CTX *mctx = p2; | ||
146 | void *key; | ||
147 | if (!data->key_set) { | ||
148 | EVP_PKEY *pkey = EVP_PKEY_CTX_get0_pkey(ctx); | ||
149 | if (!pkey) { | ||
150 | GOSTerr(GOST_F_PKEY_GOST_MAC_CTRL, GOST_R_MAC_KEY_NOT_SET); | ||
151 | return 0; | ||
152 | } | ||
153 | key = EVP_PKEY_get0(pkey); | ||
154 | if (!key) { | ||
155 | GOSTerr(GOST_F_PKEY_GOST_MAC_CTRL, GOST_R_MAC_KEY_NOT_SET); | ||
156 | return 0; | ||
157 | } | ||
158 | } else { | ||
159 | key = &(data->key); | ||
160 | } | ||
161 | if (!mctx->digest->md_ctrl) | ||
162 | return 0; | ||
163 | return mctx->digest->md_ctrl(mctx, EVP_MD_CTRL_SET_KEY, 32 * 8, key); | ||
164 | } | ||
165 | |||
166 | } | ||
167 | |||
168 | return -2; | ||
169 | } | ||
170 | static int pkey_gost_mac_ctrl_str(EVP_PKEY_CTX *ctx, | ||
171 | const char *type, const char *value) | ||
172 | { | ||
173 | if (!value) | ||
174 | return 0; | ||
175 | if (!strcmp(type, "key")) { | ||
176 | void *p = (void *)value; | ||
177 | return pkey_gost_mac_ctrl(ctx, EVP_PKEY_CTRL_SET_MAC_KEY, strlen(value), p); | ||
178 | } | ||
179 | if (!strcmp(type, "hexkey")) { | ||
180 | unsigned char *key; | ||
181 | int r; | ||
182 | long keylen; | ||
183 | key = string_to_hex(value, &keylen); | ||
184 | if (!key) | ||
185 | return 0; | ||
186 | r = pkey_gost_mac_ctrl(ctx, EVP_PKEY_CTRL_SET_MAC_KEY, keylen, key); | ||
187 | free(key); | ||
188 | return r; | ||
189 | } | ||
190 | return -2; | ||
191 | } | ||
192 | |||
193 | static int pkey_gost_mac_signctx_init(EVP_PKEY_CTX *ctx, EVP_MD_CTX *mctx) | ||
194 | { | ||
195 | return 1; | ||
196 | } | ||
197 | |||
198 | static int pkey_gost_mac_signctx(EVP_PKEY_CTX *ctx, unsigned char *sig, size_t *siglen, EVP_MD_CTX *mctx) | ||
199 | { | ||
200 | unsigned int tmpsiglen=*siglen; /* for platforms where sizeof(int)!=sizeof(size_t)*/ | ||
201 | int ret; | ||
202 | |||
203 | |||
204 | if (!sig) { | ||
205 | *siglen = 4; | ||
206 | return 1; | ||
207 | } | ||
208 | |||
209 | ret = EVP_DigestFinal_ex(mctx, sig, &tmpsiglen); | ||
210 | *siglen = tmpsiglen; | ||
211 | return ret; | ||
212 | } | ||
213 | |||
214 | const EVP_PKEY_METHOD gostimit_pkey_meth = { | ||
215 | .pkey_id = EVP_PKEY_GOSTIMIT, | ||
216 | |||
217 | .init = pkey_gost_mac_init, | ||
218 | .cleanup = pkey_gost_mac_cleanup, | ||
219 | .copy = pkey_gost_mac_copy, | ||
220 | |||
221 | .keygen = pkey_gost_mac_keygen, | ||
222 | |||
223 | .signctx_init = pkey_gost_mac_signctx_init, | ||
224 | .signctx = pkey_gost_mac_signctx, | ||
225 | |||
226 | .ctrl = pkey_gost_mac_ctrl, | ||
227 | .ctrl_str = pkey_gost_mac_ctrl_str, | ||
228 | }; | ||
229 | |||
230 | #endif | ||
diff --git a/src/lib/libcrypto/gost/gost_asn1.c b/src/lib/libcrypto/gost/gost_asn1.c new file mode 100644 index 0000000000..b8ed244e49 --- /dev/null +++ b/src/lib/libcrypto/gost/gost_asn1.c | |||
@@ -0,0 +1,53 @@ | |||
1 | /********************************************************************** | ||
2 | * gost_keytrans.c * | ||
3 | * Copyright (c) 2005-2006 Cryptocom LTD * | ||
4 | * This file is distributed under the same license as OpenSSL * | ||
5 | * * | ||
6 | * ASN1 structure definition for GOST key transport * | ||
7 | * Requires OpenSSL 0.9.9 for compilation * | ||
8 | **********************************************************************/ | ||
9 | |||
10 | #include <openssl/opensslconf.h> | ||
11 | |||
12 | #ifndef OPENSSL_NO_GOST | ||
13 | #include <openssl/asn1t.h> | ||
14 | #include <openssl/x509.h> | ||
15 | #include <openssl/gost.h> | ||
16 | |||
17 | #include "gost_locl.h" | ||
18 | #include "gost_asn1.h" | ||
19 | |||
20 | ASN1_NDEF_SEQUENCE(GOST_KEY_TRANSPORT) = { | ||
21 | ASN1_SIMPLE(GOST_KEY_TRANSPORT, key_info, GOST_KEY_INFO), | ||
22 | ASN1_IMP(GOST_KEY_TRANSPORT, key_agreement_info, GOST_KEY_AGREEMENT_INFO, 0) | ||
23 | } ASN1_NDEF_SEQUENCE_END(GOST_KEY_TRANSPORT) | ||
24 | IMPLEMENT_ASN1_FUNCTIONS(GOST_KEY_TRANSPORT) | ||
25 | |||
26 | ASN1_NDEF_SEQUENCE(GOST_KEY_INFO) = { | ||
27 | ASN1_SIMPLE(GOST_KEY_INFO, encrypted_key, ASN1_OCTET_STRING), | ||
28 | ASN1_SIMPLE(GOST_KEY_INFO, imit, ASN1_OCTET_STRING) | ||
29 | } ASN1_NDEF_SEQUENCE_END(GOST_KEY_INFO) | ||
30 | IMPLEMENT_ASN1_FUNCTIONS(GOST_KEY_INFO) | ||
31 | |||
32 | ASN1_NDEF_SEQUENCE(GOST_KEY_AGREEMENT_INFO) = { | ||
33 | ASN1_SIMPLE(GOST_KEY_AGREEMENT_INFO, cipher, ASN1_OBJECT), | ||
34 | ASN1_IMP_OPT(GOST_KEY_AGREEMENT_INFO, ephem_key, X509_PUBKEY, 0), | ||
35 | ASN1_SIMPLE(GOST_KEY_AGREEMENT_INFO, eph_iv, ASN1_OCTET_STRING) | ||
36 | } ASN1_NDEF_SEQUENCE_END(GOST_KEY_AGREEMENT_INFO) | ||
37 | IMPLEMENT_ASN1_FUNCTIONS(GOST_KEY_AGREEMENT_INFO) | ||
38 | |||
39 | |||
40 | ASN1_NDEF_SEQUENCE(GOST_KEY_PARAMS) = { | ||
41 | ASN1_SIMPLE(GOST_KEY_PARAMS, key_params, ASN1_OBJECT), | ||
42 | ASN1_SIMPLE(GOST_KEY_PARAMS, hash_params, ASN1_OBJECT), | ||
43 | ASN1_OPT(GOST_KEY_PARAMS, cipher_params, ASN1_OBJECT), | ||
44 | } ASN1_NDEF_SEQUENCE_END(GOST_KEY_PARAMS) | ||
45 | IMPLEMENT_ASN1_FUNCTIONS(GOST_KEY_PARAMS) | ||
46 | |||
47 | ASN1_NDEF_SEQUENCE(GOST_CIPHER_PARAMS) = { | ||
48 | ASN1_SIMPLE(GOST_CIPHER_PARAMS, iv, ASN1_OCTET_STRING), | ||
49 | ASN1_SIMPLE(GOST_CIPHER_PARAMS, enc_param_set, ASN1_OBJECT), | ||
50 | } ASN1_NDEF_SEQUENCE_END(GOST_CIPHER_PARAMS) | ||
51 | IMPLEMENT_ASN1_FUNCTIONS(GOST_CIPHER_PARAMS) | ||
52 | |||
53 | #endif | ||
diff --git a/src/lib/libcrypto/gost/gost_asn1.h b/src/lib/libcrypto/gost/gost_asn1.h new file mode 100644 index 0000000000..62719c70cd --- /dev/null +++ b/src/lib/libcrypto/gost/gost_asn1.h | |||
@@ -0,0 +1,87 @@ | |||
1 | /* $OpenBSD: gost_asn1.h,v 1.1 2014/11/09 19:17:13 miod Exp $ */ | ||
2 | /* | ||
3 | * Copyright (c) 2014 Dmitry Eremin-Solenikov <dbaryshkov@gmail.com> | ||
4 | * Copyright (c) 2005-2006 Cryptocom LTD | ||
5 | * | ||
6 | * Redistribution and use in source and binary forms, with or without | ||
7 | * modification, are permitted provided that the following conditions | ||
8 | * are met: | ||
9 | * | ||
10 | * 1. Redistributions of source code must retain the above copyright | ||
11 | * notice, this list of conditions and the following disclaimer. | ||
12 | * | ||
13 | * 2. Redistributions in binary form must reproduce the above copyright | ||
14 | * notice, this list of conditions and the following disclaimer in | ||
15 | * the documentation and/or other materials provided with the | ||
16 | * distribution. | ||
17 | * | ||
18 | * 3. All advertising materials mentioning features or use of this | ||
19 | * software must display the following acknowledgment: | ||
20 | * "This product includes software developed by the OpenSSL Project | ||
21 | * for use in the OpenSSL Toolkit. (http://www.openssl.org/)" | ||
22 | * | ||
23 | * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to | ||
24 | * endorse or promote products derived from this software without | ||
25 | * prior written permission. For written permission, please contact | ||
26 | * openssl-core@openssl.org. | ||
27 | * | ||
28 | * 5. Products derived from this software may not be called "OpenSSL" | ||
29 | * nor may "OpenSSL" appear in their names without prior written | ||
30 | * permission of the OpenSSL Project. | ||
31 | * | ||
32 | * 6. Redistributions of any form whatsoever must retain the following | ||
33 | * acknowledgment: | ||
34 | * "This product includes software developed by the OpenSSL Project | ||
35 | * for use in the OpenSSL Toolkit (http://www.openssl.org/)" | ||
36 | * | ||
37 | * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY | ||
38 | * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | ||
39 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR | ||
40 | * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR | ||
41 | * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, | ||
42 | * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT | ||
43 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; | ||
44 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | ||
45 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, | ||
46 | * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) | ||
47 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED | ||
48 | * OF THE POSSIBILITY OF SUCH DAMAGE. | ||
49 | * ==================================================================== | ||
50 | */ | ||
51 | |||
52 | #ifndef HEADER_GOST_ASN1_H | ||
53 | #define HEADER_GOST_ASN1_H | ||
54 | |||
55 | #include <openssl/asn1.h> | ||
56 | |||
57 | typedef struct { | ||
58 | ASN1_OCTET_STRING *encrypted_key; | ||
59 | ASN1_OCTET_STRING *imit; | ||
60 | } GOST_KEY_INFO; | ||
61 | |||
62 | DECLARE_ASN1_FUNCTIONS(GOST_KEY_INFO) | ||
63 | |||
64 | typedef struct { | ||
65 | ASN1_OBJECT *cipher; | ||
66 | X509_PUBKEY *ephem_key; | ||
67 | ASN1_OCTET_STRING *eph_iv; | ||
68 | } GOST_KEY_AGREEMENT_INFO; | ||
69 | |||
70 | DECLARE_ASN1_FUNCTIONS(GOST_KEY_AGREEMENT_INFO) | ||
71 | |||
72 | typedef struct { | ||
73 | GOST_KEY_INFO *key_info; | ||
74 | GOST_KEY_AGREEMENT_INFO *key_agreement_info; | ||
75 | } GOST_KEY_TRANSPORT; | ||
76 | |||
77 | DECLARE_ASN1_FUNCTIONS(GOST_KEY_TRANSPORT) | ||
78 | |||
79 | typedef struct { | ||
80 | ASN1_OBJECT *key_params; | ||
81 | ASN1_OBJECT *hash_params; | ||
82 | ASN1_OBJECT *cipher_params; | ||
83 | } GOST_KEY_PARAMS; | ||
84 | |||
85 | DECLARE_ASN1_FUNCTIONS(GOST_KEY_PARAMS) | ||
86 | |||
87 | #endif | ||
diff --git a/src/lib/libcrypto/gost/gost_err.c b/src/lib/libcrypto/gost/gost_err.c new file mode 100644 index 0000000000..a52fe4cd5a --- /dev/null +++ b/src/lib/libcrypto/gost/gost_err.c | |||
@@ -0,0 +1,143 @@ | |||
1 | /* crypto/gost/gost_err.c */ | ||
2 | /* ==================================================================== | ||
3 | * Copyright (c) 1999-2014 The OpenSSL Project. All rights reserved. | ||
4 | * | ||
5 | * Redistribution and use in source and binary forms, with or without | ||
6 | * modification, are permitted provided that the following conditions | ||
7 | * are met: | ||
8 | * | ||
9 | * 1. Redistributions of source code must retain the above copyright | ||
10 | * notice, this list of conditions and the following disclaimer. | ||
11 | * | ||
12 | * 2. Redistributions in binary form must reproduce the above copyright | ||
13 | * notice, this list of conditions and the following disclaimer in | ||
14 | * the documentation and/or other materials provided with the | ||
15 | * distribution. | ||
16 | * | ||
17 | * 3. All advertising materials mentioning features or use of this | ||
18 | * software must display the following acknowledgment: | ||
19 | * "This product includes software developed by the OpenSSL Project | ||
20 | * for use in the OpenSSL Toolkit. (http://www.OpenSSL.org/)" | ||
21 | * | ||
22 | * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to | ||
23 | * endorse or promote products derived from this software without | ||
24 | * prior written permission. For written permission, please contact | ||
25 | * openssl-core@OpenSSL.org. | ||
26 | * | ||
27 | * 5. Products derived from this software may not be called "OpenSSL" | ||
28 | * nor may "OpenSSL" appear in their names without prior written | ||
29 | * permission of the OpenSSL Project. | ||
30 | * | ||
31 | * 6. Redistributions of any form whatsoever must retain the following | ||
32 | * acknowledgment: | ||
33 | * "This product includes software developed by the OpenSSL Project | ||
34 | * for use in the OpenSSL Toolkit (http://www.OpenSSL.org/)" | ||
35 | * | ||
36 | * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY | ||
37 | * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | ||
38 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR | ||
39 | * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR | ||
40 | * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, | ||
41 | * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT | ||
42 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; | ||
43 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | ||
44 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, | ||
45 | * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) | ||
46 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED | ||
47 | * OF THE POSSIBILITY OF SUCH DAMAGE. | ||
48 | * ==================================================================== | ||
49 | * | ||
50 | * This product includes cryptographic software written by Eric Young | ||
51 | * (eay@cryptsoft.com). This product includes software written by Tim | ||
52 | * Hudson (tjh@cryptsoft.com). | ||
53 | * | ||
54 | */ | ||
55 | |||
56 | /* NOTE: this file was auto generated by the mkerr.pl script: any changes | ||
57 | * made to it will be overwritten when the script next updates this file, | ||
58 | * only reason strings will be preserved. | ||
59 | */ | ||
60 | |||
61 | #include <stdio.h> | ||
62 | #include <openssl/err.h> | ||
63 | #include <openssl/gost.h> | ||
64 | |||
65 | /* BEGIN ERROR CODES */ | ||
66 | #ifndef OPENSSL_NO_ERR | ||
67 | |||
68 | #define ERR_FUNC(func) ERR_PACK(ERR_LIB_GOST,func,0) | ||
69 | #define ERR_REASON(reason) ERR_PACK(ERR_LIB_GOST,0,reason) | ||
70 | |||
71 | static ERR_STRING_DATA GOST_str_functs[]= | ||
72 | { | ||
73 | {ERR_FUNC(GOST_F_DECODE_GOST01_ALGOR_PARAMS), "DECODE_GOST01_ALGOR_PARAMS"}, | ||
74 | {ERR_FUNC(GOST_F_ENCODE_GOST01_ALGOR_PARAMS), "ENCODE_GOST01_ALGOR_PARAMS"}, | ||
75 | {ERR_FUNC(GOST_F_GOST2001_COMPUTE_PUBLIC), "GOST2001_COMPUTE_PUBLIC"}, | ||
76 | {ERR_FUNC(GOST_F_GOST2001_DO_SIGN), "GOST2001_DO_SIGN"}, | ||
77 | {ERR_FUNC(GOST_F_GOST2001_DO_VERIFY), "GOST2001_DO_VERIFY"}, | ||
78 | {ERR_FUNC(GOST_F_GOST2001_KEYGEN), "GOST2001_KEYGEN"}, | ||
79 | {ERR_FUNC(GOST_F_GOST89_GET_ASN1_PARAMETERS), "GOST89_GET_ASN1_PARAMETERS"}, | ||
80 | {ERR_FUNC(GOST_F_GOST89_SET_ASN1_PARAMETERS), "GOST89_SET_ASN1_PARAMETERS"}, | ||
81 | {ERR_FUNC(GOST_F_GOST_KEY_CHECK_KEY), "GOST_KEY_check_key"}, | ||
82 | {ERR_FUNC(GOST_F_GOST_KEY_NEW), "GOST_KEY_new"}, | ||
83 | {ERR_FUNC(GOST_F_GOST_KEY_SET_PUBLIC_KEY_AFFINE_COORDINATES), "GOST_KEY_set_public_key_affine_coordinates"}, | ||
84 | {ERR_FUNC(GOST_F_PARAM_COPY_GOST01), "PARAM_COPY_GOST01"}, | ||
85 | {ERR_FUNC(GOST_F_PARAM_DECODE_GOST01), "PARAM_DECODE_GOST01"}, | ||
86 | {ERR_FUNC(GOST_F_PKEY_GOST01_CTRL), "PKEY_GOST01_CTRL"}, | ||
87 | {ERR_FUNC(GOST_F_PKEY_GOST01_DECRYPT), "PKEY_GOST01_DECRYPT"}, | ||
88 | {ERR_FUNC(GOST_F_PKEY_GOST01_DERIVE), "PKEY_GOST01_DERIVE"}, | ||
89 | {ERR_FUNC(GOST_F_PKEY_GOST01_ENCRYPT), "PKEY_GOST01_ENCRYPT"}, | ||
90 | {ERR_FUNC(GOST_F_PKEY_GOST01_PARAMGEN), "PKEY_GOST01_PARAMGEN"}, | ||
91 | {ERR_FUNC(GOST_F_PKEY_GOST01_SIGN), "PKEY_GOST01_SIGN"}, | ||
92 | {ERR_FUNC(GOST_F_PKEY_GOST_MAC_CTRL), "PKEY_GOST_MAC_CTRL"}, | ||
93 | {ERR_FUNC(GOST_F_PKEY_GOST_MAC_KEYGEN), "PKEY_GOST_MAC_KEYGEN"}, | ||
94 | {ERR_FUNC(GOST_F_PRIV_DECODE_GOST01), "PRIV_DECODE_GOST01"}, | ||
95 | {ERR_FUNC(GOST_F_PUB_DECODE_GOST01), "PUB_DECODE_GOST01"}, | ||
96 | {ERR_FUNC(GOST_F_PUB_ENCODE_GOST01), "PUB_ENCODE_GOST01"}, | ||
97 | {ERR_FUNC(GOST_F_PUB_PRINT_GOST01), "PUB_PRINT_GOST01"}, | ||
98 | {ERR_FUNC(GOST_F_UNPACK_SIGNATURE_CP), "UNPACK_SIGNATURE_CP"}, | ||
99 | {ERR_FUNC(GOST_F_UNPACK_SIGNATURE_LE), "UNPACK_SIGNATURE_LE"}, | ||
100 | {0,NULL} | ||
101 | }; | ||
102 | |||
103 | static ERR_STRING_DATA GOST_str_reasons[]= | ||
104 | { | ||
105 | {ERR_REASON(GOST_R_BAD_KEY_PARAMETERS_FORMAT),"bad key parameters format"}, | ||
106 | {ERR_REASON(GOST_R_BAD_PKEY_PARAMETERS_FORMAT),"bad pkey parameters format"}, | ||
107 | {ERR_REASON(GOST_R_CANNOT_PACK_EPHEMERAL_KEY),"cannot pack ephemeral key"}, | ||
108 | {ERR_REASON(GOST_R_CTRL_CALL_FAILED) ,"ctrl call failed"}, | ||
109 | {ERR_REASON(GOST_R_ERROR_COMPUTING_SHARED_KEY),"error computing shared key"}, | ||
110 | {ERR_REASON(GOST_R_ERROR_PARSING_KEY_TRANSPORT_INFO),"error parsing key transport info"}, | ||
111 | {ERR_REASON(GOST_R_INCOMPATIBLE_ALGORITHMS),"incompatible algorithms"}, | ||
112 | {ERR_REASON(GOST_R_INCOMPATIBLE_PEER_KEY),"incompatible peer key"}, | ||
113 | {ERR_REASON(GOST_R_INVALID_DIGEST_TYPE) ,"invalid digest type"}, | ||
114 | {ERR_REASON(GOST_R_INVALID_IV_LENGTH) ,"invalid iv length"}, | ||
115 | {ERR_REASON(GOST_R_INVALID_MAC_KEY_LENGTH),"invalid mac key length"}, | ||
116 | {ERR_REASON(GOST_R_KEY_IS_NOT_INITIALIZED),"key is not initialized"}, | ||
117 | {ERR_REASON(GOST_R_KEY_PARAMETERS_MISSING),"key parameters missing"}, | ||
118 | {ERR_REASON(GOST_R_MAC_KEY_NOT_SET) ,"mac key not set"}, | ||
119 | {ERR_REASON(GOST_R_NO_PARAMETERS_SET) ,"no parameters set"}, | ||
120 | {ERR_REASON(GOST_R_NO_PEER_KEY) ,"no peer key"}, | ||
121 | {ERR_REASON(GOST_R_NO_PRIVATE_PART_OF_NON_EPHEMERAL_KEYPAIR),"no private part of non ephemeral keypair"}, | ||
122 | {ERR_REASON(GOST_R_PUBLIC_KEY_UNDEFINED) ,"public key undefined"}, | ||
123 | {ERR_REASON(GOST_R_RANDOM_GENERATOR_FAILURE),"random generator failure"}, | ||
124 | {ERR_REASON(GOST_R_RANDOM_NUMBER_GENERATOR_FAILED),"random number generator failed"}, | ||
125 | {ERR_REASON(GOST_R_SIGNATURE_MISMATCH) ,"signature mismatch"}, | ||
126 | {ERR_REASON(GOST_R_SIGNATURE_PARTS_GREATER_THAN_Q),"signature parts greater than q"}, | ||
127 | {ERR_REASON(GOST_R_UKM_NOT_SET) ,"ukm not set"}, | ||
128 | {0,NULL} | ||
129 | }; | ||
130 | |||
131 | #endif | ||
132 | |||
133 | void ERR_load_GOST_strings(void) | ||
134 | { | ||
135 | #ifndef OPENSSL_NO_ERR | ||
136 | |||
137 | if (ERR_func_error_string(GOST_str_functs[0].error) == NULL) | ||
138 | { | ||
139 | ERR_load_strings(0,GOST_str_functs); | ||
140 | ERR_load_strings(0,GOST_str_reasons); | ||
141 | } | ||
142 | #endif | ||
143 | } | ||
diff --git a/src/lib/libcrypto/gost/gost_locl.h b/src/lib/libcrypto/gost/gost_locl.h new file mode 100644 index 0000000000..b616005dc5 --- /dev/null +++ b/src/lib/libcrypto/gost/gost_locl.h | |||
@@ -0,0 +1,114 @@ | |||
1 | /* $OpenBSD: gost_locl.h,v 1.1 2014/11/09 19:17:13 miod Exp $ */ | ||
2 | /* | ||
3 | * Copyright (c) 2014 Dmitry Eremin-Solenikov <dbaryshkov@gmail.com> | ||
4 | * Copyright (c) 2005-2006 Cryptocom LTD | ||
5 | * | ||
6 | * Redistribution and use in source and binary forms, with or without | ||
7 | * modification, are permitted provided that the following conditions | ||
8 | * are met: | ||
9 | * | ||
10 | * 1. Redistributions of source code must retain the above copyright | ||
11 | * notice, this list of conditions and the following disclaimer. | ||
12 | * | ||
13 | * 2. Redistributions in binary form must reproduce the above copyright | ||
14 | * notice, this list of conditions and the following disclaimer in | ||
15 | * the documentation and/or other materials provided with the | ||
16 | * distribution. | ||
17 | * | ||
18 | * 3. All advertising materials mentioning features or use of this | ||
19 | * software must display the following acknowledgment: | ||
20 | * "This product includes software developed by the OpenSSL Project | ||
21 | * for use in the OpenSSL Toolkit. (http://www.openssl.org/)" | ||
22 | * | ||
23 | * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to | ||
24 | * endorse or promote products derived from this software without | ||
25 | * prior written permission. For written permission, please contact | ||
26 | * openssl-core@openssl.org. | ||
27 | * | ||
28 | * 5. Products derived from this software may not be called "OpenSSL" | ||
29 | * nor may "OpenSSL" appear in their names without prior written | ||
30 | * permission of the OpenSSL Project. | ||
31 | * | ||
32 | * 6. Redistributions of any form whatsoever must retain the following | ||
33 | * acknowledgment: | ||
34 | * "This product includes software developed by the OpenSSL Project | ||
35 | * for use in the OpenSSL Toolkit (http://www.openssl.org/)" | ||
36 | * | ||
37 | * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY | ||
38 | * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | ||
39 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR | ||
40 | * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR | ||
41 | * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, | ||
42 | * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT | ||
43 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; | ||
44 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | ||
45 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, | ||
46 | * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) | ||
47 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED | ||
48 | * OF THE POSSIBILITY OF SUCH DAMAGE. | ||
49 | * ==================================================================== | ||
50 | */ | ||
51 | |||
52 | #ifndef HEADER_GOST_LOCL_H | ||
53 | #define HEADER_GOST_LOCL_H | ||
54 | |||
55 | #include <openssl/ec.h> | ||
56 | #include <openssl/ecdsa.h> | ||
57 | |||
58 | /* Internal representation of GOST substitution blocks */ | ||
59 | typedef struct { | ||
60 | unsigned char k8[16]; | ||
61 | unsigned char k7[16]; | ||
62 | unsigned char k6[16]; | ||
63 | unsigned char k5[16]; | ||
64 | unsigned char k4[16]; | ||
65 | unsigned char k3[16]; | ||
66 | unsigned char k2[16]; | ||
67 | unsigned char k1[16]; | ||
68 | } gost_subst_block; | ||
69 | |||
70 | #if defined(__i386) || defined(__i386__) || defined(__x86_64) || defined(__x86_64__) | ||
71 | # define c2l(c,l) ((l)=*((const unsigned int *)(c)), (c)+=4) | ||
72 | # define l2c(l,c) (*((unsigned int *)(c))=(l), (c)+=4) | ||
73 | #else | ||
74 | #define c2l(c,l) (l =(((unsigned long)(*((c)++))) ), \ | ||
75 | l|=(((unsigned long)(*((c)++)))<< 8), \ | ||
76 | l|=(((unsigned long)(*((c)++)))<<16), \ | ||
77 | l|=(((unsigned long)(*((c)++)))<<24)) | ||
78 | #define l2c(l,c) (*((c)++)=(unsigned char)(((l) )&0xff), \ | ||
79 | *((c)++)=(unsigned char)(((l)>> 8)&0xff), \ | ||
80 | *((c)++)=(unsigned char)(((l)>>16)&0xff), \ | ||
81 | *((c)++)=(unsigned char)(((l)>>24)&0xff)) | ||
82 | #endif | ||
83 | |||
84 | extern void Gost2814789_encrypt(const unsigned char *in, unsigned char *out, | ||
85 | const GOST2814789_KEY *key); | ||
86 | extern void Gost2814789_decrypt(const unsigned char *in, unsigned char *out, | ||
87 | const GOST2814789_KEY *key); | ||
88 | extern void Gost2814789_cryptopro_key_mesh(GOST2814789_KEY *key); | ||
89 | |||
90 | /* GOST 28147-89 key wrapping */ | ||
91 | extern int key_unwrap_crypto_pro(int nid, const unsigned char *keyExchangeKey, | ||
92 | const unsigned char *wrappedKey, | ||
93 | unsigned char *sessionKey); | ||
94 | extern int key_wrap_crypto_pro(int nid, const unsigned char *keyExchangeKey, | ||
95 | const unsigned char *ukm, const unsigned char *sessionKey, | ||
96 | unsigned char *wrappedKey); | ||
97 | /* Pkey part */ | ||
98 | extern int gost2001_compute_public(GOST_KEY * ec); | ||
99 | extern ECDSA_SIG *gost2001_do_sign(BIGNUM * md, GOST_KEY * eckey); | ||
100 | extern int gost2001_do_verify(BIGNUM * md, ECDSA_SIG * sig, GOST_KEY * ec); | ||
101 | extern int gost2001_keygen(GOST_KEY * ec); | ||
102 | extern void VKO_compute_key(BIGNUM * X, BIGNUM * Y, | ||
103 | const GOST_KEY * pkey, GOST_KEY * priv_key, | ||
104 | const BIGNUM * ukm); | ||
105 | extern BIGNUM *GOST_le2bn(const unsigned char * buf, size_t len, BIGNUM * bn); | ||
106 | extern int GOST_bn2le(BIGNUM * bn, unsigned char * buf, int len); | ||
107 | |||
108 | /* GOST R 34.10 parameters */ | ||
109 | extern int GostR3410_get_md_digest(int nid); | ||
110 | extern int GostR3410_get_pk_digest(int nid); | ||
111 | extern int GostR3410_256_param_id(const char *value); | ||
112 | extern int GostR3410_512_param_id(const char *value); | ||
113 | |||
114 | #endif | ||
diff --git a/src/lib/libcrypto/gost/gostr341001.c b/src/lib/libcrypto/gost/gostr341001.c new file mode 100644 index 0000000000..3c314765f7 --- /dev/null +++ b/src/lib/libcrypto/gost/gostr341001.c | |||
@@ -0,0 +1,321 @@ | |||
1 | /* $OpenBSD: gostr341001.c,v 1.1 2014/11/09 19:17:13 miod Exp $ */ | ||
2 | /* | ||
3 | * Copyright (c) 2014 Dmitry Eremin-Solenikov <dbaryshkov@gmail.com> | ||
4 | * Copyright (c) 2005-2006 Cryptocom LTD | ||
5 | * | ||
6 | * Redistribution and use in source and binary forms, with or without | ||
7 | * modification, are permitted provided that the following conditions | ||
8 | * are met: | ||
9 | * | ||
10 | * 1. Redistributions of source code must retain the above copyright | ||
11 | * notice, this list of conditions and the following disclaimer. | ||
12 | * | ||
13 | * 2. Redistributions in binary form must reproduce the above copyright | ||
14 | * notice, this list of conditions and the following disclaimer in | ||
15 | * the documentation and/or other materials provided with the | ||
16 | * distribution. | ||
17 | * | ||
18 | * 3. All advertising materials mentioning features or use of this | ||
19 | * software must display the following acknowledgment: | ||
20 | * "This product includes software developed by the OpenSSL Project | ||
21 | * for use in the OpenSSL Toolkit. (http://www.openssl.org/)" | ||
22 | * | ||
23 | * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to | ||
24 | * endorse or promote products derived from this software without | ||
25 | * prior written permission. For written permission, please contact | ||
26 | * openssl-core@openssl.org. | ||
27 | * | ||
28 | * 5. Products derived from this software may not be called "OpenSSL" | ||
29 | * nor may "OpenSSL" appear in their names without prior written | ||
30 | * permission of the OpenSSL Project. | ||
31 | * | ||
32 | * 6. Redistributions of any form whatsoever must retain the following | ||
33 | * acknowledgment: | ||
34 | * "This product includes software developed by the OpenSSL Project | ||
35 | * for use in the OpenSSL Toolkit (http://www.openssl.org/)" | ||
36 | * | ||
37 | * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY | ||
38 | * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | ||
39 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR | ||
40 | * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR | ||
41 | * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, | ||
42 | * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT | ||
43 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; | ||
44 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | ||
45 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, | ||
46 | * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) | ||
47 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED | ||
48 | * OF THE POSSIBILITY OF SUCH DAMAGE. | ||
49 | * ==================================================================== | ||
50 | */ | ||
51 | |||
52 | #include <string.h> | ||
53 | |||
54 | #include <openssl/opensslconf.h> | ||
55 | |||
56 | #ifndef OPENSSL_NO_GOST | ||
57 | #include <openssl/err.h> | ||
58 | #include <openssl/gost.h> | ||
59 | #include "gost_locl.h" | ||
60 | |||
61 | /* Convert little-endian byte array into bignum */ | ||
62 | BIGNUM *GOST_le2bn(const unsigned char * buf, size_t len, BIGNUM * bn) | ||
63 | { | ||
64 | unsigned char temp[64]; | ||
65 | int i; | ||
66 | if (len > 64) | ||
67 | return NULL; | ||
68 | |||
69 | for (i = 0; i < len; i++) { | ||
70 | temp[len - 1 - i] = buf[i]; | ||
71 | } | ||
72 | |||
73 | return BN_bin2bn(temp, len, bn); | ||
74 | } | ||
75 | |||
76 | int GOST_bn2le(BIGNUM * bn, unsigned char * buf, int len) | ||
77 | { | ||
78 | unsigned char temp[64]; | ||
79 | int i, bytes; | ||
80 | |||
81 | bytes = BN_num_bytes(bn); | ||
82 | if (len > 64 || bytes > len) | ||
83 | return 0; | ||
84 | |||
85 | BN_bn2bin(bn, temp); | ||
86 | |||
87 | for (i = 0; i < bytes; i++) { | ||
88 | buf[bytes - 1 - i] = temp[i]; | ||
89 | } | ||
90 | |||
91 | memset(buf + bytes, 0, len - bytes); | ||
92 | |||
93 | return 1; | ||
94 | } | ||
95 | |||
96 | |||
97 | int gost2001_compute_public(GOST_KEY * ec) | ||
98 | { | ||
99 | const EC_GROUP *group = GOST_KEY_get0_group(ec); | ||
100 | EC_POINT *pub_key = NULL; | ||
101 | const BIGNUM *priv_key = NULL; | ||
102 | BN_CTX *ctx = NULL; | ||
103 | int ok = 0; | ||
104 | |||
105 | if (!group) { | ||
106 | GOSTerr(GOST_F_GOST2001_COMPUTE_PUBLIC, | ||
107 | GOST_R_KEY_IS_NOT_INITIALIZED); | ||
108 | return 0; | ||
109 | } | ||
110 | ctx = BN_CTX_new(); | ||
111 | BN_CTX_start(ctx); | ||
112 | if (!(priv_key = GOST_KEY_get0_private_key(ec))) { | ||
113 | GOSTerr(GOST_F_GOST2001_COMPUTE_PUBLIC, ERR_R_EC_LIB); | ||
114 | goto err; | ||
115 | } | ||
116 | |||
117 | pub_key = EC_POINT_new(group); | ||
118 | if (!EC_POINT_mul(group, pub_key, priv_key, NULL, NULL, ctx)) { | ||
119 | GOSTerr(GOST_F_GOST2001_COMPUTE_PUBLIC, ERR_R_EC_LIB); | ||
120 | goto err; | ||
121 | } | ||
122 | if (!GOST_KEY_set_public_key(ec, pub_key)) { | ||
123 | GOSTerr(GOST_F_GOST2001_COMPUTE_PUBLIC, ERR_R_EC_LIB); | ||
124 | goto err; | ||
125 | } | ||
126 | ok = 256; | ||
127 | err: | ||
128 | BN_CTX_end(ctx); | ||
129 | EC_POINT_free(pub_key); | ||
130 | BN_CTX_free(ctx); | ||
131 | return ok; | ||
132 | } | ||
133 | |||
134 | ECDSA_SIG *gost2001_do_sign(BIGNUM * md, GOST_KEY * eckey) | ||
135 | { | ||
136 | ECDSA_SIG *newsig = NULL; | ||
137 | BIGNUM *order = NULL; | ||
138 | const EC_GROUP *group; | ||
139 | const BIGNUM *priv_key; | ||
140 | BIGNUM *r = NULL, *s = NULL, *X = NULL, *tmp = NULL, *tmp2 = NULL, *k = | ||
141 | NULL, *e = NULL; | ||
142 | EC_POINT *C = NULL; | ||
143 | BN_CTX *ctx = BN_CTX_new(); | ||
144 | BN_CTX_start(ctx); | ||
145 | newsig = ECDSA_SIG_new(); | ||
146 | if (!newsig) { | ||
147 | GOSTerr(GOST_F_GOST2001_DO_SIGN, ERR_R_MALLOC_FAILURE); | ||
148 | goto err; | ||
149 | } | ||
150 | s = newsig->s; | ||
151 | r = newsig->r; | ||
152 | group = GOST_KEY_get0_group(eckey); | ||
153 | order = BN_CTX_get(ctx); | ||
154 | EC_GROUP_get_order(group, order, ctx); | ||
155 | priv_key = GOST_KEY_get0_private_key(eckey); | ||
156 | e = BN_CTX_get(ctx); | ||
157 | BN_mod(e, md, order, ctx); | ||
158 | if (BN_is_zero(e)) { | ||
159 | BN_one(e); | ||
160 | } | ||
161 | k = BN_CTX_get(ctx); | ||
162 | X = BN_CTX_get(ctx); | ||
163 | C = EC_POINT_new(group); | ||
164 | do { | ||
165 | do { | ||
166 | if (!BN_rand_range(k, order)) { | ||
167 | GOSTerr(GOST_F_GOST2001_DO_SIGN, | ||
168 | GOST_R_RANDOM_NUMBER_GENERATOR_FAILED); | ||
169 | ECDSA_SIG_free(newsig); | ||
170 | newsig = NULL; | ||
171 | goto err; | ||
172 | } | ||
173 | /* We do not want timing information to leak the length of k, | ||
174 | * so we compute G*k using an equivalent scalar of fixed | ||
175 | * bit-length. */ | ||
176 | if (!BN_add(k, k, order)) | ||
177 | goto err; | ||
178 | if (BN_num_bits(k) <= BN_num_bits(order)) | ||
179 | if (!BN_add(k, k, order)) | ||
180 | goto err; | ||
181 | |||
182 | if (!EC_POINT_mul(group, C, k, NULL, NULL, ctx)) { | ||
183 | GOSTerr(GOST_F_GOST2001_DO_SIGN, ERR_R_EC_LIB); | ||
184 | ECDSA_SIG_free(newsig); | ||
185 | newsig = NULL; | ||
186 | goto err; | ||
187 | } | ||
188 | if (!EC_POINT_get_affine_coordinates_GFp | ||
189 | (group, C, X, NULL, ctx)) { | ||
190 | GOSTerr(GOST_F_GOST2001_DO_SIGN, ERR_R_EC_LIB); | ||
191 | ECDSA_SIG_free(newsig); | ||
192 | newsig = NULL; | ||
193 | goto err; | ||
194 | } | ||
195 | BN_nnmod(r, X, order, ctx); | ||
196 | } | ||
197 | while (BN_is_zero(r)); | ||
198 | /* s = (r*priv_key+k*e) mod order */ | ||
199 | if (!tmp) | ||
200 | tmp = BN_CTX_get(ctx); | ||
201 | BN_mod_mul(tmp, priv_key, r, order, ctx); | ||
202 | if (!tmp2) | ||
203 | tmp2 = BN_CTX_get(ctx); | ||
204 | BN_mod_mul(tmp2, k, e, order, ctx); | ||
205 | BN_mod_add(s, tmp, tmp2, order, ctx); | ||
206 | } | ||
207 | while (BN_is_zero(s)); | ||
208 | |||
209 | err: | ||
210 | BN_CTX_end(ctx); | ||
211 | BN_CTX_free(ctx); | ||
212 | EC_POINT_free(C); | ||
213 | BN_free(md); | ||
214 | return newsig; | ||
215 | } | ||
216 | |||
217 | int gost2001_do_verify(BIGNUM * md, ECDSA_SIG * sig, GOST_KEY * ec) | ||
218 | { | ||
219 | BN_CTX *ctx = BN_CTX_new(); | ||
220 | const EC_GROUP *group = GOST_KEY_get0_group(ec); | ||
221 | BIGNUM *order; | ||
222 | BIGNUM *e = NULL, *R = NULL, *v = NULL, *z1 = NULL, *z2 = NULL; | ||
223 | BIGNUM *X = NULL, *tmp = NULL; | ||
224 | EC_POINT *C = NULL; | ||
225 | const EC_POINT *pub_key = NULL; | ||
226 | int ok = 0; | ||
227 | |||
228 | BN_CTX_start(ctx); | ||
229 | order = BN_CTX_get(ctx); | ||
230 | e = BN_CTX_get(ctx); | ||
231 | z1 = BN_CTX_get(ctx); | ||
232 | z2 = BN_CTX_get(ctx); | ||
233 | tmp = BN_CTX_get(ctx); | ||
234 | X = BN_CTX_get(ctx); | ||
235 | R = BN_CTX_get(ctx); | ||
236 | v = BN_CTX_get(ctx); | ||
237 | |||
238 | EC_GROUP_get_order(group, order, ctx); | ||
239 | pub_key = GOST_KEY_get0_public_key(ec); | ||
240 | if (BN_is_zero(sig->s) || BN_is_zero(sig->r) || | ||
241 | (BN_cmp(sig->s, order) >= 1) || (BN_cmp(sig->r, order) >= 1)) { | ||
242 | GOSTerr(GOST_F_GOST2001_DO_VERIFY, GOST_R_SIGNATURE_PARTS_GREATER_THAN_Q); | ||
243 | goto err; | ||
244 | |||
245 | } | ||
246 | |||
247 | BN_mod(e, md, order, ctx); | ||
248 | if (BN_is_zero(e)) | ||
249 | BN_one(e); | ||
250 | v = BN_mod_inverse(v, e, order, ctx); | ||
251 | BN_mod_mul(z1, sig->s, v, order, ctx); | ||
252 | BN_sub(tmp, order, sig->r); | ||
253 | BN_mod_mul(z2, tmp, v, order, ctx); | ||
254 | C = EC_POINT_new(group); | ||
255 | if (!EC_POINT_mul(group, C, z1, pub_key, z2, ctx)) { | ||
256 | GOSTerr(GOST_F_GOST2001_DO_VERIFY, ERR_R_EC_LIB); | ||
257 | goto err; | ||
258 | } | ||
259 | if (!EC_POINT_get_affine_coordinates_GFp(group, C, X, NULL, ctx)) { | ||
260 | GOSTerr(GOST_F_GOST2001_DO_VERIFY, ERR_R_EC_LIB); | ||
261 | goto err; | ||
262 | } | ||
263 | BN_mod(R, X, order, ctx); | ||
264 | if (BN_cmp(R, sig->r) != 0) { | ||
265 | GOSTerr(GOST_F_GOST2001_DO_VERIFY, GOST_R_SIGNATURE_MISMATCH); | ||
266 | } else { | ||
267 | ok = 1; | ||
268 | } | ||
269 | err: | ||
270 | EC_POINT_free(C); | ||
271 | BN_CTX_end(ctx); | ||
272 | BN_CTX_free(ctx); | ||
273 | return ok; | ||
274 | } | ||
275 | |||
276 | |||
277 | /* Implementation of CryptoPro VKO 34.10-2001 algorithm */ | ||
278 | void VKO_compute_key(BIGNUM * X, BIGNUM * Y, | ||
279 | const GOST_KEY * pkey, GOST_KEY * priv_key, | ||
280 | const BIGNUM * ukm) | ||
281 | { | ||
282 | BIGNUM *p = NULL, *order = NULL; | ||
283 | const BIGNUM *key = GOST_KEY_get0_private_key(priv_key); | ||
284 | const EC_POINT *pub_key = GOST_KEY_get0_public_key(pkey); | ||
285 | EC_POINT *pnt = EC_POINT_new(GOST_KEY_get0_group(priv_key)); | ||
286 | BN_CTX *ctx = BN_CTX_new(); | ||
287 | |||
288 | BN_CTX_start(ctx); | ||
289 | p = BN_CTX_get(ctx); | ||
290 | order = BN_CTX_get(ctx); | ||
291 | EC_GROUP_get_order(GOST_KEY_get0_group(priv_key), order, ctx); | ||
292 | BN_mod_mul(p, key, ukm, order, ctx); | ||
293 | EC_POINT_mul(GOST_KEY_get0_group(priv_key), pnt, NULL, pub_key, p, ctx); | ||
294 | EC_POINT_get_affine_coordinates_GFp(GOST_KEY_get0_group(priv_key), | ||
295 | pnt, X, Y, ctx); | ||
296 | BN_CTX_end(ctx); | ||
297 | BN_CTX_free(ctx); | ||
298 | EC_POINT_free(pnt); | ||
299 | } | ||
300 | |||
301 | int gost2001_keygen(GOST_KEY * ec) | ||
302 | { | ||
303 | BIGNUM *order = BN_new(), *d = BN_new(); | ||
304 | const EC_GROUP *group = GOST_KEY_get0_group(ec); | ||
305 | EC_GROUP_get_order(group, order, NULL); | ||
306 | |||
307 | do { | ||
308 | if (!BN_rand_range(d, order)) { | ||
309 | GOSTerr(GOST_F_GOST2001_KEYGEN, | ||
310 | GOST_R_RANDOM_NUMBER_GENERATOR_FAILED); | ||
311 | BN_free(d); | ||
312 | BN_free(order); | ||
313 | return 0; | ||
314 | } | ||
315 | } while (BN_is_zero(d)); | ||
316 | GOST_KEY_set_private_key(ec, d); | ||
317 | BN_free(d); | ||
318 | BN_free(order); | ||
319 | return gost2001_compute_public(ec); | ||
320 | } | ||
321 | #endif | ||
diff --git a/src/lib/libcrypto/gost/gostr341001_ameth.c b/src/lib/libcrypto/gost/gostr341001_ameth.c new file mode 100644 index 0000000000..09b851cef4 --- /dev/null +++ b/src/lib/libcrypto/gost/gostr341001_ameth.c | |||
@@ -0,0 +1,656 @@ | |||
1 | /* $OpenBSD: gostr341001_ameth.c,v 1.1 2014/11/09 19:17:13 miod Exp $ */ | ||
2 | /* | ||
3 | * Copyright (c) 2014 Dmitry Eremin-Solenikov <dbaryshkov@gmail.com> | ||
4 | * Copyright (c) 2005-2006 Cryptocom LTD | ||
5 | * | ||
6 | * Redistribution and use in source and binary forms, with or without | ||
7 | * modification, are permitted provided that the following conditions | ||
8 | * are met: | ||
9 | * | ||
10 | * 1. Redistributions of source code must retain the above copyright | ||
11 | * notice, this list of conditions and the following disclaimer. | ||
12 | * | ||
13 | * 2. Redistributions in binary form must reproduce the above copyright | ||
14 | * notice, this list of conditions and the following disclaimer in | ||
15 | * the documentation and/or other materials provided with the | ||
16 | * distribution. | ||
17 | * | ||
18 | * 3. All advertising materials mentioning features or use of this | ||
19 | * software must display the following acknowledgment: | ||
20 | * "This product includes software developed by the OpenSSL Project | ||
21 | * for use in the OpenSSL Toolkit. (http://www.openssl.org/)" | ||
22 | * | ||
23 | * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to | ||
24 | * endorse or promote products derived from this software without | ||
25 | * prior written permission. For written permission, please contact | ||
26 | * openssl-core@openssl.org. | ||
27 | * | ||
28 | * 5. Products derived from this software may not be called "OpenSSL" | ||
29 | * nor may "OpenSSL" appear in their names without prior written | ||
30 | * permission of the OpenSSL Project. | ||
31 | * | ||
32 | * 6. Redistributions of any form whatsoever must retain the following | ||
33 | * acknowledgment: | ||
34 | * "This product includes software developed by the OpenSSL Project | ||
35 | * for use in the OpenSSL Toolkit (http://www.openssl.org/)" | ||
36 | * | ||
37 | * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY | ||
38 | * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | ||
39 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR | ||
40 | * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR | ||
41 | * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, | ||
42 | * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT | ||
43 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; | ||
44 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | ||
45 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, | ||
46 | * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) | ||
47 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED | ||
48 | * OF THE POSSIBILITY OF SUCH DAMAGE. | ||
49 | * ==================================================================== | ||
50 | */ | ||
51 | |||
52 | #include <string.h> | ||
53 | |||
54 | #include <openssl/opensslconf.h> | ||
55 | |||
56 | #ifndef OPENSSL_NO_GOST | ||
57 | #include <openssl/evp.h> | ||
58 | #include <openssl/ec.h> | ||
59 | #include <openssl/err.h> | ||
60 | #include <openssl/x509.h> | ||
61 | #include <openssl/gost.h> | ||
62 | |||
63 | #ifndef OPENSSL_NO_CMS | ||
64 | #include <openssl/cms.h> | ||
65 | #endif | ||
66 | |||
67 | #include "asn1_locl.h" | ||
68 | #include "gost_locl.h" | ||
69 | #include "gost_asn1.h" | ||
70 | |||
71 | static void pkey_free_gost01(EVP_PKEY *key) | ||
72 | { | ||
73 | GOST_KEY_free(key->pkey.gost); | ||
74 | } | ||
75 | |||
76 | /* Parses GOST algorithm parameters from X509_ALGOR and | ||
77 | * modifies pkey setting NID and parameters | ||
78 | */ | ||
79 | static int decode_gost01_algor_params(EVP_PKEY * pkey, const unsigned char **p, int len) | ||
80 | { | ||
81 | int param_nid = NID_undef, digest_nid = NID_undef; | ||
82 | GOST_KEY_PARAMS *gkp = NULL; | ||
83 | EC_GROUP *group; | ||
84 | GOST_KEY *ec; | ||
85 | |||
86 | gkp = d2i_GOST_KEY_PARAMS(NULL, p, len); | ||
87 | if (!gkp) { | ||
88 | GOSTerr(GOST_F_DECODE_GOST01_ALGOR_PARAMS, | ||
89 | GOST_R_BAD_PKEY_PARAMETERS_FORMAT); | ||
90 | return 0; | ||
91 | } | ||
92 | param_nid = OBJ_obj2nid(gkp->key_params); | ||
93 | digest_nid = OBJ_obj2nid(gkp->hash_params); | ||
94 | GOST_KEY_PARAMS_free(gkp); | ||
95 | ec = pkey->pkey.gost; | ||
96 | if (!ec) { | ||
97 | ec = GOST_KEY_new(); | ||
98 | if (!EVP_PKEY_assign_GOST(pkey, ec)) | ||
99 | return 0; | ||
100 | } | ||
101 | |||
102 | group = EC_GROUP_new_by_curve_name(param_nid); | ||
103 | if (group == NULL) | ||
104 | return 0; | ||
105 | EC_GROUP_set_asn1_flag(group, OPENSSL_EC_NAMED_CURVE); | ||
106 | if (GOST_KEY_set_group(ec, group) == 0) { | ||
107 | EC_GROUP_free(group); | ||
108 | return 0; | ||
109 | } | ||
110 | EC_GROUP_free(group); | ||
111 | if (GOST_KEY_set_digest(ec, digest_nid) == 0) | ||
112 | return 0; | ||
113 | return 1; | ||
114 | } | ||
115 | |||
116 | static ASN1_STRING *encode_gost01_algor_params(const EVP_PKEY * key) | ||
117 | { | ||
118 | ASN1_STRING *params = ASN1_STRING_new(); | ||
119 | GOST_KEY_PARAMS *gkp = GOST_KEY_PARAMS_new(); | ||
120 | int pkey_param_nid = NID_undef; | ||
121 | |||
122 | if (!params || !gkp) { | ||
123 | GOSTerr(GOST_F_ENCODE_GOST01_ALGOR_PARAMS, ERR_R_MALLOC_FAILURE); | ||
124 | ASN1_STRING_free(params); | ||
125 | params = NULL; | ||
126 | goto err; | ||
127 | } | ||
128 | |||
129 | pkey_param_nid = EC_GROUP_get_curve_name(GOST_KEY_get0_group(key->pkey.gost)); | ||
130 | gkp->key_params = OBJ_nid2obj(pkey_param_nid); | ||
131 | gkp->hash_params = OBJ_nid2obj(GOST_KEY_get_digest(key->pkey.gost)); | ||
132 | /*gkp->cipher_params = OBJ_nid2obj(cipher_param_nid); */ | ||
133 | params->length = i2d_GOST_KEY_PARAMS(gkp, ¶ms->data); | ||
134 | if (params->length <= 0) { | ||
135 | GOSTerr(GOST_F_ENCODE_GOST01_ALGOR_PARAMS, ERR_R_MALLOC_FAILURE); | ||
136 | ASN1_STRING_free(params); | ||
137 | params = NULL; | ||
138 | goto err; | ||
139 | } | ||
140 | params->type = V_ASN1_SEQUENCE; | ||
141 | err: | ||
142 | GOST_KEY_PARAMS_free(gkp); | ||
143 | return params; | ||
144 | } | ||
145 | |||
146 | static int pub_cmp_gost01(const EVP_PKEY * a, const EVP_PKEY * b) | ||
147 | { | ||
148 | const GOST_KEY *ea = a->pkey.gost; | ||
149 | const GOST_KEY *eb = b->pkey.gost; | ||
150 | const EC_POINT *ka, *kb; | ||
151 | int ret = 0; | ||
152 | if (!ea || !eb) | ||
153 | return 0; | ||
154 | ka = GOST_KEY_get0_public_key(ea); | ||
155 | kb = GOST_KEY_get0_public_key(eb); | ||
156 | if (!ka || !kb) | ||
157 | return 0; | ||
158 | ret = (0 == EC_POINT_cmp(GOST_KEY_get0_group(ea), ka, kb, NULL)); | ||
159 | return ret; | ||
160 | } | ||
161 | |||
162 | static int pkey_size_gost01(const EVP_PKEY * pk) | ||
163 | { | ||
164 | if (GOST_KEY_get_digest(pk->pkey.gost) == NID_id_tc26_gost3411_2012_512) | ||
165 | return 128; | ||
166 | return 64; | ||
167 | } | ||
168 | |||
169 | static int pkey_bits_gost01(const EVP_PKEY * pk) | ||
170 | { | ||
171 | if (GOST_KEY_get_digest(pk->pkey.gost) == NID_id_tc26_gost3411_2012_512) | ||
172 | return 512; | ||
173 | return 256; | ||
174 | } | ||
175 | |||
176 | static int pub_decode_gost01(EVP_PKEY *pk, X509_PUBKEY *pub) | ||
177 | { | ||
178 | X509_ALGOR *palg = NULL; | ||
179 | const unsigned char *pubkey_buf = NULL; | ||
180 | const unsigned char *p; | ||
181 | ASN1_OBJECT *palgobj = NULL; | ||
182 | int pub_len; | ||
183 | BIGNUM *X, *Y; | ||
184 | ASN1_OCTET_STRING *octet = NULL; | ||
185 | int len; | ||
186 | int ret; | ||
187 | int ptype = V_ASN1_UNDEF; | ||
188 | ASN1_STRING *pval = NULL; | ||
189 | |||
190 | if (!X509_PUBKEY_get0_param(&palgobj, &pubkey_buf, &pub_len, | ||
191 | &palg, pub)) | ||
192 | return 0; | ||
193 | EVP_PKEY_assign_GOST(pk, NULL); | ||
194 | X509_ALGOR_get0(NULL, &ptype, (void **)&pval, palg); | ||
195 | if (ptype != V_ASN1_SEQUENCE) { | ||
196 | GOSTerr(GOST_F_PUB_DECODE_GOST01, | ||
197 | GOST_R_BAD_KEY_PARAMETERS_FORMAT); | ||
198 | return 0; | ||
199 | } | ||
200 | p = pval->data; | ||
201 | if (!decode_gost01_algor_params(pk, &p, pval->length)) | ||
202 | return 0; | ||
203 | octet = d2i_ASN1_OCTET_STRING(NULL, &pubkey_buf, pub_len); | ||
204 | if (!octet) { | ||
205 | GOSTerr(GOST_F_PUB_DECODE_GOST01, ERR_R_MALLOC_FAILURE); | ||
206 | return 0; | ||
207 | } | ||
208 | len = octet->length / 2; | ||
209 | |||
210 | X = GOST_le2bn(octet->data, len, NULL); | ||
211 | Y = GOST_le2bn(octet->data + len, len, NULL); | ||
212 | |||
213 | ASN1_OCTET_STRING_free(octet); | ||
214 | |||
215 | ret = GOST_KEY_set_public_key_affine_coordinates(pk->pkey.gost, X, Y); | ||
216 | if (!ret) | ||
217 | GOSTerr(GOST_F_PUB_DECODE_GOST01, ERR_R_EC_LIB); | ||
218 | |||
219 | BN_free(X); | ||
220 | BN_free(Y); | ||
221 | |||
222 | return ret; | ||
223 | |||
224 | } | ||
225 | |||
226 | static int pub_encode_gost01(X509_PUBKEY * pub, const EVP_PKEY * pk) | ||
227 | { | ||
228 | ASN1_OBJECT *algobj = NULL; | ||
229 | ASN1_OCTET_STRING *octet = NULL; | ||
230 | void *pval = NULL; | ||
231 | unsigned char *buf = NULL, *sptr; | ||
232 | int key_size, ret = 0; | ||
233 | const EC_POINT *pub_key; | ||
234 | BIGNUM *X, *Y; | ||
235 | const GOST_KEY *ec = pk->pkey.gost; | ||
236 | int ptype = V_ASN1_UNDEF; | ||
237 | |||
238 | algobj = OBJ_nid2obj(GostR3410_get_pk_digest(GOST_KEY_get_digest(ec))); | ||
239 | if (pk->save_parameters) { | ||
240 | ASN1_STRING *params = encode_gost01_algor_params(pk); | ||
241 | pval = params; | ||
242 | ptype = V_ASN1_SEQUENCE; | ||
243 | } | ||
244 | |||
245 | key_size = GOST_KEY_get_size(ec); | ||
246 | |||
247 | pub_key = GOST_KEY_get0_public_key(ec); | ||
248 | if (!pub_key) { | ||
249 | GOSTerr(GOST_F_PUB_ENCODE_GOST01, GOST_R_PUBLIC_KEY_UNDEFINED); | ||
250 | return 0; | ||
251 | } | ||
252 | |||
253 | octet = ASN1_OCTET_STRING_new(); | ||
254 | if (!octet) { | ||
255 | GOSTerr(GOST_F_PUB_ENCODE_GOST01, ERR_R_MALLOC_FAILURE); | ||
256 | return 0; | ||
257 | } | ||
258 | |||
259 | ret = ASN1_STRING_set(octet, NULL, 2 * key_size); | ||
260 | if (!ret) { | ||
261 | GOSTerr(GOST_F_PUB_ENCODE_GOST01, ERR_R_INTERNAL_ERROR); | ||
262 | ASN1_BIT_STRING_free(octet); | ||
263 | return 0; | ||
264 | } | ||
265 | |||
266 | sptr = ASN1_STRING_data(octet); | ||
267 | |||
268 | X = BN_new(); | ||
269 | Y = BN_new(); | ||
270 | if (!X || !Y) { | ||
271 | GOSTerr(GOST_F_PUB_ENCODE_GOST01, ERR_R_MALLOC_FAILURE); | ||
272 | ASN1_BIT_STRING_free(octet); | ||
273 | BN_free(X); | ||
274 | BN_free(Y); | ||
275 | return 0; | ||
276 | } | ||
277 | |||
278 | EC_POINT_get_affine_coordinates_GFp(GOST_KEY_get0_group(ec), | ||
279 | pub_key, X, Y, NULL); | ||
280 | |||
281 | GOST_bn2le(X, sptr, key_size); | ||
282 | GOST_bn2le(Y, sptr + key_size, key_size); | ||
283 | |||
284 | BN_free(X); | ||
285 | BN_free(Y); | ||
286 | |||
287 | ret = i2d_ASN1_OCTET_STRING(octet, &buf); | ||
288 | ASN1_BIT_STRING_free(octet); | ||
289 | if (ret < 0) | ||
290 | return 0; | ||
291 | |||
292 | return X509_PUBKEY_set0_param(pub, algobj, ptype, pval, buf, ret); | ||
293 | } | ||
294 | |||
295 | static int param_print_gost01(BIO * out, const EVP_PKEY * pkey, int indent, | ||
296 | ASN1_PCTX * pctx) | ||
297 | { | ||
298 | int param_nid = EC_GROUP_get_curve_name(GOST_KEY_get0_group(pkey->pkey.gost)); | ||
299 | if (!BIO_indent(out, indent, 128)) | ||
300 | return 0; | ||
301 | BIO_printf(out, "Parameter set: %s\n", OBJ_nid2ln(param_nid)); | ||
302 | if (!BIO_indent(out, indent, 128)) | ||
303 | return 0; | ||
304 | BIO_printf(out, "Digest Algorithm: %s\n", OBJ_nid2ln(GOST_KEY_get_digest(pkey->pkey.gost))); | ||
305 | return 1; | ||
306 | } | ||
307 | |||
308 | static int pub_print_gost01(BIO * out, const EVP_PKEY * pkey, int indent, | ||
309 | ASN1_PCTX * pctx) | ||
310 | { | ||
311 | BN_CTX *ctx = BN_CTX_new(); | ||
312 | BIGNUM *X, *Y; | ||
313 | const EC_POINT *pubkey; | ||
314 | const EC_GROUP *group; | ||
315 | |||
316 | if (!ctx) { | ||
317 | GOSTerr(GOST_F_PUB_PRINT_GOST01, ERR_R_MALLOC_FAILURE); | ||
318 | return 0; | ||
319 | } | ||
320 | BN_CTX_start(ctx); | ||
321 | X = BN_CTX_get(ctx); | ||
322 | Y = BN_CTX_get(ctx); | ||
323 | pubkey = GOST_KEY_get0_public_key(pkey->pkey.gost); | ||
324 | group = GOST_KEY_get0_group(pkey->pkey.gost); | ||
325 | if (!EC_POINT_get_affine_coordinates_GFp(group, pubkey, X, Y, ctx)) { | ||
326 | GOSTerr(GOST_F_PUB_PRINT_GOST01, ERR_R_EC_LIB); | ||
327 | BN_CTX_free(ctx); | ||
328 | return 0; | ||
329 | } | ||
330 | if (!BIO_indent(out, indent, 128)) | ||
331 | return 0; | ||
332 | BIO_printf(out, "Public key:\n"); | ||
333 | if (!BIO_indent(out, indent + 3, 128)) | ||
334 | return 0; | ||
335 | BIO_printf(out, "X:"); | ||
336 | BN_print(out, X); | ||
337 | BIO_printf(out, "\n"); | ||
338 | BIO_indent(out, indent + 3, 128); | ||
339 | BIO_printf(out, "Y:"); | ||
340 | BN_print(out, Y); | ||
341 | BIO_printf(out, "\n"); | ||
342 | BN_CTX_end(ctx); | ||
343 | BN_CTX_free(ctx); | ||
344 | |||
345 | return param_print_gost01(out, pkey, indent, pctx); | ||
346 | } | ||
347 | |||
348 | static int priv_print_gost01(BIO * out, const EVP_PKEY * pkey, int indent, | ||
349 | ASN1_PCTX * pctx) | ||
350 | { | ||
351 | const BIGNUM *key; | ||
352 | |||
353 | if (!BIO_indent(out, indent, 128)) | ||
354 | return 0; | ||
355 | BIO_printf(out, "Private key: "); | ||
356 | key = GOST_KEY_get0_private_key(pkey->pkey.gost); | ||
357 | if (!key) | ||
358 | BIO_printf(out, "<undefined)"); | ||
359 | else | ||
360 | BN_print(out, key); | ||
361 | BIO_printf(out, "\n"); | ||
362 | |||
363 | return pub_print_gost01(out, pkey, indent, pctx); | ||
364 | } | ||
365 | |||
366 | static int priv_decode_gost01(EVP_PKEY * pk, PKCS8_PRIV_KEY_INFO * p8inf) | ||
367 | { | ||
368 | const unsigned char *pkey_buf = NULL, *p = NULL; | ||
369 | int priv_len = 0; | ||
370 | BIGNUM *pk_num = NULL; | ||
371 | int ret = 0; | ||
372 | X509_ALGOR *palg = NULL; | ||
373 | ASN1_OBJECT *palg_obj = NULL; | ||
374 | ASN1_INTEGER *priv_key = NULL; | ||
375 | GOST_KEY *ec; | ||
376 | int ptype = V_ASN1_UNDEF; | ||
377 | ASN1_STRING *pval = NULL; | ||
378 | |||
379 | if (!PKCS8_pkey_get0(&palg_obj, &pkey_buf, &priv_len, &palg, p8inf)) | ||
380 | return 0; | ||
381 | EVP_PKEY_assign_GOST(pk, NULL); | ||
382 | X509_ALGOR_get0(NULL, &ptype, (void **)&pval, palg); | ||
383 | if (ptype != V_ASN1_SEQUENCE) { | ||
384 | GOSTerr(GOST_F_PUB_DECODE_GOST01, | ||
385 | GOST_R_BAD_KEY_PARAMETERS_FORMAT); | ||
386 | return 0; | ||
387 | } | ||
388 | p = pval->data; | ||
389 | if (!decode_gost01_algor_params(pk, &p, pval->length)) | ||
390 | return 0; | ||
391 | p = pkey_buf; | ||
392 | if (V_ASN1_OCTET_STRING == *p) { | ||
393 | /* New format - Little endian octet string */ | ||
394 | unsigned char rev_buf[32]; | ||
395 | int i; | ||
396 | ASN1_OCTET_STRING *s = d2i_ASN1_OCTET_STRING(NULL, &p, priv_len); | ||
397 | if (!s || s->length != 32) { | ||
398 | GOSTerr(GOST_F_PRIV_DECODE_GOST01, EVP_R_DECODE_ERROR); | ||
399 | return 0; | ||
400 | } | ||
401 | for (i = 0; i < 32; i++) { | ||
402 | rev_buf[31 - i] = s->data[i]; | ||
403 | } | ||
404 | ASN1_STRING_free(s); | ||
405 | pk_num = BN_bin2bn(rev_buf, 32, NULL); | ||
406 | } else { | ||
407 | priv_key = d2i_ASN1_INTEGER(NULL, &p, priv_len); | ||
408 | if (!priv_key) | ||
409 | return 0; | ||
410 | ret = ((pk_num = ASN1_INTEGER_to_BN(priv_key, NULL)) != NULL); | ||
411 | ASN1_INTEGER_free(priv_key); | ||
412 | if (!ret) { | ||
413 | GOSTerr(GOST_F_PRIV_DECODE_GOST01, EVP_R_DECODE_ERROR); | ||
414 | return 0; | ||
415 | } | ||
416 | } | ||
417 | |||
418 | ec = pk->pkey.gost; | ||
419 | if (!ec) { | ||
420 | ec = GOST_KEY_new(); | ||
421 | EVP_PKEY_assign_GOST(pk, ec); | ||
422 | } | ||
423 | if (!GOST_KEY_set_private_key(ec, pk_num)) { | ||
424 | BN_free(pk_num); | ||
425 | return 0; | ||
426 | } | ||
427 | if (!EVP_PKEY_missing_parameters(pk)) | ||
428 | gost2001_compute_public(ec); | ||
429 | BN_free(pk_num); | ||
430 | |||
431 | return 1; | ||
432 | } | ||
433 | |||
434 | static int priv_encode_gost01(PKCS8_PRIV_KEY_INFO * p8, const EVP_PKEY * pk) | ||
435 | { | ||
436 | ASN1_OBJECT *algobj = OBJ_nid2obj(GostR3410_get_pk_digest(GOST_KEY_get_digest(pk->pkey.gost))); | ||
437 | ASN1_STRING *params = encode_gost01_algor_params(pk); | ||
438 | unsigned char *priv_buf = NULL; | ||
439 | int priv_len; | ||
440 | |||
441 | ASN1_INTEGER *asn1key = NULL; | ||
442 | if (!params) { | ||
443 | return 0; | ||
444 | } | ||
445 | asn1key = BN_to_ASN1_INTEGER(GOST_KEY_get0_private_key(pk->pkey.gost), NULL); | ||
446 | priv_len = i2d_ASN1_INTEGER(asn1key, &priv_buf); | ||
447 | ASN1_INTEGER_free(asn1key); | ||
448 | return PKCS8_pkey_set0(p8, algobj, 0, V_ASN1_SEQUENCE, params, | ||
449 | priv_buf, priv_len); | ||
450 | } | ||
451 | |||
452 | static int param_encode_gost01(const EVP_PKEY * pkey, unsigned char **pder) | ||
453 | { | ||
454 | ASN1_STRING *params = encode_gost01_algor_params(pkey); | ||
455 | int len; | ||
456 | if (!params) | ||
457 | return 0; | ||
458 | len = params->length; | ||
459 | if (pder) | ||
460 | memcpy(*pder, params->data, params->length); | ||
461 | ASN1_STRING_free(params); | ||
462 | return len; | ||
463 | } | ||
464 | |||
465 | static int param_decode_gost01(EVP_PKEY * pkey, const unsigned char **pder, | ||
466 | int derlen) | ||
467 | { | ||
468 | ASN1_OBJECT *obj = NULL; | ||
469 | int nid; | ||
470 | GOST_KEY *ec; | ||
471 | EC_GROUP *group; | ||
472 | |||
473 | /* New format */ | ||
474 | if ((V_ASN1_SEQUENCE | V_ASN1_CONSTRUCTED) == **pder) | ||
475 | return decode_gost01_algor_params(pkey, pder, derlen); | ||
476 | |||
477 | /* Compatibility */ | ||
478 | if (d2i_ASN1_OBJECT(&obj, pder, derlen) == NULL) { | ||
479 | GOSTerr(GOST_F_PARAM_DECODE_GOST01, ERR_R_MALLOC_FAILURE); | ||
480 | return 0; | ||
481 | } | ||
482 | nid = OBJ_obj2nid(obj); | ||
483 | ASN1_OBJECT_free(obj); | ||
484 | |||
485 | ec = GOST_KEY_new(); | ||
486 | if (!ec) { | ||
487 | GOSTerr(GOST_F_PARAM_DECODE_GOST01, ERR_R_MALLOC_FAILURE); | ||
488 | return 0; | ||
489 | } | ||
490 | group = EC_GROUP_new_by_curve_name(nid); | ||
491 | if (group == NULL) { | ||
492 | GOSTerr(GOST_F_PARAM_DECODE_GOST01, EC_R_EC_GROUP_NEW_BY_NAME_FAILURE); | ||
493 | GOST_KEY_free(ec); | ||
494 | return 0; | ||
495 | } | ||
496 | |||
497 | EC_GROUP_set_asn1_flag(group, OPENSSL_EC_NAMED_CURVE); | ||
498 | if (GOST_KEY_set_group(ec, group) == 0) { | ||
499 | GOSTerr(GOST_F_PARAM_DECODE_GOST01, ERR_R_EC_LIB); | ||
500 | EC_GROUP_free(group); | ||
501 | GOST_KEY_free(ec); | ||
502 | return 0; | ||
503 | } | ||
504 | EC_GROUP_free(group); | ||
505 | if (GOST_KEY_set_digest(ec, NID_id_GostR3411_94_CryptoProParamSet) == 0) { | ||
506 | GOSTerr(GOST_F_PARAM_DECODE_GOST01, GOST_R_INVALID_DIGEST_TYPE); | ||
507 | GOST_KEY_free(ec); | ||
508 | return 0; | ||
509 | } | ||
510 | EVP_PKEY_assign_GOST(pkey, ec); | ||
511 | return 1; | ||
512 | } | ||
513 | |||
514 | static int param_missing_gost01(const EVP_PKEY * pk) | ||
515 | { | ||
516 | const GOST_KEY *ec = pk->pkey.gost; | ||
517 | if (!ec) | ||
518 | return 1; | ||
519 | if (!GOST_KEY_get0_group(ec)) | ||
520 | return 1; | ||
521 | if (GOST_KEY_get_digest(ec) == NID_undef) | ||
522 | return 1; | ||
523 | return 0; | ||
524 | } | ||
525 | |||
526 | static int param_copy_gost01(EVP_PKEY * to, const EVP_PKEY * from) | ||
527 | { | ||
528 | GOST_KEY *eto = to->pkey.gost; | ||
529 | const GOST_KEY *efrom = from->pkey.gost; | ||
530 | if (EVP_PKEY_base_id(from) != EVP_PKEY_base_id(to)) { | ||
531 | GOSTerr(GOST_F_PARAM_COPY_GOST01, | ||
532 | GOST_R_INCOMPATIBLE_ALGORITHMS); | ||
533 | return 0; | ||
534 | } | ||
535 | if (!efrom) { | ||
536 | GOSTerr(GOST_F_PARAM_COPY_GOST01, | ||
537 | GOST_R_KEY_PARAMETERS_MISSING); | ||
538 | return 0; | ||
539 | } | ||
540 | if (!eto) { | ||
541 | eto = GOST_KEY_new(); | ||
542 | EVP_PKEY_assign(to, EVP_PKEY_base_id(from), eto); | ||
543 | } | ||
544 | GOST_KEY_set_group(eto, GOST_KEY_get0_group(efrom)); | ||
545 | GOST_KEY_set_digest(eto, GOST_KEY_get_digest(efrom)); | ||
546 | if (GOST_KEY_get0_private_key(eto)) { | ||
547 | gost2001_compute_public(eto); | ||
548 | } | ||
549 | return 1; | ||
550 | } | ||
551 | |||
552 | static int param_cmp_gost01(const EVP_PKEY * a, const EVP_PKEY * b) | ||
553 | { | ||
554 | if (EC_GROUP_get_curve_name(GOST_KEY_get0_group(a->pkey.gost)) != | ||
555 | EC_GROUP_get_curve_name(GOST_KEY_get0_group(b->pkey.gost))) { | ||
556 | return 0; | ||
557 | } | ||
558 | if (GOST_KEY_get_digest(a->pkey.gost) != | ||
559 | GOST_KEY_get_digest(b->pkey.gost)) | ||
560 | return 0; | ||
561 | return 1; | ||
562 | |||
563 | } | ||
564 | |||
565 | static int pkey_ctrl_gost01(EVP_PKEY * pkey, int op, long arg1, void *arg2) | ||
566 | { | ||
567 | X509_ALGOR *alg1 = NULL, *alg2 = NULL, *alg3 = NULL; | ||
568 | int digest = GOST_KEY_get_digest(pkey->pkey.gost); | ||
569 | |||
570 | switch (op) { | ||
571 | case ASN1_PKEY_CTRL_PKCS7_SIGN: | ||
572 | if (arg1 == 0) | ||
573 | PKCS7_SIGNER_INFO_get0_algs(arg2, NULL, &alg1, &alg2); | ||
574 | break; | ||
575 | |||
576 | case ASN1_PKEY_CTRL_PKCS7_ENCRYPT: | ||
577 | if (arg1 == 0) | ||
578 | PKCS7_RECIP_INFO_get0_alg(arg2, &alg3); | ||
579 | break; | ||
580 | #ifndef OPENSSL_NO_CMS | ||
581 | case ASN1_PKEY_CTRL_CMS_SIGN: | ||
582 | if (arg1 == 0) | ||
583 | CMS_SignerInfo_get0_algs(arg2, NULL, NULL, &alg1, &alg2); | ||
584 | break; | ||
585 | |||
586 | case ASN1_PKEY_CTRL_CMS_ENVELOPE: | ||
587 | if (arg1 == 0) | ||
588 | CMS_RecipientInfo_ktri_get0_algs(arg2, NULL, NULL, &alg3); | ||
589 | break; | ||
590 | #endif | ||
591 | case ASN1_PKEY_CTRL_DEFAULT_MD_NID: | ||
592 | *(int *)arg2 = GostR3410_get_md_digest(digest); | ||
593 | return 2; | ||
594 | |||
595 | default: | ||
596 | return -2; | ||
597 | } | ||
598 | |||
599 | if (alg1) | ||
600 | X509_ALGOR_set0(alg1, OBJ_nid2obj(GostR3410_get_md_digest(digest)), V_ASN1_NULL, 0); | ||
601 | if (alg2) | ||
602 | X509_ALGOR_set0(alg2, OBJ_nid2obj(GostR3410_get_pk_digest(digest)), V_ASN1_NULL, 0); | ||
603 | if (alg3) { | ||
604 | ASN1_STRING *params = encode_gost01_algor_params(pkey); | ||
605 | if (!params) { | ||
606 | return -1; | ||
607 | } | ||
608 | X509_ALGOR_set0(alg3, OBJ_nid2obj(GostR3410_get_pk_digest(digest)), V_ASN1_SEQUENCE, params); | ||
609 | } | ||
610 | |||
611 | return 1; | ||
612 | } | ||
613 | |||
614 | const EVP_PKEY_ASN1_METHOD gostr01_asn1_meths[] = { | ||
615 | { | ||
616 | .pkey_id = EVP_PKEY_GOSTR01, | ||
617 | .pkey_base_id = EVP_PKEY_GOSTR01, | ||
618 | .pkey_flags = ASN1_PKEY_SIGPARAM_NULL, | ||
619 | |||
620 | .pem_str = "GOST2001", | ||
621 | .info = "GOST R 34.10-2001", | ||
622 | |||
623 | .pkey_free = pkey_free_gost01, | ||
624 | .pkey_ctrl = pkey_ctrl_gost01, | ||
625 | |||
626 | .priv_decode = priv_decode_gost01, | ||
627 | .priv_encode = priv_encode_gost01, | ||
628 | .priv_print = priv_print_gost01, | ||
629 | |||
630 | .param_decode = param_decode_gost01, | ||
631 | .param_encode = param_encode_gost01, | ||
632 | .param_missing = param_missing_gost01, | ||
633 | .param_copy = param_copy_gost01, | ||
634 | .param_cmp = param_cmp_gost01, | ||
635 | .param_print = param_print_gost01, | ||
636 | |||
637 | .pub_decode = pub_decode_gost01, | ||
638 | .pub_encode = pub_encode_gost01, | ||
639 | .pub_cmp = pub_cmp_gost01, | ||
640 | .pub_print = pub_print_gost01, | ||
641 | .pkey_size = pkey_size_gost01, | ||
642 | .pkey_bits = pkey_bits_gost01, | ||
643 | }, | ||
644 | { | ||
645 | .pkey_id = EVP_PKEY_GOSTR12_256, | ||
646 | .pkey_base_id = EVP_PKEY_GOSTR01, | ||
647 | .pkey_flags = ASN1_PKEY_ALIAS | ||
648 | }, | ||
649 | { | ||
650 | .pkey_id = EVP_PKEY_GOSTR12_512, | ||
651 | .pkey_base_id = EVP_PKEY_GOSTR01, | ||
652 | .pkey_flags = ASN1_PKEY_ALIAS | ||
653 | }, | ||
654 | }; | ||
655 | |||
656 | #endif | ||
diff --git a/src/lib/libcrypto/gost/gostr341001_key.c b/src/lib/libcrypto/gost/gostr341001_key.c new file mode 100644 index 0000000000..9c7f52b769 --- /dev/null +++ b/src/lib/libcrypto/gost/gostr341001_key.c | |||
@@ -0,0 +1,306 @@ | |||
1 | /* $OpenBSD: gostr341001_key.c,v 1.1 2014/11/09 19:17:13 miod Exp $ */ | ||
2 | /* | ||
3 | * Copyright (c) 2014 Dmitry Eremin-Solenikov <dbaryshkov@gmail.com> | ||
4 | * Copyright (c) 2005-2006 Cryptocom LTD | ||
5 | * | ||
6 | * Redistribution and use in source and binary forms, with or without | ||
7 | * modification, are permitted provided that the following conditions | ||
8 | * are met: | ||
9 | * | ||
10 | * 1. Redistributions of source code must retain the above copyright | ||
11 | * notice, this list of conditions and the following disclaimer. | ||
12 | * | ||
13 | * 2. Redistributions in binary form must reproduce the above copyright | ||
14 | * notice, this list of conditions and the following disclaimer in | ||
15 | * the documentation and/or other materials provided with the | ||
16 | * distribution. | ||
17 | * | ||
18 | * 3. All advertising materials mentioning features or use of this | ||
19 | * software must display the following acknowledgment: | ||
20 | * "This product includes software developed by the OpenSSL Project | ||
21 | * for use in the OpenSSL Toolkit. (http://www.openssl.org/)" | ||
22 | * | ||
23 | * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to | ||
24 | * endorse or promote products derived from this software without | ||
25 | * prior written permission. For written permission, please contact | ||
26 | * openssl-core@openssl.org. | ||
27 | * | ||
28 | * 5. Products derived from this software may not be called "OpenSSL" | ||
29 | * nor may "OpenSSL" appear in their names without prior written | ||
30 | * permission of the OpenSSL Project. | ||
31 | * | ||
32 | * 6. Redistributions of any form whatsoever must retain the following | ||
33 | * acknowledgment: | ||
34 | * "This product includes software developed by the OpenSSL Project | ||
35 | * for use in the OpenSSL Toolkit (http://www.openssl.org/)" | ||
36 | * | ||
37 | * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY | ||
38 | * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | ||
39 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR | ||
40 | * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR | ||
41 | * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, | ||
42 | * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT | ||
43 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; | ||
44 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | ||
45 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, | ||
46 | * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) | ||
47 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED | ||
48 | * OF THE POSSIBILITY OF SUCH DAMAGE. | ||
49 | * ==================================================================== | ||
50 | */ | ||
51 | |||
52 | #include <openssl/opensslconf.h> | ||
53 | |||
54 | #ifndef OPENSSL_NO_GOST | ||
55 | #include <openssl/err.h> | ||
56 | #include <openssl/gost.h> | ||
57 | #include <openssl/objects.h> | ||
58 | #include "gost_locl.h" | ||
59 | |||
60 | struct gost_key_st { | ||
61 | EC_GROUP *group; | ||
62 | |||
63 | EC_POINT *pub_key; | ||
64 | BIGNUM *priv_key; | ||
65 | |||
66 | int references; | ||
67 | |||
68 | int digest_nid; | ||
69 | }; | ||
70 | |||
71 | GOST_KEY * GOST_KEY_new(void) | ||
72 | { | ||
73 | GOST_KEY *ret; | ||
74 | |||
75 | ret = malloc(sizeof(GOST_KEY)); | ||
76 | if (ret == NULL) { | ||
77 | GOSTerr(GOST_F_GOST_KEY_NEW, ERR_R_MALLOC_FAILURE); | ||
78 | return (NULL); | ||
79 | } | ||
80 | ret->group = NULL; | ||
81 | ret->pub_key = NULL; | ||
82 | ret->priv_key = NULL; | ||
83 | ret->references = 1; | ||
84 | ret->digest_nid = NID_undef; | ||
85 | return (ret); | ||
86 | } | ||
87 | |||
88 | void GOST_KEY_free(GOST_KEY * r) | ||
89 | { | ||
90 | int i; | ||
91 | |||
92 | if (r == NULL) | ||
93 | return; | ||
94 | |||
95 | i = CRYPTO_add(&r->references, -1, CRYPTO_LOCK_EC); | ||
96 | if (i > 0) | ||
97 | return; | ||
98 | |||
99 | EC_GROUP_free(r->group); | ||
100 | EC_POINT_free(r->pub_key); | ||
101 | BN_clear_free(r->priv_key); | ||
102 | |||
103 | OPENSSL_cleanse((void *) r, sizeof(GOST_KEY)); | ||
104 | |||
105 | free(r); | ||
106 | } | ||
107 | |||
108 | int GOST_KEY_check_key(const GOST_KEY * key) | ||
109 | { | ||
110 | int ok = 0; | ||
111 | BN_CTX *ctx = NULL; | ||
112 | BIGNUM *order = NULL; | ||
113 | EC_POINT *point = NULL; | ||
114 | |||
115 | if (!key || !key->group || !key->pub_key) { | ||
116 | GOSTerr(GOST_F_GOST_KEY_CHECK_KEY, ERR_R_PASSED_NULL_PARAMETER); | ||
117 | return 0; | ||
118 | } | ||
119 | if (EC_POINT_is_at_infinity(key->group, key->pub_key)) { | ||
120 | GOSTerr(GOST_F_GOST_KEY_CHECK_KEY, EC_R_POINT_AT_INFINITY); | ||
121 | goto err; | ||
122 | } | ||
123 | if ((ctx = BN_CTX_new()) == NULL) | ||
124 | goto err; | ||
125 | if ((point = EC_POINT_new(key->group)) == NULL) | ||
126 | goto err; | ||
127 | |||
128 | /* testing whether the pub_key is on the elliptic curve */ | ||
129 | if (!EC_POINT_is_on_curve(key->group, key->pub_key, ctx)) { | ||
130 | GOSTerr(GOST_F_GOST_KEY_CHECK_KEY, EC_R_POINT_IS_NOT_ON_CURVE); | ||
131 | goto err; | ||
132 | } | ||
133 | /* testing whether pub_key * order is the point at infinity */ | ||
134 | if ((order = BN_new()) == NULL) | ||
135 | goto err; | ||
136 | if (!EC_GROUP_get_order(key->group, order, ctx)) { | ||
137 | GOSTerr(GOST_F_GOST_KEY_CHECK_KEY, EC_R_INVALID_GROUP_ORDER); | ||
138 | goto err; | ||
139 | } | ||
140 | if (!EC_POINT_mul(key->group, point, NULL, key->pub_key, order, ctx)) { | ||
141 | GOSTerr(GOST_F_GOST_KEY_CHECK_KEY, ERR_R_EC_LIB); | ||
142 | goto err; | ||
143 | } | ||
144 | if (!EC_POINT_is_at_infinity(key->group, point)) { | ||
145 | GOSTerr(GOST_F_GOST_KEY_CHECK_KEY, EC_R_WRONG_ORDER); | ||
146 | goto err; | ||
147 | } | ||
148 | /* | ||
149 | * in case the priv_key is present : check if generator * priv_key == | ||
150 | * pub_key | ||
151 | */ | ||
152 | if (key->priv_key) { | ||
153 | if (BN_cmp(key->priv_key, order) >= 0) { | ||
154 | GOSTerr(GOST_F_GOST_KEY_CHECK_KEY, EC_R_WRONG_ORDER); | ||
155 | goto err; | ||
156 | } | ||
157 | if (!EC_POINT_mul(key->group, point, key->priv_key, | ||
158 | NULL, NULL, ctx)) { | ||
159 | GOSTerr(GOST_F_GOST_KEY_CHECK_KEY, ERR_R_EC_LIB); | ||
160 | goto err; | ||
161 | } | ||
162 | if (EC_POINT_cmp(key->group, point, key->pub_key, | ||
163 | ctx) != 0) { | ||
164 | GOSTerr(GOST_F_GOST_KEY_CHECK_KEY, EC_R_INVALID_PRIVATE_KEY); | ||
165 | goto err; | ||
166 | } | ||
167 | } | ||
168 | ok = 1; | ||
169 | err: | ||
170 | BN_free(order); | ||
171 | BN_CTX_free(ctx); | ||
172 | EC_POINT_free(point); | ||
173 | return (ok); | ||
174 | } | ||
175 | |||
176 | int GOST_KEY_set_public_key_affine_coordinates(GOST_KEY * key, BIGNUM * x, BIGNUM * y) | ||
177 | { | ||
178 | BN_CTX *ctx = NULL; | ||
179 | BIGNUM *tx, *ty; | ||
180 | EC_POINT *point = NULL; | ||
181 | int ok = 0; | ||
182 | |||
183 | if (!key || !key->group || !x || !y) { | ||
184 | GOSTerr(GOST_F_GOST_KEY_SET_PUBLIC_KEY_AFFINE_COORDINATES, | ||
185 | ERR_R_PASSED_NULL_PARAMETER); | ||
186 | return 0; | ||
187 | } | ||
188 | ctx = BN_CTX_new(); | ||
189 | if (!ctx) | ||
190 | goto err; | ||
191 | |||
192 | point = EC_POINT_new(key->group); | ||
193 | |||
194 | if (!point) | ||
195 | goto err; | ||
196 | |||
197 | tx = BN_CTX_get(ctx); | ||
198 | ty = BN_CTX_get(ctx); | ||
199 | if (!EC_POINT_set_affine_coordinates_GFp(key->group, point, | ||
200 | x, y, ctx)) | ||
201 | goto err; | ||
202 | if (!EC_POINT_get_affine_coordinates_GFp(key->group, point, | ||
203 | tx, ty, ctx)) | ||
204 | goto err; | ||
205 | /* | ||
206 | * Check if retrieved coordinates match originals: if not values are | ||
207 | * out of range. | ||
208 | */ | ||
209 | if (BN_cmp(x, tx) || BN_cmp(y, ty)) { | ||
210 | GOSTerr(GOST_F_GOST_KEY_SET_PUBLIC_KEY_AFFINE_COORDINATES, | ||
211 | EC_R_COORDINATES_OUT_OF_RANGE); | ||
212 | goto err; | ||
213 | } | ||
214 | if (!GOST_KEY_set_public_key(key, point)) | ||
215 | goto err; | ||
216 | |||
217 | if (GOST_KEY_check_key(key) == 0) | ||
218 | goto err; | ||
219 | |||
220 | ok = 1; | ||
221 | |||
222 | err: | ||
223 | BN_CTX_free(ctx); | ||
224 | EC_POINT_free(point); | ||
225 | return ok; | ||
226 | |||
227 | } | ||
228 | |||
229 | const EC_GROUP * GOST_KEY_get0_group(const GOST_KEY * key) | ||
230 | { | ||
231 | return key->group; | ||
232 | } | ||
233 | |||
234 | int GOST_KEY_set_group(GOST_KEY * key, const EC_GROUP * group) | ||
235 | { | ||
236 | EC_GROUP_free(key->group); | ||
237 | key->group = EC_GROUP_dup(group); | ||
238 | return (key->group == NULL) ? 0 : 1; | ||
239 | } | ||
240 | |||
241 | const BIGNUM * GOST_KEY_get0_private_key(const GOST_KEY * key) | ||
242 | { | ||
243 | return key->priv_key; | ||
244 | } | ||
245 | |||
246 | int GOST_KEY_set_private_key(GOST_KEY * key, const BIGNUM * priv_key) | ||
247 | { | ||
248 | BN_clear_free(key->priv_key); | ||
249 | key->priv_key = BN_dup(priv_key); | ||
250 | return (key->priv_key == NULL) ? 0 : 1; | ||
251 | } | ||
252 | |||
253 | const EC_POINT * | ||
254 | GOST_KEY_get0_public_key(const GOST_KEY * key) | ||
255 | { | ||
256 | return key->pub_key; | ||
257 | } | ||
258 | |||
259 | int GOST_KEY_set_public_key(GOST_KEY * key, const EC_POINT * pub_key) | ||
260 | { | ||
261 | EC_POINT_free(key->pub_key); | ||
262 | key->pub_key = EC_POINT_dup(pub_key, key->group); | ||
263 | return (key->pub_key == NULL) ? 0 : 1; | ||
264 | } | ||
265 | |||
266 | int GOST_KEY_get_digest(const GOST_KEY * key) | ||
267 | { | ||
268 | return key->digest_nid; | ||
269 | } | ||
270 | int GOST_KEY_set_digest(GOST_KEY * key, int digest_nid) | ||
271 | { | ||
272 | if (digest_nid == NID_id_GostR3411_94_CryptoProParamSet || | ||
273 | digest_nid == NID_id_tc26_gost3411_2012_256 || | ||
274 | digest_nid == NID_id_tc26_gost3411_2012_512) { | ||
275 | key->digest_nid = digest_nid; | ||
276 | return 1; | ||
277 | } | ||
278 | |||
279 | return 0; | ||
280 | } | ||
281 | |||
282 | size_t GOST_KEY_get_size(const GOST_KEY * r) | ||
283 | { | ||
284 | int i; | ||
285 | BIGNUM *order = NULL; | ||
286 | const EC_GROUP *group; | ||
287 | |||
288 | if (r == NULL) | ||
289 | return 0; | ||
290 | group = GOST_KEY_get0_group(r); | ||
291 | if (group == NULL) | ||
292 | return 0; | ||
293 | |||
294 | if ((order = BN_new()) == NULL) | ||
295 | return 0; | ||
296 | |||
297 | if (!EC_GROUP_get_order(group,order,NULL)) { | ||
298 | BN_clear_free(order); | ||
299 | return 0; | ||
300 | } | ||
301 | |||
302 | i = BN_num_bytes(order); | ||
303 | BN_clear_free(order); | ||
304 | return (i); | ||
305 | } | ||
306 | #endif | ||
diff --git a/src/lib/libcrypto/gost/gostr341001_params.c b/src/lib/libcrypto/gost/gostr341001_params.c new file mode 100644 index 0000000000..1c8276e7b0 --- /dev/null +++ b/src/lib/libcrypto/gost/gostr341001_params.c | |||
@@ -0,0 +1,126 @@ | |||
1 | /* $OpenBSD: gostr341001_params.c,v 1.1 2014/11/09 19:17:13 miod Exp $ */ | ||
2 | /* | ||
3 | * Copyright (c) 2014 Dmitry Eremin-Solenikov <dbaryshkov@gmail.com> | ||
4 | * Copyright (c) 2005-2006 Cryptocom LTD | ||
5 | * | ||
6 | * Redistribution and use in source and binary forms, with or without | ||
7 | * modification, are permitted provided that the following conditions | ||
8 | * are met: | ||
9 | * | ||
10 | * 1. Redistributions of source code must retain the above copyright | ||
11 | * notice, this list of conditions and the following disclaimer. | ||
12 | * | ||
13 | * 2. Redistributions in binary form must reproduce the above copyright | ||
14 | * notice, this list of conditions and the following disclaimer in | ||
15 | * the documentation and/or other materials provided with the | ||
16 | * distribution. | ||
17 | * | ||
18 | * 3. All advertising materials mentioning features or use of this | ||
19 | * software must display the following acknowledgment: | ||
20 | * "This product includes software developed by the OpenSSL Project | ||
21 | * for use in the OpenSSL Toolkit. (http://www.openssl.org/)" | ||
22 | * | ||
23 | * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to | ||
24 | * endorse or promote products derived from this software without | ||
25 | * prior written permission. For written permission, please contact | ||
26 | * openssl-core@openssl.org. | ||
27 | * | ||
28 | * 5. Products derived from this software may not be called "OpenSSL" | ||
29 | * nor may "OpenSSL" appear in their names without prior written | ||
30 | * permission of the OpenSSL Project. | ||
31 | * | ||
32 | * 6. Redistributions of any form whatsoever must retain the following | ||
33 | * acknowledgment: | ||
34 | * "This product includes software developed by the OpenSSL Project | ||
35 | * for use in the OpenSSL Toolkit (http://www.openssl.org/)" | ||
36 | * | ||
37 | * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY | ||
38 | * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | ||
39 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR | ||
40 | * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR | ||
41 | * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, | ||
42 | * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT | ||
43 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; | ||
44 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | ||
45 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, | ||
46 | * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) | ||
47 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED | ||
48 | * OF THE POSSIBILITY OF SUCH DAMAGE. | ||
49 | * ==================================================================== | ||
50 | */ | ||
51 | |||
52 | #include <strings.h> | ||
53 | |||
54 | #include <openssl/opensslconf.h> | ||
55 | |||
56 | #ifndef OPENSSL_NO_GOST | ||
57 | #include <openssl/objects.h> | ||
58 | #include <openssl/gost.h> | ||
59 | |||
60 | #include "gost_locl.h" | ||
61 | |||
62 | int GostR3410_get_md_digest(int nid) | ||
63 | { | ||
64 | if (nid == NID_id_GostR3411_94_CryptoProParamSet) | ||
65 | return NID_id_GostR3411_94; | ||
66 | return nid; | ||
67 | } | ||
68 | |||
69 | int GostR3410_get_pk_digest(int nid) | ||
70 | { | ||
71 | switch (nid) { | ||
72 | case NID_id_GostR3411_94_CryptoProParamSet: | ||
73 | return NID_id_GostR3410_2001; | ||
74 | case NID_id_tc26_gost3411_2012_256: | ||
75 | return NID_id_tc26_gost3410_2012_256; | ||
76 | case NID_id_tc26_gost3411_2012_512: | ||
77 | return NID_id_tc26_gost3410_2012_512; | ||
78 | default: | ||
79 | return NID_undef; | ||
80 | } | ||
81 | } | ||
82 | |||
83 | typedef struct GostR3410_params { | ||
84 | const char *name; | ||
85 | int nid; | ||
86 | } GostR3410_params; | ||
87 | |||
88 | static const GostR3410_params GostR3410_256_params[] = { | ||
89 | { "A", NID_id_GostR3410_2001_CryptoPro_A_ParamSet }, | ||
90 | { "B", NID_id_GostR3410_2001_CryptoPro_B_ParamSet }, | ||
91 | { "C", NID_id_GostR3410_2001_CryptoPro_C_ParamSet }, | ||
92 | { "0", NID_id_GostR3410_2001_TestParamSet }, | ||
93 | { "XA", NID_id_GostR3410_2001_CryptoPro_XchA_ParamSet }, | ||
94 | { "XB", NID_id_GostR3410_2001_CryptoPro_XchB_ParamSet }, | ||
95 | { NULL, NID_undef }, | ||
96 | }; | ||
97 | |||
98 | static const GostR3410_params GostR3410_512_params[] = { | ||
99 | { "A", NID_id_tc26_gost_3410_2012_512_paramSetA }, | ||
100 | { "B", NID_id_tc26_gost_3410_2012_512_paramSetB }, | ||
101 | { NULL, NID_undef }, | ||
102 | }; | ||
103 | |||
104 | int GostR3410_256_param_id(const char *value) | ||
105 | { | ||
106 | int i; | ||
107 | for (i = 0; GostR3410_256_params[i].nid != NID_undef; i++) { | ||
108 | if (!strcasecmp(GostR3410_256_params[i].name, value)) | ||
109 | return GostR3410_256_params[i].nid; | ||
110 | } | ||
111 | |||
112 | return NID_undef; | ||
113 | } | ||
114 | |||
115 | int GostR3410_512_param_id(const char *value) | ||
116 | { | ||
117 | int i; | ||
118 | for (i = 0; GostR3410_512_params[i].nid != NID_undef; i++) { | ||
119 | if (!strcasecmp(GostR3410_512_params[i].name, value)) | ||
120 | return GostR3410_512_params[i].nid; | ||
121 | } | ||
122 | |||
123 | return NID_undef; | ||
124 | } | ||
125 | |||
126 | #endif | ||
diff --git a/src/lib/libcrypto/gost/gostr341001_pmeth.c b/src/lib/libcrypto/gost/gostr341001_pmeth.c new file mode 100644 index 0000000000..0f82e88a9d --- /dev/null +++ b/src/lib/libcrypto/gost/gostr341001_pmeth.c | |||
@@ -0,0 +1,657 @@ | |||
1 | /* $OpenBSD: gostr341001_pmeth.c,v 1.1 2014/11/09 19:17:13 miod Exp $ */ | ||
2 | /* | ||
3 | * Copyright (c) 2014 Dmitry Eremin-Solenikov <dbaryshkov@gmail.com> | ||
4 | * Copyright (c) 2005-2006 Cryptocom LTD | ||
5 | * | ||
6 | * Redistribution and use in source and binary forms, with or without | ||
7 | * modification, are permitted provided that the following conditions | ||
8 | * are met: | ||
9 | * | ||
10 | * 1. Redistributions of source code must retain the above copyright | ||
11 | * notice, this list of conditions and the following disclaimer. | ||
12 | * | ||
13 | * 2. Redistributions in binary form must reproduce the above copyright | ||
14 | * notice, this list of conditions and the following disclaimer in | ||
15 | * the documentation and/or other materials provided with the | ||
16 | * distribution. | ||
17 | * | ||
18 | * 3. All advertising materials mentioning features or use of this | ||
19 | * software must display the following acknowledgment: | ||
20 | * "This product includes software developed by the OpenSSL Project | ||
21 | * for use in the OpenSSL Toolkit. (http://www.openssl.org/)" | ||
22 | * | ||
23 | * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to | ||
24 | * endorse or promote products derived from this software without | ||
25 | * prior written permission. For written permission, please contact | ||
26 | * openssl-core@openssl.org. | ||
27 | * | ||
28 | * 5. Products derived from this software may not be called "OpenSSL" | ||
29 | * nor may "OpenSSL" appear in their names without prior written | ||
30 | * permission of the OpenSSL Project. | ||
31 | * | ||
32 | * 6. Redistributions of any form whatsoever must retain the following | ||
33 | * acknowledgment: | ||
34 | * "This product includes software developed by the OpenSSL Project | ||
35 | * for use in the OpenSSL Toolkit (http://www.openssl.org/)" | ||
36 | * | ||
37 | * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY | ||
38 | * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | ||
39 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR | ||
40 | * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR | ||
41 | * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, | ||
42 | * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT | ||
43 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; | ||
44 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | ||
45 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, | ||
46 | * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) | ||
47 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED | ||
48 | * OF THE POSSIBILITY OF SUCH DAMAGE. | ||
49 | * ==================================================================== | ||
50 | */ | ||
51 | |||
52 | #include <string.h> | ||
53 | |||
54 | #include <openssl/opensslconf.h> | ||
55 | |||
56 | #ifndef OPENSSL_NO_GOST | ||
57 | #include <openssl/evp.h> | ||
58 | #include <openssl/err.h> | ||
59 | #include <openssl/gost.h> | ||
60 | #include <openssl/ec.h> | ||
61 | #include <openssl/ecdsa.h> | ||
62 | #include <openssl/x509.h> | ||
63 | #include <openssl/rand.h> /* for RAND_bytes */ | ||
64 | |||
65 | #include "evp_locl.h" | ||
66 | #include "gost_locl.h" | ||
67 | #include "gost_asn1.h" | ||
68 | |||
69 | static ECDSA_SIG *unpack_signature_cp(const unsigned char *sig, size_t siglen) | ||
70 | { | ||
71 | ECDSA_SIG *s; | ||
72 | |||
73 | s = ECDSA_SIG_new(); | ||
74 | if (s == NULL) { | ||
75 | GOSTerr(GOST_F_UNPACK_SIGNATURE_CP, ERR_R_MALLOC_FAILURE); | ||
76 | return NULL; | ||
77 | } | ||
78 | BN_bin2bn(sig, siglen / 2, s->s); | ||
79 | BN_bin2bn(sig + siglen / 2, siglen / 2, s->r); | ||
80 | return s; | ||
81 | } | ||
82 | |||
83 | static int pack_signature_cp(ECDSA_SIG * s, int order, unsigned char *sig, size_t * siglen) | ||
84 | { | ||
85 | int r_len = BN_num_bytes(s->r); | ||
86 | int s_len = BN_num_bytes(s->s); | ||
87 | |||
88 | if ((r_len > order) || (s_len > order)) | ||
89 | return 0; | ||
90 | |||
91 | *siglen = 2 * order; | ||
92 | |||
93 | memset(sig, 0, *siglen); | ||
94 | BN_bn2bin(s->s, sig + order - s_len); | ||
95 | BN_bn2bin(s->r, sig + 2 * order - r_len); | ||
96 | ECDSA_SIG_free(s); | ||
97 | return 1; | ||
98 | } | ||
99 | |||
100 | static ECDSA_SIG *unpack_signature_le(const unsigned char *sig, size_t siglen) | ||
101 | { | ||
102 | ECDSA_SIG *s; | ||
103 | |||
104 | s = ECDSA_SIG_new(); | ||
105 | if (s == NULL) { | ||
106 | GOSTerr(GOST_F_UNPACK_SIGNATURE_LE, ERR_R_MALLOC_FAILURE); | ||
107 | return NULL; | ||
108 | } | ||
109 | GOST_le2bn(sig, siglen / 2, s->r); | ||
110 | GOST_le2bn(sig + siglen / 2, siglen / 2, s->s); | ||
111 | return s; | ||
112 | } | ||
113 | |||
114 | static int pack_signature_le(ECDSA_SIG * s, int order, unsigned char *sig, size_t * siglen) | ||
115 | { | ||
116 | *siglen = 2 * order; | ||
117 | memset(sig, 0, *siglen); | ||
118 | GOST_bn2le(s->r, sig, order); | ||
119 | GOST_bn2le(s->s, sig + order, order); | ||
120 | ECDSA_SIG_free(s); | ||
121 | return 1; | ||
122 | } | ||
123 | |||
124 | struct gost_pmeth_data { | ||
125 | int sign_param_nid; /* Should be set whenever parameters are filled */ | ||
126 | int digest_nid; | ||
127 | EVP_MD *md; | ||
128 | unsigned char *shared_ukm; | ||
129 | int peer_key_used; | ||
130 | int sig_format; | ||
131 | }; | ||
132 | |||
133 | static int pkey_gost01_init(EVP_PKEY_CTX * ctx) | ||
134 | { | ||
135 | struct gost_pmeth_data *data; | ||
136 | EVP_PKEY *pkey = EVP_PKEY_CTX_get0_pkey(ctx); | ||
137 | data = malloc(sizeof(struct gost_pmeth_data)); | ||
138 | if (!data) | ||
139 | return 0; | ||
140 | |||
141 | memset(data, 0, sizeof(struct gost_pmeth_data)); | ||
142 | if (pkey && pkey->pkey.gost) { | ||
143 | data->sign_param_nid = EC_GROUP_get_curve_name(GOST_KEY_get0_group(pkey->pkey.gost)); | ||
144 | data->digest_nid = GOST_KEY_get_digest(pkey->pkey.gost); | ||
145 | } | ||
146 | EVP_PKEY_CTX_set_data(ctx, data); | ||
147 | return 1; | ||
148 | } | ||
149 | |||
150 | /* Copies contents of gost_pmeth_data structure */ | ||
151 | static int pkey_gost01_copy(EVP_PKEY_CTX * dst, EVP_PKEY_CTX * src) | ||
152 | { | ||
153 | struct gost_pmeth_data *dst_data, *src_data; | ||
154 | if (!pkey_gost01_init(dst)) { | ||
155 | return 0; | ||
156 | } | ||
157 | src_data = EVP_PKEY_CTX_get_data(src); | ||
158 | dst_data = EVP_PKEY_CTX_get_data(dst); | ||
159 | *dst_data = *src_data; | ||
160 | if (src_data->shared_ukm) { | ||
161 | dst_data->shared_ukm = NULL; | ||
162 | } | ||
163 | return 1; | ||
164 | } | ||
165 | |||
166 | /* Frees up gost_pmeth_data structure */ | ||
167 | static void pkey_gost01_cleanup(EVP_PKEY_CTX * ctx) | ||
168 | { | ||
169 | struct gost_pmeth_data *data = EVP_PKEY_CTX_get_data(ctx); | ||
170 | free(data->shared_ukm); | ||
171 | free(data); | ||
172 | } | ||
173 | |||
174 | static int pkey_gost01_paramgen(EVP_PKEY_CTX * ctx, EVP_PKEY * pkey) | ||
175 | { | ||
176 | struct gost_pmeth_data *data = EVP_PKEY_CTX_get_data(ctx); | ||
177 | EC_GROUP *group; | ||
178 | GOST_KEY *gost; | ||
179 | int ret; | ||
180 | |||
181 | if (data->sign_param_nid == NID_undef || data->digest_nid == NID_undef) { | ||
182 | GOSTerr(GOST_F_PKEY_GOST01_PARAMGEN, GOST_R_NO_PARAMETERS_SET); | ||
183 | return 0; | ||
184 | } | ||
185 | |||
186 | group = EC_GROUP_new_by_curve_name(data->sign_param_nid); | ||
187 | if (!group) | ||
188 | return 0; | ||
189 | |||
190 | EC_GROUP_set_asn1_flag(group, OPENSSL_EC_NAMED_CURVE); | ||
191 | |||
192 | gost = GOST_KEY_new(); | ||
193 | if (!gost) | ||
194 | return 0; | ||
195 | |||
196 | if (!GOST_KEY_set_digest(gost, data->digest_nid)) | ||
197 | return 0; | ||
198 | |||
199 | ret = GOST_KEY_set_group(gost, group); | ||
200 | if (ret) | ||
201 | EVP_PKEY_assign_GOST(pkey, gost); | ||
202 | else | ||
203 | GOST_KEY_free(gost); | ||
204 | |||
205 | EC_GROUP_free(group); | ||
206 | return ret; | ||
207 | } | ||
208 | |||
209 | static int pkey_gost01_keygen(EVP_PKEY_CTX * ctx, EVP_PKEY * pkey) | ||
210 | { | ||
211 | if (!pkey_gost01_paramgen(ctx, pkey)) | ||
212 | return 0; | ||
213 | gost2001_keygen(pkey->pkey.gost); | ||
214 | return 1; | ||
215 | } | ||
216 | |||
217 | static int pkey_gost01_sign(EVP_PKEY_CTX * ctx, unsigned char *sig, | ||
218 | size_t * siglen, const unsigned char *tbs, | ||
219 | size_t tbs_len) | ||
220 | { | ||
221 | ECDSA_SIG *unpacked_sig = NULL; | ||
222 | EVP_PKEY *pkey = EVP_PKEY_CTX_get0_pkey(ctx); | ||
223 | struct gost_pmeth_data *pctx = EVP_PKEY_CTX_get_data(ctx); | ||
224 | BIGNUM *md; | ||
225 | size_t size = GOST_KEY_get_size(pkey->pkey.gost); | ||
226 | |||
227 | if (!siglen) | ||
228 | return 0; | ||
229 | if (!sig) { | ||
230 | *siglen = 2 * size; | ||
231 | return 1; | ||
232 | } else if (*siglen < 2 * size) { | ||
233 | GOSTerr(GOST_F_PKEY_GOST01_SIGN, EC_R_BUFFER_TOO_SMALL); | ||
234 | return 0; | ||
235 | } | ||
236 | OPENSSL_assert(tbs_len == 32 || tbs_len == 64); | ||
237 | md = GOST_le2bn(tbs, tbs_len, NULL); | ||
238 | unpacked_sig = gost2001_do_sign(md, pkey->pkey.gost); | ||
239 | #ifdef DEBUG_SIGN | ||
240 | fprintf(stderr, "S.R="); | ||
241 | BN_print_fp(stderr, unpacked_sig->r); | ||
242 | fprintf(stderr, "\nS.S="); | ||
243 | BN_print_fp(stderr, unpacked_sig->s); | ||
244 | fprintf(stderr, "\n"); | ||
245 | #endif | ||
246 | if (!unpacked_sig) { | ||
247 | return 0; | ||
248 | } | ||
249 | switch (pctx->sig_format) { | ||
250 | case GOST_SIG_FORMAT_SR_BE: | ||
251 | return pack_signature_cp(unpacked_sig, size, sig, siglen); | ||
252 | case GOST_SIG_FORMAT_RS_LE: | ||
253 | return pack_signature_le(unpacked_sig, size, sig, siglen); | ||
254 | default: | ||
255 | ECDSA_SIG_free(unpacked_sig); | ||
256 | return -1; | ||
257 | } | ||
258 | } | ||
259 | |||
260 | static int pkey_gost01_verify(EVP_PKEY_CTX * ctx, const unsigned char *sig, | ||
261 | size_t siglen, const unsigned char *tbs, | ||
262 | size_t tbs_len) | ||
263 | { | ||
264 | int ok = 0; | ||
265 | EVP_PKEY *pub_key = EVP_PKEY_CTX_get0_pkey(ctx); | ||
266 | struct gost_pmeth_data *pctx = EVP_PKEY_CTX_get_data(ctx); | ||
267 | ECDSA_SIG *s = NULL; | ||
268 | BIGNUM *md; | ||
269 | |||
270 | if (!pub_key) | ||
271 | return 0; | ||
272 | switch (pctx->sig_format) { | ||
273 | case GOST_SIG_FORMAT_SR_BE: | ||
274 | s = unpack_signature_cp(sig, siglen); | ||
275 | break; | ||
276 | case GOST_SIG_FORMAT_RS_LE: | ||
277 | s = unpack_signature_le(sig, siglen); | ||
278 | break; | ||
279 | } | ||
280 | if (!s) | ||
281 | return 0; | ||
282 | md = GOST_le2bn(tbs, tbs_len, NULL); | ||
283 | if (!md) | ||
284 | goto err; | ||
285 | #ifdef DEBUG_SIGN | ||
286 | fprintf(stderr, "V.R="); | ||
287 | BN_print_fp(stderr, s->r); | ||
288 | fprintf(stderr, "\nV.S="); | ||
289 | BN_print_fp(stderr, s->s); | ||
290 | fprintf(stderr, "\n"); | ||
291 | #endif | ||
292 | ok = gost2001_do_verify(md, s, pub_key->pkey.gost); | ||
293 | |||
294 | err: | ||
295 | BN_free(md); | ||
296 | ECDSA_SIG_free(s); | ||
297 | return ok; | ||
298 | } | ||
299 | |||
300 | static int gost01_VKO_key(EVP_PKEY * pub_key, EVP_PKEY * priv_key, | ||
301 | const unsigned char *ukm, unsigned char *key) | ||
302 | { | ||
303 | unsigned char hashbuf[128]; | ||
304 | int digest_nid; | ||
305 | int ret; | ||
306 | BN_CTX *ctx = BN_CTX_new(); | ||
307 | BIGNUM *UKM, *X, *Y; | ||
308 | |||
309 | BN_CTX_start(ctx); | ||
310 | UKM = BN_CTX_get(ctx); | ||
311 | X = BN_CTX_get(ctx); | ||
312 | Y = BN_CTX_get(ctx); | ||
313 | |||
314 | GOST_le2bn(ukm, 8, UKM); | ||
315 | |||
316 | digest_nid = GOST_KEY_get_digest(priv_key->pkey.gost); | ||
317 | VKO_compute_key(X, Y, pub_key->pkey.gost, priv_key->pkey.gost, UKM); | ||
318 | switch (digest_nid) { | ||
319 | case NID_id_GostR3411_94_CryptoProParamSet: | ||
320 | GOST_bn2le(X, hashbuf, 32); | ||
321 | GOST_bn2le(Y, hashbuf + 32, 32); | ||
322 | GOSTR341194(hashbuf, 64, key, digest_nid); | ||
323 | ret = 1; | ||
324 | break; | ||
325 | case NID_id_tc26_gost3411_2012_256: | ||
326 | GOST_bn2le(X, hashbuf, 32); | ||
327 | GOST_bn2le(Y, hashbuf + 32, 32); | ||
328 | STREEBOG256(hashbuf, 64, key); | ||
329 | ret = 1; | ||
330 | break; | ||
331 | case NID_id_tc26_gost3411_2012_512: | ||
332 | GOST_bn2le(X, hashbuf, 64); | ||
333 | GOST_bn2le(Y, hashbuf + 64, 64); | ||
334 | STREEBOG256(hashbuf, 128, key); | ||
335 | ret = 1; | ||
336 | break; | ||
337 | default: | ||
338 | ret = -2; | ||
339 | break; | ||
340 | } | ||
341 | BN_CTX_end(ctx); | ||
342 | BN_CTX_free(ctx); | ||
343 | return ret; | ||
344 | } | ||
345 | |||
346 | int pkey_gost01_decrypt(EVP_PKEY_CTX * pctx, unsigned char *key, | ||
347 | size_t * key_len, const unsigned char *in, | ||
348 | size_t in_len) | ||
349 | { | ||
350 | const unsigned char *p = in; | ||
351 | EVP_PKEY *priv = EVP_PKEY_CTX_get0_pkey(pctx); | ||
352 | GOST_KEY_TRANSPORT *gkt = NULL; | ||
353 | int ret = 0; | ||
354 | unsigned char wrappedKey[44]; | ||
355 | unsigned char sharedKey[32]; | ||
356 | EVP_PKEY *eph_key = NULL, *peerkey = NULL; | ||
357 | int nid; | ||
358 | |||
359 | if (!key) { | ||
360 | *key_len = 32; | ||
361 | return 1; | ||
362 | } | ||
363 | gkt = d2i_GOST_KEY_TRANSPORT(NULL, (const unsigned char **)&p, in_len); | ||
364 | if (!gkt) { | ||
365 | GOSTerr(GOST_F_PKEY_GOST01_DECRYPT, | ||
366 | GOST_R_ERROR_PARSING_KEY_TRANSPORT_INFO); | ||
367 | return -1; | ||
368 | } | ||
369 | |||
370 | /* If key transport structure contains public key, use it */ | ||
371 | eph_key = X509_PUBKEY_get(gkt->key_agreement_info->ephem_key); | ||
372 | if (eph_key) { | ||
373 | if (EVP_PKEY_derive_set_peer(pctx, eph_key) <= 0) { | ||
374 | GOSTerr(GOST_F_PKEY_GOST01_DECRYPT, | ||
375 | GOST_R_INCOMPATIBLE_PEER_KEY); | ||
376 | goto err; | ||
377 | } | ||
378 | } else { | ||
379 | /* Set control "public key from client certificate used" */ | ||
380 | if (EVP_PKEY_CTX_ctrl(pctx, -1, -1, EVP_PKEY_CTRL_PEER_KEY, 3, NULL) <= 0) { | ||
381 | GOSTerr(GOST_F_PKEY_GOST01_DECRYPT, GOST_R_CTRL_CALL_FAILED); | ||
382 | goto err; | ||
383 | } | ||
384 | } | ||
385 | peerkey = EVP_PKEY_CTX_get0_peerkey(pctx); | ||
386 | if (!peerkey) { | ||
387 | GOSTerr(GOST_F_PKEY_GOST01_DECRYPT, GOST_R_NO_PEER_KEY); | ||
388 | goto err; | ||
389 | } | ||
390 | |||
391 | nid = OBJ_obj2nid(gkt->key_agreement_info->cipher); | ||
392 | |||
393 | OPENSSL_assert(gkt->key_agreement_info->eph_iv->length == 8); | ||
394 | memcpy(wrappedKey, gkt->key_agreement_info->eph_iv->data, 8); | ||
395 | OPENSSL_assert(gkt->key_info->encrypted_key->length == 32); | ||
396 | memcpy(wrappedKey + 8, gkt->key_info->encrypted_key->data, 32); | ||
397 | OPENSSL_assert(gkt->key_info->imit->length == 4); | ||
398 | memcpy(wrappedKey + 40, gkt->key_info->imit->data, 4); | ||
399 | gost01_VKO_key(peerkey, priv, wrappedKey, sharedKey); | ||
400 | if (!key_unwrap_crypto_pro(nid, sharedKey, wrappedKey, key)) { | ||
401 | GOSTerr(GOST_F_PKEY_GOST01_DECRYPT, | ||
402 | GOST_R_ERROR_COMPUTING_SHARED_KEY); | ||
403 | goto err; | ||
404 | } | ||
405 | |||
406 | ret = 1; | ||
407 | err: | ||
408 | if (eph_key) | ||
409 | EVP_PKEY_free(eph_key); | ||
410 | if (gkt) | ||
411 | GOST_KEY_TRANSPORT_free(gkt); | ||
412 | return ret; | ||
413 | } | ||
414 | |||
415 | int pkey_gost01_derive(EVP_PKEY_CTX * ctx, unsigned char *key, | ||
416 | size_t * keylen) | ||
417 | { | ||
418 | /* Public key of peer in the ctx field peerkey | ||
419 | * Our private key in the ctx pkey | ||
420 | * ukm is in the algorithm specific context data | ||
421 | */ | ||
422 | EVP_PKEY *my_key = EVP_PKEY_CTX_get0_pkey(ctx); | ||
423 | EVP_PKEY *peer_key = EVP_PKEY_CTX_get0_peerkey(ctx); | ||
424 | struct gost_pmeth_data *data = EVP_PKEY_CTX_get_data(ctx); | ||
425 | |||
426 | if (!data->shared_ukm) { | ||
427 | GOSTerr(GOST_F_PKEY_GOST01_DERIVE, GOST_R_UKM_NOT_SET); | ||
428 | return 0; | ||
429 | } | ||
430 | |||
431 | if (key == NULL) { | ||
432 | *keylen = 32; | ||
433 | return 32; | ||
434 | } | ||
435 | |||
436 | gost01_VKO_key(peer_key, my_key, data->shared_ukm, key); | ||
437 | *keylen = 32; | ||
438 | return 1; | ||
439 | } | ||
440 | |||
441 | int pkey_gost01_encrypt(EVP_PKEY_CTX * pctx, unsigned char *out, | ||
442 | size_t * out_len, const unsigned char *key, | ||
443 | size_t key_len) | ||
444 | { | ||
445 | GOST_KEY_TRANSPORT *gkt = NULL; | ||
446 | EVP_PKEY *pubk = EVP_PKEY_CTX_get0_pkey(pctx); | ||
447 | struct gost_pmeth_data *data = EVP_PKEY_CTX_get_data(pctx); | ||
448 | unsigned char ukm[8], shared_key[32], crypted_key[44]; | ||
449 | int ret = 0; | ||
450 | int key_is_ephemeral = 1; | ||
451 | EVP_PKEY *sec_key = EVP_PKEY_CTX_get0_peerkey(pctx); | ||
452 | int nid = NID_id_Gost28147_89_CryptoPro_A_ParamSet; | ||
453 | |||
454 | if (data->shared_ukm) { | ||
455 | memcpy(ukm, data->shared_ukm, 8); | ||
456 | } else if (out) { | ||
457 | if (RAND_bytes(ukm, 8) <= 0) { | ||
458 | GOSTerr(GOST_F_PKEY_GOST01_ENCRYPT, | ||
459 | GOST_R_RANDOM_GENERATOR_FAILURE); | ||
460 | return 0; | ||
461 | } | ||
462 | } | ||
463 | /* Check for private key in the peer_key of context */ | ||
464 | if (sec_key) { | ||
465 | key_is_ephemeral = 0; | ||
466 | if (!GOST_KEY_get0_private_key(sec_key->pkey.gost)) { | ||
467 | GOSTerr(GOST_F_PKEY_GOST01_ENCRYPT, | ||
468 | GOST_R_NO_PRIVATE_PART_OF_NON_EPHEMERAL_KEYPAIR); | ||
469 | goto err; | ||
470 | } | ||
471 | } else { | ||
472 | key_is_ephemeral = 1; | ||
473 | if (out) { | ||
474 | sec_key = EVP_PKEY_new(); | ||
475 | EVP_PKEY_assign(sec_key, EVP_PKEY_base_id(pubk), | ||
476 | GOST_KEY_new()); | ||
477 | EVP_PKEY_copy_parameters(sec_key, pubk); | ||
478 | if (!gost2001_keygen(sec_key->pkey.gost)) { | ||
479 | goto err; | ||
480 | } | ||
481 | } | ||
482 | } | ||
483 | |||
484 | if (out) { | ||
485 | gost01_VKO_key(pubk, sec_key, ukm, shared_key); | ||
486 | key_wrap_crypto_pro(nid, shared_key, ukm, key, crypted_key); | ||
487 | } | ||
488 | gkt = GOST_KEY_TRANSPORT_new(); | ||
489 | if (!gkt) { | ||
490 | goto err; | ||
491 | } | ||
492 | if (!ASN1_OCTET_STRING_set(gkt->key_agreement_info->eph_iv, ukm, 8)) { | ||
493 | goto err; | ||
494 | } | ||
495 | if (!ASN1_OCTET_STRING_set(gkt->key_info->imit, crypted_key + 40, 4)) { | ||
496 | goto err; | ||
497 | } | ||
498 | if (!ASN1_OCTET_STRING_set(gkt->key_info->encrypted_key, crypted_key + 8, 32)) { | ||
499 | goto err; | ||
500 | } | ||
501 | if (key_is_ephemeral) { | ||
502 | if (!X509_PUBKEY_set | ||
503 | (&gkt->key_agreement_info->ephem_key, | ||
504 | out ? sec_key : pubk)) { | ||
505 | GOSTerr(GOST_F_PKEY_GOST01_ENCRYPT, | ||
506 | GOST_R_CANNOT_PACK_EPHEMERAL_KEY); | ||
507 | goto err; | ||
508 | } | ||
509 | } | ||
510 | ASN1_OBJECT_free(gkt->key_agreement_info->cipher); | ||
511 | gkt->key_agreement_info->cipher = OBJ_nid2obj(nid); | ||
512 | if (key_is_ephemeral && sec_key) | ||
513 | EVP_PKEY_free(sec_key); | ||
514 | if (!key_is_ephemeral) { | ||
515 | /* Set control "public key from client certificate used" */ | ||
516 | if (EVP_PKEY_CTX_ctrl | ||
517 | (pctx, -1, -1, EVP_PKEY_CTRL_PEER_KEY, 3, NULL) <= 0) { | ||
518 | GOSTerr(GOST_F_PKEY_GOST01_ENCRYPT, | ||
519 | GOST_R_CTRL_CALL_FAILED); | ||
520 | goto err; | ||
521 | } | ||
522 | } | ||
523 | if ((*out_len = i2d_GOST_KEY_TRANSPORT(gkt, out ? &out : NULL)) > 0) | ||
524 | ret = 1; | ||
525 | GOST_KEY_TRANSPORT_free(gkt); | ||
526 | return ret; | ||
527 | err: | ||
528 | if (key_is_ephemeral && sec_key) | ||
529 | EVP_PKEY_free(sec_key); | ||
530 | GOST_KEY_TRANSPORT_free(gkt); | ||
531 | return -1; | ||
532 | } | ||
533 | |||
534 | |||
535 | static int pkey_gost01_ctrl(EVP_PKEY_CTX * ctx, int type, int p1, void *p2) | ||
536 | { | ||
537 | struct gost_pmeth_data *pctx = EVP_PKEY_CTX_get_data(ctx); | ||
538 | switch (type) { | ||
539 | case EVP_PKEY_CTRL_MD: | ||
540 | if (EVP_MD_type(p2) != GostR3410_get_md_digest(pctx->digest_nid)) { | ||
541 | GOSTerr(GOST_F_PKEY_GOST01_CTRL, GOST_R_INVALID_DIGEST_TYPE); | ||
542 | return 0; | ||
543 | } | ||
544 | pctx->md = p2; | ||
545 | return 1; | ||
546 | case EVP_PKEY_CTRL_PKCS7_ENCRYPT: | ||
547 | case EVP_PKEY_CTRL_PKCS7_DECRYPT: | ||
548 | case EVP_PKEY_CTRL_PKCS7_SIGN: | ||
549 | case EVP_PKEY_CTRL_DIGESTINIT: | ||
550 | #ifndef OPENSSL_NO_CMS | ||
551 | case EVP_PKEY_CTRL_CMS_ENCRYPT: | ||
552 | case EVP_PKEY_CTRL_CMS_DECRYPT: | ||
553 | case EVP_PKEY_CTRL_CMS_SIGN: | ||
554 | #endif | ||
555 | return 1; | ||
556 | |||
557 | case EVP_PKEY_CTRL_GOST_PARAMSET: | ||
558 | pctx->sign_param_nid = (int)p1; | ||
559 | return 1; | ||
560 | |||
561 | case EVP_PKEY_CTRL_SET_IV: | ||
562 | pctx->shared_ukm = malloc((int)p1); | ||
563 | memcpy(pctx->shared_ukm, p2, (int)p1); | ||
564 | return 1; | ||
565 | |||
566 | case EVP_PKEY_CTRL_PEER_KEY: | ||
567 | if (p1 == 0 || p1 == 1) /* call from EVP_PKEY_derive_set_peer */ | ||
568 | return 1; | ||
569 | if (p1 == 2) /* TLS: peer key used? */ | ||
570 | return pctx->peer_key_used; | ||
571 | if (p1 == 3) /* TLS: peer key used! */ | ||
572 | return (pctx->peer_key_used = 1); | ||
573 | return -2; | ||
574 | case EVP_PKEY_CTRL_GOST_SIG_FORMAT: | ||
575 | switch (p1) { | ||
576 | case GOST_SIG_FORMAT_SR_BE: | ||
577 | case GOST_SIG_FORMAT_RS_LE: | ||
578 | pctx->sig_format = p1; | ||
579 | return 1; | ||
580 | default: | ||
581 | return 0; | ||
582 | } | ||
583 | break; | ||
584 | case EVP_PKEY_CTRL_GOST_SET_DIGEST: | ||
585 | pctx->digest_nid = (int)p1; | ||
586 | return 1; | ||
587 | case EVP_PKEY_CTRL_GOST_GET_DIGEST: | ||
588 | *(int *)p2 = pctx->digest_nid; | ||
589 | return 1; | ||
590 | default: | ||
591 | return -2; | ||
592 | } | ||
593 | } | ||
594 | |||
595 | static int pkey_gost01_ctrl_str(EVP_PKEY_CTX * ctx, | ||
596 | const char *type, const char *value) | ||
597 | { | ||
598 | int param_nid = NID_undef; | ||
599 | int digest_nid = NID_undef; | ||
600 | |||
601 | if (!strcmp(type, "paramset")) { | ||
602 | if (!value) { | ||
603 | return 0; | ||
604 | } | ||
605 | if (!pkey_gost01_ctrl(ctx, EVP_PKEY_CTRL_GOST_GET_DIGEST, 0, &digest_nid)) | ||
606 | return 0; | ||
607 | if (digest_nid == NID_id_tc26_gost3411_2012_512) | ||
608 | param_nid = GostR3410_512_param_id(value); | ||
609 | else | ||
610 | param_nid = GostR3410_256_param_id(value); | ||
611 | if (param_nid == NID_undef) | ||
612 | param_nid = OBJ_txt2nid(value); | ||
613 | if (param_nid == NID_undef) | ||
614 | return 0; | ||
615 | |||
616 | return pkey_gost01_ctrl(ctx, EVP_PKEY_CTRL_GOST_PARAMSET, | ||
617 | param_nid, NULL); | ||
618 | } | ||
619 | if (!strcmp(type, "dgst")) { | ||
620 | if (!value) | ||
621 | return 0; | ||
622 | else if (!strcmp(value, "gost94") || !strcmp(value, "md_gost94")) | ||
623 | digest_nid = NID_id_GostR3411_94_CryptoProParamSet; | ||
624 | else if (!strcmp(value, "streebog256")) | ||
625 | digest_nid = NID_id_tc26_gost3411_2012_256; | ||
626 | else if (!strcmp(value, "streebog512")) | ||
627 | digest_nid = NID_id_tc26_gost3411_2012_512; | ||
628 | |||
629 | if (digest_nid == NID_undef) | ||
630 | return 0; | ||
631 | |||
632 | return pkey_gost01_ctrl(ctx, EVP_PKEY_CTRL_GOST_SET_DIGEST, | ||
633 | digest_nid, NULL); | ||
634 | } | ||
635 | return -2; | ||
636 | } | ||
637 | |||
638 | const EVP_PKEY_METHOD gostr01_pkey_meth = { | ||
639 | .pkey_id = EVP_PKEY_GOSTR01, | ||
640 | |||
641 | .init = pkey_gost01_init, | ||
642 | .copy = pkey_gost01_copy, | ||
643 | .cleanup = pkey_gost01_cleanup, | ||
644 | |||
645 | .paramgen = pkey_gost01_paramgen, | ||
646 | .keygen = pkey_gost01_keygen, | ||
647 | .sign = pkey_gost01_sign, | ||
648 | .verify = pkey_gost01_verify, | ||
649 | |||
650 | .encrypt = pkey_gost01_encrypt, | ||
651 | .decrypt = pkey_gost01_decrypt, | ||
652 | .derive = pkey_gost01_derive, | ||
653 | |||
654 | .ctrl = pkey_gost01_ctrl, | ||
655 | .ctrl_str = pkey_gost01_ctrl_str, | ||
656 | }; | ||
657 | #endif | ||
diff --git a/src/lib/libcrypto/gost/gostr341194.c b/src/lib/libcrypto/gost/gostr341194.c new file mode 100644 index 0000000000..706bf3d431 --- /dev/null +++ b/src/lib/libcrypto/gost/gostr341194.c | |||
@@ -0,0 +1,259 @@ | |||
1 | /* $OpenBSD: gostr341194.c,v 1.1 2014/11/09 19:17:13 miod Exp $ */ | ||
2 | /* | ||
3 | * Copyright (c) 2014 Dmitry Eremin-Solenikov <dbaryshkov@gmail.com> | ||
4 | * Copyright (c) 2005-2006 Cryptocom LTD | ||
5 | * | ||
6 | * Redistribution and use in source and binary forms, with or without | ||
7 | * modification, are permitted provided that the following conditions | ||
8 | * are met: | ||
9 | * | ||
10 | * 1. Redistributions of source code must retain the above copyright | ||
11 | * notice, this list of conditions and the following disclaimer. | ||
12 | * | ||
13 | * 2. Redistributions in binary form must reproduce the above copyright | ||
14 | * notice, this list of conditions and the following disclaimer in | ||
15 | * the documentation and/or other materials provided with the | ||
16 | * distribution. | ||
17 | * | ||
18 | * 3. All advertising materials mentioning features or use of this | ||
19 | * software must display the following acknowledgment: | ||
20 | * "This product includes software developed by the OpenSSL Project | ||
21 | * for use in the OpenSSL Toolkit. (http://www.openssl.org/)" | ||
22 | * | ||
23 | * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to | ||
24 | * endorse or promote products derived from this software without | ||
25 | * prior written permission. For written permission, please contact | ||
26 | * openssl-core@openssl.org. | ||
27 | * | ||
28 | * 5. Products derived from this software may not be called "OpenSSL" | ||
29 | * nor may "OpenSSL" appear in their names without prior written | ||
30 | * permission of the OpenSSL Project. | ||
31 | * | ||
32 | * 6. Redistributions of any form whatsoever must retain the following | ||
33 | * acknowledgment: | ||
34 | * "This product includes software developed by the OpenSSL Project | ||
35 | * for use in the OpenSSL Toolkit (http://www.openssl.org/)" | ||
36 | * | ||
37 | * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY | ||
38 | * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | ||
39 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR | ||
40 | * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR | ||
41 | * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, | ||
42 | * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT | ||
43 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; | ||
44 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | ||
45 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, | ||
46 | * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) | ||
47 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED | ||
48 | * OF THE POSSIBILITY OF SUCH DAMAGE. | ||
49 | * ==================================================================== | ||
50 | */ | ||
51 | |||
52 | #include <string.h> | ||
53 | |||
54 | #include <openssl/opensslconf.h> | ||
55 | |||
56 | #ifndef OPENSSL_NO_GOST | ||
57 | #include <openssl/crypto.h> | ||
58 | #include <openssl/objects.h> | ||
59 | #include <openssl/gost.h> | ||
60 | |||
61 | #include "gost_locl.h" | ||
62 | |||
63 | /* Following functions are various bit meshing routines used in | ||
64 | * GOST R 34.11-94 algorithms */ | ||
65 | static void swap_bytes(unsigned char *w, unsigned char *k) | ||
66 | { | ||
67 | int i, j; | ||
68 | for (i = 0; i < 4; i++) | ||
69 | for (j = 0; j < 8; j++) | ||
70 | k[i + 4 * j] = w[8 * i + j]; | ||
71 | |||
72 | } | ||
73 | |||
74 | /* was A_A */ | ||
75 | static void circle_xor8(const unsigned char *w, unsigned char *k) | ||
76 | { | ||
77 | unsigned char buf[8]; | ||
78 | int i; | ||
79 | |||
80 | memcpy(buf, w, 8); | ||
81 | memmove(k, w + 8, 24); | ||
82 | for (i = 0; i < 8; i++) | ||
83 | k[i + 24] = buf[i] ^ k[i]; | ||
84 | } | ||
85 | |||
86 | /* was R_R */ | ||
87 | static void transform_3(unsigned char *data) | ||
88 | { | ||
89 | unsigned short int acc; | ||
90 | acc = (data[0] ^ data[2] ^ data[4] ^ data[6] ^ data[24] ^ data[30]) | | ||
91 | ((data[1] ^ data[3] ^ data[5] ^ data[7] ^ data[25] ^ data[31]) << 8); | ||
92 | memmove(data, data + 2, 30); | ||
93 | data[30] = acc & 0xff; | ||
94 | data[31] = acc >> 8; | ||
95 | } | ||
96 | |||
97 | /* Adds blocks of N bytes modulo 2**(8*n). Returns carry*/ | ||
98 | static int add_blocks(int n, unsigned char *left, const unsigned char *right) | ||
99 | { | ||
100 | int i; | ||
101 | int carry = 0; | ||
102 | int sum; | ||
103 | |||
104 | for (i = 0; i < n; i++) { | ||
105 | sum = (int)left[i] + (int)right[i] + carry; | ||
106 | left[i] = sum & 0xff; | ||
107 | carry = sum >> 8; | ||
108 | } | ||
109 | return carry; | ||
110 | } | ||
111 | |||
112 | /* Xor two sequences of bytes */ | ||
113 | static void xor_blocks(unsigned char *result, const unsigned char *a, | ||
114 | const unsigned char *b, size_t len) | ||
115 | { | ||
116 | size_t i; | ||
117 | for (i = 0; i < len; i++) | ||
118 | result[i] = a[i] ^ b[i]; | ||
119 | } | ||
120 | |||
121 | /* | ||
122 | * Calculate H(i+1) = Hash(Hi,Mi) | ||
123 | * Where H and M are 32 bytes long | ||
124 | */ | ||
125 | static int hash_step(GOSTR341194_CTX *c, unsigned char *H, const unsigned char *M) | ||
126 | { | ||
127 | unsigned char U[32], W[32], V[32], S[32], Key[32]; | ||
128 | int i; | ||
129 | |||
130 | /* Compute first key */ | ||
131 | xor_blocks(W, H, M, 32); | ||
132 | swap_bytes(W, Key); | ||
133 | /* Encrypt first 8 bytes of H with first key */ | ||
134 | Gost2814789_set_key(&c->cipher, Key, 256); | ||
135 | Gost2814789_encrypt(H, S, &c->cipher); | ||
136 | |||
137 | /* Compute second key */ | ||
138 | circle_xor8(H, U); | ||
139 | circle_xor8(M, V); | ||
140 | circle_xor8(V, V); | ||
141 | xor_blocks(W, U, V, 32); | ||
142 | swap_bytes(W, Key); | ||
143 | /* encrypt second 8 bytes of H with second key */ | ||
144 | Gost2814789_set_key(&c->cipher, Key, 256); | ||
145 | Gost2814789_encrypt(H+8, S+8, &c->cipher); | ||
146 | |||
147 | /* compute third key */ | ||
148 | circle_xor8(U, U); | ||
149 | U[31] = ~U[31]; | ||
150 | U[29] = ~U[29]; | ||
151 | U[28] = ~U[28]; | ||
152 | U[24] = ~U[24]; | ||
153 | U[23] = ~U[23]; | ||
154 | U[20] = ~U[20]; | ||
155 | U[18] = ~U[18]; | ||
156 | U[17] = ~U[17]; | ||
157 | U[14] = ~U[14]; | ||
158 | U[12] = ~U[12]; | ||
159 | U[10] = ~U[10]; | ||
160 | U[8] = ~U[8]; | ||
161 | U[7] = ~U[7]; | ||
162 | U[5] = ~U[5]; | ||
163 | U[3] = ~U[3]; | ||
164 | U[1] = ~U[1]; | ||
165 | circle_xor8(V, V); | ||
166 | circle_xor8(V, V); | ||
167 | xor_blocks(W, U, V, 32); | ||
168 | swap_bytes(W, Key); | ||
169 | /* encrypt third 8 bytes of H with third key */ | ||
170 | Gost2814789_set_key(&c->cipher, Key, 256); | ||
171 | Gost2814789_encrypt(H+16, S+16, &c->cipher); | ||
172 | |||
173 | /* Compute fourth key */ | ||
174 | circle_xor8(U, U); | ||
175 | circle_xor8(V, V); | ||
176 | circle_xor8(V, V); | ||
177 | xor_blocks(W, U, V, 32); | ||
178 | swap_bytes(W, Key); | ||
179 | /* Encrypt last 8 bytes with fourth key */ | ||
180 | Gost2814789_set_key(&c->cipher, Key, 256); | ||
181 | Gost2814789_encrypt(H+24, S+24, &c->cipher); | ||
182 | |||
183 | for (i = 0; i < 12; i++) | ||
184 | transform_3(S); | ||
185 | xor_blocks(S, S, M, 32); | ||
186 | transform_3(S); | ||
187 | xor_blocks(S, S, H, 32); | ||
188 | for (i = 0; i < 61; i++) | ||
189 | transform_3(S); | ||
190 | memcpy(H, S, 32); | ||
191 | return 1; | ||
192 | } | ||
193 | |||
194 | int GOSTR341194_Init(GOSTR341194_CTX *c, int nid) | ||
195 | { | ||
196 | memset (c,0,sizeof(*c)); | ||
197 | return Gost2814789_set_sbox(&c->cipher, nid); | ||
198 | } | ||
199 | |||
200 | static void GOSTR341194_block_data_order(GOSTR341194_CTX *ctx, const void *p, size_t num) | ||
201 | { | ||
202 | int i; | ||
203 | for (i = 0; i < num; i++) { | ||
204 | hash_step(ctx, ctx->H, p); | ||
205 | add_blocks(32, ctx->S, p); | ||
206 | p += 32; | ||
207 | } | ||
208 | } | ||
209 | |||
210 | #define DATA_ORDER_IS_LITTLE_ENDIAN | ||
211 | |||
212 | #define HASH_CBLOCK GOSTR341194_CBLOCK | ||
213 | #define HASH_LONG GOSTR341194_LONG | ||
214 | #define HASH_CTX GOSTR341194_CTX | ||
215 | #define HASH_UPDATE GOSTR341194_Update | ||
216 | #define HASH_TRANSFORM GOSTR341194_Transform | ||
217 | #define HASH_NO_FINAL 1 | ||
218 | #define HASH_BLOCK_DATA_ORDER GOSTR341194_block_data_order | ||
219 | |||
220 | #include "md32_common.h" | ||
221 | |||
222 | int GOSTR341194_Final(unsigned char *md, GOSTR341194_CTX * c) | ||
223 | { | ||
224 | unsigned char *p = (unsigned char *)c->data; | ||
225 | unsigned char T[32]; | ||
226 | |||
227 | if (c->num > 0) { | ||
228 | memset(p + c->num, 0, 32); | ||
229 | hash_step(c, c->H, p); | ||
230 | add_blocks(32, c->S, p); | ||
231 | } | ||
232 | |||
233 | p = T; | ||
234 | HOST_l2c(c->Nl, p); | ||
235 | HOST_l2c(c->Nh, p); | ||
236 | memset(p, 0, 32-8); | ||
237 | hash_step(c, c->H, T); | ||
238 | hash_step(c, c->H, c->S); | ||
239 | |||
240 | memcpy(md, c->H, 32); | ||
241 | |||
242 | return 1; | ||
243 | } | ||
244 | |||
245 | unsigned char *GOSTR341194(const unsigned char *d, size_t n, unsigned char *md, int nid) | ||
246 | { | ||
247 | GOSTR341194_CTX c; | ||
248 | static unsigned char m[GOSTR341194_LENGTH]; | ||
249 | |||
250 | if (md == NULL) | ||
251 | md = m; | ||
252 | if (!GOSTR341194_Init(&c, nid)) | ||
253 | return 0; | ||
254 | GOSTR341194_Update(&c, d, n); | ||
255 | GOSTR341194_Final(md, &c); | ||
256 | OPENSSL_cleanse(&c, sizeof(c)); | ||
257 | return (md); | ||
258 | } | ||
259 | #endif | ||
diff --git a/src/lib/libcrypto/gost/streebog.c b/src/lib/libcrypto/gost/streebog.c new file mode 100644 index 0000000000..c621c41daa --- /dev/null +++ b/src/lib/libcrypto/gost/streebog.c | |||
@@ -0,0 +1,1436 @@ | |||
1 | /* $OpenBSD: streebog.c,v 1.1 2014/11/09 19:17:13 miod Exp $ */ | ||
2 | /* | ||
3 | * Copyright (c) 2014 Dmitry Eremin-Solenikov <dbaryshkov@gmail.com> | ||
4 | * Copyright (c) 2005-2006 Cryptocom LTD | ||
5 | * | ||
6 | * Redistribution and use in source and binary forms, with or without | ||
7 | * modification, are permitted provided that the following conditions | ||
8 | * are met: | ||
9 | * | ||
10 | * 1. Redistributions of source code must retain the above copyright | ||
11 | * notice, this list of conditions and the following disclaimer. | ||
12 | * | ||
13 | * 2. Redistributions in binary form must reproduce the above copyright | ||
14 | * notice, this list of conditions and the following disclaimer in | ||
15 | * the documentation and/or other materials provided with the | ||
16 | * distribution. | ||
17 | * | ||
18 | * 3. All advertising materials mentioning features or use of this | ||
19 | * software must display the following acknowledgment: | ||
20 | * "This product includes software developed by the OpenSSL Project | ||
21 | * for use in the OpenSSL Toolkit. (http://www.openssl.org/)" | ||
22 | * | ||
23 | * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to | ||
24 | * endorse or promote products derived from this software without | ||
25 | * prior written permission. For written permission, please contact | ||
26 | * openssl-core@openssl.org. | ||
27 | * | ||
28 | * 5. Products derived from this software may not be called "OpenSSL" | ||
29 | * nor may "OpenSSL" appear in their names without prior written | ||
30 | * permission of the OpenSSL Project. | ||
31 | * | ||
32 | * 6. Redistributions of any form whatsoever must retain the following | ||
33 | * acknowledgment: | ||
34 | * "This product includes software developed by the OpenSSL Project | ||
35 | * for use in the OpenSSL Toolkit (http://www.openssl.org/)" | ||
36 | * | ||
37 | * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY | ||
38 | * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | ||
39 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR | ||
40 | * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR | ||
41 | * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, | ||
42 | * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT | ||
43 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; | ||
44 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | ||
45 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, | ||
46 | * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) | ||
47 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED | ||
48 | * OF THE POSSIBILITY OF SUCH DAMAGE. | ||
49 | * ==================================================================== | ||
50 | */ | ||
51 | |||
52 | #include <string.h> | ||
53 | |||
54 | #include <openssl/opensslconf.h> | ||
55 | |||
56 | #ifndef OPENSSL_NO_GOST | ||
57 | #include <openssl/crypto.h> | ||
58 | #include <openssl/objects.h> | ||
59 | #include <openssl/gost.h> | ||
60 | |||
61 | #include "gost_locl.h" | ||
62 | |||
63 | static const STREEBOG_LONG64 A_PI_table[8][256] = | ||
64 | { | ||
65 | { /* 0 */ | ||
66 | U64(0xd01f715b5c7ef8e6), U64(0x16fa240980778325), | ||
67 | U64(0xa8a42e857ee049c8), U64(0x6ac1068fa186465b), | ||
68 | U64(0x6e417bd7a2e9320b), U64(0x665c8167a437daab), | ||
69 | U64(0x7666681aa89617f6), U64(0x4b959163700bdcf5), | ||
70 | U64(0xf14be6b78df36248), U64(0xc585bd689a625cff), | ||
71 | U64(0x9557d7fca67d82cb), U64(0x89f0b969af6dd366), | ||
72 | U64(0xb0833d48749f6c35), U64(0xa1998c23b1ecbc7c), | ||
73 | U64(0x8d70c431ac02a736), U64(0xd6dfbc2fd0a8b69e), | ||
74 | U64(0x37aeb3e551fa198b), U64(0x0b7d128a40b5cf9c), | ||
75 | U64(0x5a8f2008b5780cbc), U64(0xedec882284e333e5), | ||
76 | U64(0xd25fc177d3c7c2ce), U64(0x5e0f5d50b61778ec), | ||
77 | U64(0x1d873683c0c24cb9), U64(0xad040bcbb45d208c), | ||
78 | U64(0x2f89a0285b853c76), U64(0x5732fff6791b8d58), | ||
79 | U64(0x3e9311439ef6ec3f), U64(0xc9183a809fd3c00f), | ||
80 | U64(0x83adf3f5260a01ee), U64(0xa6791941f4e8ef10), | ||
81 | U64(0x103ae97d0ca1cd5d), U64(0x2ce948121dee1b4a), | ||
82 | U64(0x39738421dbf2bf53), U64(0x093da2a6cf0cf5b4), | ||
83 | U64(0xcd9847d89cbcb45f), U64(0xf9561c078b2d8ae8), | ||
84 | U64(0x9c6a755a6971777f), U64(0xbc1ebaa0712ef0c5), | ||
85 | U64(0x72e61542abf963a6), U64(0x78bb5fde229eb12e), | ||
86 | U64(0x14ba94250fceb90d), U64(0x844d6697630e5282), | ||
87 | U64(0x98ea08026a1e032f), U64(0xf06bbea144217f5c), | ||
88 | U64(0xdb6263d11ccb377a), U64(0x641c314b2b8ee083), | ||
89 | U64(0x320e96ab9b4770cf), U64(0x1ee7deb986a96b85), | ||
90 | U64(0xe96cf57a878c47b5), U64(0xfdd6615f8842feb8), | ||
91 | U64(0xc83862965601dd1b), U64(0x2ea9f83e92572162), | ||
92 | U64(0xf876441142ff97fc), U64(0xeb2c455608357d9d), | ||
93 | U64(0x5612a7e0b0c9904c), U64(0x6c01cbfb2d500823), | ||
94 | U64(0x4548a6a7fa037a2d), U64(0xabc4c6bf388b6ef4), | ||
95 | U64(0xbade77d4fdf8bebd), U64(0x799b07c8eb4cac3a), | ||
96 | U64(0x0c9d87e805b19cf0), U64(0xcb588aac106afa27), | ||
97 | U64(0xea0c1d40c1e76089), U64(0x2869354a1e816f1a), | ||
98 | U64(0xff96d17307fbc490), U64(0x9f0a9d602f1a5043), | ||
99 | U64(0x96373fc6e016a5f7), U64(0x5292dab8b3a6e41c), | ||
100 | U64(0x9b8ae0382c752413), U64(0x4f15ec3b7364a8a5), | ||
101 | U64(0x3fb349555724f12b), U64(0xc7c50d4415db66d7), | ||
102 | U64(0x92b7429ee379d1a7), U64(0xd37f99611a15dfda), | ||
103 | U64(0x231427c05e34a086), U64(0xa439a96d7b51d538), | ||
104 | U64(0xb403401077f01865), U64(0xdda2aea5901d7902), | ||
105 | U64(0x0a5d4a9c8967d288), U64(0xc265280adf660f93), | ||
106 | U64(0x8bb0094520d4e94e), U64(0x2a29856691385532), | ||
107 | U64(0x42a833c5bf072941), U64(0x73c64d54622b7eb2), | ||
108 | U64(0x07e095624504536c), U64(0x8a905153e906f45a), | ||
109 | U64(0x6f6123c16b3b2f1f), U64(0xc6e55552dc097bc3), | ||
110 | U64(0x4468feb133d16739), U64(0xe211e7f0c7398829), | ||
111 | U64(0xa2f96419f7879b40), U64(0x19074bdbc3ad38e9), | ||
112 | U64(0xf4ebc3f9474e0b0c), U64(0x43886bd376d53455), | ||
113 | U64(0xd8028beb5aa01046), U64(0x51f23282f5cdc320), | ||
114 | U64(0xe7b1c2be0d84e16d), U64(0x081dfab006dee8a0), | ||
115 | U64(0x3b33340d544b857b), U64(0x7f5bcabc679ae242), | ||
116 | U64(0x0edd37c48a08a6d8), U64(0x81ed43d9a9b33bc6), | ||
117 | U64(0xb1a3655ebd4d7121), U64(0x69a1eeb5e7ed6167), | ||
118 | U64(0xf6ab73d5c8f73124), U64(0x1a67a3e185c61fd5), | ||
119 | U64(0x2dc91004d43c065e), U64(0x0240b02c8fb93a28), | ||
120 | U64(0x90f7f2b26cc0eb8f), U64(0x3cd3a16f114fd617), | ||
121 | U64(0xaae49ea9f15973e0), U64(0x06c0cd748cd64e78), | ||
122 | U64(0xda423bc7d5192a6e), U64(0xc345701c16b41287), | ||
123 | U64(0x6d2193ede4821537), U64(0xfcf639494190e3ac), | ||
124 | U64(0x7c3b228621f1c57e), U64(0xfb16ac2b0494b0c0), | ||
125 | U64(0xbf7e529a3745d7f9), U64(0x6881b6a32e3f7c73), | ||
126 | U64(0xca78d2bad9b8e733), U64(0xbbfe2fc2342aa3a9), | ||
127 | U64(0x0dbddffecc6381e4), U64(0x70a6a56e2440598e), | ||
128 | U64(0xe4d12a844befc651), U64(0x8c509c2765d0ba22), | ||
129 | U64(0xee8c6018c28814d9), U64(0x17da7c1f49a59e31), | ||
130 | U64(0x609c4c1328e194d3), U64(0xb3e3d57232f44b09), | ||
131 | U64(0x91d7aaa4a512f69b), U64(0x0ffd6fd243dabbcc), | ||
132 | U64(0x50d26a943c1fde34), U64(0x6be15e9968545b4f), | ||
133 | U64(0x94778fea6faf9fdf), U64(0x2b09dd7058ea4826), | ||
134 | U64(0x677cd9716de5c7bf), U64(0x49d5214fffb2e6dd), | ||
135 | U64(0x0360e83a466b273c), U64(0x1fc786af4f7b7691), | ||
136 | U64(0xa0b9d435783ea168), U64(0xd49f0c035f118cb6), | ||
137 | U64(0x01205816c9d21d14), U64(0xac2453dd7d8f3d98), | ||
138 | U64(0x545217cc3f70aa64), U64(0x26b4028e9489c9c2), | ||
139 | U64(0xdec2469fd6765e3e), U64(0x04807d58036f7450), | ||
140 | U64(0xe5f17292823ddb45), U64(0xf30b569b024a5860), | ||
141 | U64(0x62dcfc3fa758aefb), U64(0xe84cad6c4e5e5aa1), | ||
142 | U64(0xccb81fce556ea94b), U64(0x53b282ae7a74f908), | ||
143 | U64(0x1b47fbf74c1402c1), U64(0x368eebf39828049f), | ||
144 | U64(0x7afbeff2ad278b06), U64(0xbe5e0a8cfe97caed), | ||
145 | U64(0xcfd8f7f413058e77), U64(0xf78b2bc301252c30), | ||
146 | U64(0x4d555c17fcdd928d), U64(0x5f2f05467fc565f8), | ||
147 | U64(0x24f4b2a21b30f3ea), U64(0x860dd6bbecb768aa), | ||
148 | U64(0x4c750401350f8f99), U64(0x0000000000000000), | ||
149 | U64(0xecccd0344d312ef1), U64(0xb5231806be220571), | ||
150 | U64(0xc105c030990d28af), U64(0x653c695de25cfd97), | ||
151 | U64(0x159acc33c61ca419), U64(0xb89ec7f872418495), | ||
152 | U64(0xa9847693b73254dc), U64(0x58cf90243ac13694), | ||
153 | U64(0x59efc832f3132b80), U64(0x5c4fed7c39ae42c4), | ||
154 | U64(0x828dabe3efd81cfa), U64(0xd13f294d95ace5f2), | ||
155 | U64(0x7d1b7a90e823d86a), U64(0xb643f03cf849224d), | ||
156 | U64(0x3df3f979d89dcb03), U64(0x7426d836272f2dde), | ||
157 | U64(0xdfe21e891fa4432a), U64(0x3a136c1b9d99986f), | ||
158 | U64(0xfa36f43dcd46add4), U64(0xc025982650df35bb), | ||
159 | U64(0x856d3e81aadc4f96), U64(0xc4a5e57e53b041eb), | ||
160 | U64(0x4708168b75ba4005), U64(0xaf44bbe73be41aa4), | ||
161 | U64(0x971767d029c4b8e3), U64(0xb9be9feebb939981), | ||
162 | U64(0x215497ecd18d9aae), U64(0x316e7e91dd2c57f3), | ||
163 | U64(0xcef8afe2dad79363), U64(0x3853dc371220a247), | ||
164 | U64(0x35ee03c9de4323a3), U64(0xe6919aa8c456fc79), | ||
165 | U64(0xe05157dc4880b201), U64(0x7bdbb7e464f59612), | ||
166 | U64(0x127a59518318f775), U64(0x332ecebd52956ddb), | ||
167 | U64(0x8f30741d23bb9d1e), U64(0xd922d3fd93720d52), | ||
168 | U64(0x7746300c61440ae2), U64(0x25d4eab4d2e2eefe), | ||
169 | U64(0x75068020eefd30ca), U64(0x135a01474acaea61), | ||
170 | U64(0x304e268714fe4ae7), U64(0xa519f17bb283c82c), | ||
171 | U64(0xdc82f6b359cf6416), U64(0x5baf781e7caa11a8), | ||
172 | U64(0xb2c38d64fb26561d), U64(0x34ce5bdf17913eb7), | ||
173 | U64(0x5d6fb56af07c5fd0), U64(0x182713cd0a7f25fd), | ||
174 | U64(0x9e2ac576e6c84d57), U64(0x9aaab82ee5a73907), | ||
175 | U64(0xa3d93c0f3e558654), U64(0x7e7b92aaae48ff56), | ||
176 | U64(0x872d8ead256575be), U64(0x41c8dbfff96c0e7d), | ||
177 | U64(0x99ca5014a3cc1e3b), U64(0x40e883e930be1369), | ||
178 | U64(0x1ca76e95091051ad), U64(0x4e35b42dbab6b5b1), | ||
179 | U64(0x05a0254ecabd6944), U64(0xe1710fca8152af15), | ||
180 | U64(0xf22b0e8dcb984574), U64(0xb763a82a319b3f59), | ||
181 | U64(0x63fca4296e8ab3ef), U64(0x9d4a2d4ca0a36a6b), | ||
182 | U64(0xe331bfe60eeb953d), U64(0xd5bf541596c391a2), | ||
183 | U64(0xf5cb9bef8e9c1618), U64(0x46284e9dbc685d11), | ||
184 | U64(0x2074cffa185f87ba), U64(0xbd3ee2b6b8fcedd1), | ||
185 | U64(0xae64e3f1f23607b0), U64(0xfeb68965ce29d984), | ||
186 | U64(0x55724fdaf6a2b770), U64(0x29496d5cd753720e), | ||
187 | U64(0xa75941573d3af204), U64(0x8e102c0bea69800a), | ||
188 | U64(0x111ab16bc573d049), U64(0xd7ffe439197aab8a), | ||
189 | U64(0xefac380e0b5a09cd), U64(0x48f579593660fbc9), | ||
190 | U64(0x22347fd697e6bd92), U64(0x61bc1405e13389c7), | ||
191 | U64(0x4ab5c975b9d9c1e1), U64(0x80cd1bcf606126d2), | ||
192 | U64(0x7186fd78ed92449a), U64(0x93971a882aabccb3), | ||
193 | U64(0x88d0e17f66bfce72), U64(0x27945a985d5bd4d6) | ||
194 | }, { /* 1 */ | ||
195 | U64(0xde553f8c05a811c8), U64(0x1906b59631b4f565), | ||
196 | U64(0x436e70d6b1964ff7), U64(0x36d343cb8b1e9d85), | ||
197 | U64(0x843dfacc858aab5a), U64(0xfdfc95c299bfc7f9), | ||
198 | U64(0x0f634bdea1d51fa2), U64(0x6d458b3b76efb3cd), | ||
199 | U64(0x85c3f77cf8593f80), U64(0x3c91315fbe737cb2), | ||
200 | U64(0x2148b03366ace398), U64(0x18f8b8264c6761bf), | ||
201 | U64(0xc830c1c495c9fb0f), U64(0x981a76102086a0aa), | ||
202 | U64(0xaa16012142f35760), U64(0x35cc54060c763cf6), | ||
203 | U64(0x42907d66cc45db2d), U64(0x8203d44b965af4bc), | ||
204 | U64(0x3d6f3cefc3a0e868), U64(0xbc73ff69d292bda7), | ||
205 | U64(0x8722ed0102e20a29), U64(0x8f8185e8cd34deb7), | ||
206 | U64(0x9b0561dda7ee01d9), U64(0x5335a0193227fad6), | ||
207 | U64(0xc9cecc74e81a6fd5), U64(0x54f5832e5c2431ea), | ||
208 | U64(0x99e47ba05d553470), U64(0xf7bee756acd226ce), | ||
209 | U64(0x384e05a5571816fd), U64(0xd1367452a47d0e6a), | ||
210 | U64(0xf29fde1c386ad85b), U64(0x320c77316275f7ca), | ||
211 | U64(0xd0c879e2d9ae9ab0), U64(0xdb7406c69110ef5d), | ||
212 | U64(0x45505e51a2461011), U64(0xfc029872e46c5323), | ||
213 | U64(0xfa3cb6f5f7bc0cc5), U64(0x031f17cd8768a173), | ||
214 | U64(0xbd8df2d9af41297d), U64(0x9d3b4f5ab43e5e3f), | ||
215 | U64(0x4071671b36feee84), U64(0x716207e7d3e3b83d), | ||
216 | U64(0x48d20ff2f9283a1a), U64(0x27769eb4757cbc7e), | ||
217 | U64(0x5c56ebc793f2e574), U64(0xa48b474f9ef5dc18), | ||
218 | U64(0x52cbada94ff46e0c), U64(0x60c7da982d8199c6), | ||
219 | U64(0x0e9d466edc068b78), U64(0x4eec2175eaf865fc), | ||
220 | U64(0x550b8e9e21f7a530), U64(0x6b7ba5bc653fec2b), | ||
221 | U64(0x5eb7f1ba6949d0dd), U64(0x57ea94e3db4c9099), | ||
222 | U64(0xf640eae6d101b214), U64(0xdd4a284182c0b0bb), | ||
223 | U64(0xff1d8fbf6304f250), U64(0xb8accb933bf9d7e8), | ||
224 | U64(0xe8867c478eb68c4d), U64(0x3f8e2692391bddc1), | ||
225 | U64(0xcb2fd60912a15a7c), U64(0xaec935dbab983d2f), | ||
226 | U64(0xf55ffd2b56691367), U64(0x80e2ce366ce1c115), | ||
227 | U64(0x179bf3f8edb27e1d), U64(0x01fe0db07dd394da), | ||
228 | U64(0xda8a0b76ecc37b87), U64(0x44ae53e1df9584cb), | ||
229 | U64(0xb310b4b77347a205), U64(0xdfab323c787b8512), | ||
230 | U64(0x3b511268d070b78e), U64(0x65e6e3d2b9396753), | ||
231 | U64(0x6864b271e2574d58), U64(0x259784c98fc789d7), | ||
232 | U64(0x02e11a7dfabb35a9), U64(0x8841a6dfa337158b), | ||
233 | U64(0x7ade78c39b5dcdd0), U64(0xb7cf804d9a2cc84a), | ||
234 | U64(0x20b6bd831b7f7742), U64(0x75bd331d3a88d272), | ||
235 | U64(0x418f6aab4b2d7a5e), U64(0xd9951cbb6babdaf4), | ||
236 | U64(0xb6318dfde7ff5c90), U64(0x1f389b112264aa83), | ||
237 | U64(0x492c024284fbaec0), U64(0xe33a0363c608f9a0), | ||
238 | U64(0x2688930408af28a4), U64(0xc7538a1a341ce4ad), | ||
239 | U64(0x5da8e677ee2171ae), U64(0x8c9e92254a5c7fc4), | ||
240 | U64(0x63d8cd55aae938b5), U64(0x29ebd8daa97a3706), | ||
241 | U64(0x959827b37be88aa1), U64(0x1484e4356adadf6e), | ||
242 | U64(0xa7945082199d7d6b), U64(0xbf6ce8a455fa1cd4), | ||
243 | U64(0x9cc542eac9edcae5), U64(0x79c16f0e1c356ca3), | ||
244 | U64(0x89bfab6fdee48151), U64(0xd4174d1830c5f0ff), | ||
245 | U64(0x9258048415eb419d), U64(0x6139d72850520d1c), | ||
246 | U64(0x6a85a80c18ec78f1), U64(0xcd11f88e0171059a), | ||
247 | U64(0xcceff53e7ca29140), U64(0xd229639f2315af19), | ||
248 | U64(0x90b91ef9ef507434), U64(0x5977d28d074a1be1), | ||
249 | U64(0x311360fce51d56b9), U64(0xc093a92d5a1f2f91), | ||
250 | U64(0x1a19a25bb6dc5416), U64(0xeb996b8a09de2d3e), | ||
251 | U64(0xfee3820f1ed7668a), U64(0xd7085ad5b7ad518c), | ||
252 | U64(0x7fff41890fe53345), U64(0xec5948bd67dde602), | ||
253 | U64(0x2fd5f65dbaaa68e0), U64(0xa5754affe32648c2), | ||
254 | U64(0xf8ddac880d07396c), U64(0x6fa491468c548664), | ||
255 | U64(0x0c7c5c1326bdbed1), U64(0x4a33158f03930fb3), | ||
256 | U64(0x699abfc19f84d982), U64(0xe4fa2054a80b329c), | ||
257 | U64(0x6707f9af438252fa), U64(0x08a368e9cfd6d49e), | ||
258 | U64(0x47b1442c58fd25b8), U64(0xbbb3dc5ebc91769b), | ||
259 | U64(0x1665fe489061eac7), U64(0x33f27a811fa66310), | ||
260 | U64(0x93a609346838d547), U64(0x30ed6d4c98cec263), | ||
261 | U64(0x1dd9816cd8df9f2a), U64(0x94662a03063b1e7b), | ||
262 | U64(0x83fdd9fbeb896066), U64(0x7b207573e68e590a), | ||
263 | U64(0x5f49fc0a149a4407), U64(0x343259b671a5a82c), | ||
264 | U64(0xfbc2bb458a6f981f), U64(0xc272b350a0a41a38), | ||
265 | U64(0x3aaf1fd8ada32354), U64(0x6cbb868b0b3c2717), | ||
266 | U64(0xa2b569c88d2583fe), U64(0xf180c9d1bf027928), | ||
267 | U64(0xaf37386bd64ba9f5), U64(0x12bacab2790a8088), | ||
268 | U64(0x4c0d3b0810435055), U64(0xb2eeb9070e9436df), | ||
269 | U64(0xc5b29067cea7d104), U64(0xdcb425f1ff132461), | ||
270 | U64(0x4f122cc5972bf126), U64(0xac282fa651230886), | ||
271 | U64(0xe7e537992f6393ef), U64(0xe61b3a2952b00735), | ||
272 | U64(0x709c0a57ae302ce7), U64(0xe02514ae416058d3), | ||
273 | U64(0xc44c9dd7b37445de), U64(0x5a68c5408022ba92), | ||
274 | U64(0x1c278cdca50c0bf0), U64(0x6e5a9cf6f18712be), | ||
275 | U64(0x86dce0b17f319ef3), U64(0x2d34ec2040115d49), | ||
276 | U64(0x4bcd183f7e409b69), U64(0x2815d56ad4a9a3dc), | ||
277 | U64(0x24698979f2141d0d), U64(0x0000000000000000), | ||
278 | U64(0x1ec696a15fb73e59), U64(0xd86b110b16784e2e), | ||
279 | U64(0x8e7f8858b0e74a6d), U64(0x063e2e8713d05fe6), | ||
280 | U64(0xe2c40ed3bbdb6d7a), U64(0xb1f1aeca89fc97ac), | ||
281 | U64(0xe1db191e3cb3cc09), U64(0x6418ee62c4eaf389), | ||
282 | U64(0xc6ad87aa49cf7077), U64(0xd6f65765ca7ec556), | ||
283 | U64(0x9afb6c6dda3d9503), U64(0x7ce05644888d9236), | ||
284 | U64(0x8d609f95378feb1e), U64(0x23a9aa4e9c17d631), | ||
285 | U64(0x6226c0e5d73aac6f), U64(0x56149953a69f0443), | ||
286 | U64(0xeeb852c09d66d3ab), U64(0x2b0ac2a753c102af), | ||
287 | U64(0x07c023376e03cb3c), U64(0x2ccae1903dc2c993), | ||
288 | U64(0xd3d76e2f5ec63bc3), U64(0x9e2458973356ff4c), | ||
289 | U64(0xa66a5d32644ee9b1), U64(0x0a427294356de137), | ||
290 | U64(0x783f62be61e6f879), U64(0x1344c70204d91452), | ||
291 | U64(0x5b96c8f0fdf12e48), U64(0xa90916ecc59bf613), | ||
292 | U64(0xbe92e5142829880e), U64(0x727d102a548b194e), | ||
293 | U64(0x1be7afebcb0fc0cc), U64(0x3e702b2244c8491b), | ||
294 | U64(0xd5e940a84d166425), U64(0x66f9f41f3e51c620), | ||
295 | U64(0xabe80c913f20c3ba), U64(0xf07ec461c2d1edf2), | ||
296 | U64(0xf361d3ac45b94c81), U64(0x0521394a94b8fe95), | ||
297 | U64(0xadd622162cf09c5c), U64(0xe97871f7f3651897), | ||
298 | U64(0xf4a1f09b2bba87bd), U64(0x095d6559b2054044), | ||
299 | U64(0x0bbc7f2448be75ed), U64(0x2af4cf172e129675), | ||
300 | U64(0x157ae98517094bb4), U64(0x9fda55274e856b96), | ||
301 | U64(0x914713499283e0ee), U64(0xb952c623462a4332), | ||
302 | U64(0x74433ead475b46a8), U64(0x8b5eb112245fb4f8), | ||
303 | U64(0xa34b6478f0f61724), U64(0x11a5dd7ffe6221fb), | ||
304 | U64(0xc16da49d27ccbb4b), U64(0x76a224d0bde07301), | ||
305 | U64(0x8aa0bca2598c2022), U64(0x4df336b86d90c48f), | ||
306 | U64(0xea67663a740db9e4), U64(0xef465f70e0b54771), | ||
307 | U64(0x39b008152acb8227), U64(0x7d1e5bf4f55e06ec), | ||
308 | U64(0x105bd0cf83b1b521), U64(0x775c2960c033e7db), | ||
309 | U64(0x7e014c397236a79f), U64(0x811cc386113255cf), | ||
310 | U64(0xeda7450d1a0e72d8), U64(0x5889df3d7a998f3b), | ||
311 | U64(0x2e2bfbedc779fc3a), U64(0xce0eef438619a4e9), | ||
312 | U64(0x372d4e7bf6cd095f), U64(0x04df34fae96b6a4f), | ||
313 | U64(0xf923a13870d4adb6), U64(0xa1aa7e050a4d228d), | ||
314 | U64(0xa8f71b5cb84862c9), U64(0xb52e9a306097fde3), | ||
315 | U64(0x0d8251a35b6e2a0b), U64(0x2257a7fee1c442eb), | ||
316 | U64(0x73831d9a29588d94), U64(0x51d4ba64c89ccf7f), | ||
317 | U64(0x502ab7d4b54f5ba5), U64(0x97793dce8153bf08), | ||
318 | U64(0xe5042de4d5d8a646), U64(0x9687307efc802bd2), | ||
319 | U64(0xa05473b5779eb657), U64(0xb4d097801d446939), | ||
320 | U64(0xcff0e2f3fbca3033), U64(0xc38cbee0dd778ee2), | ||
321 | U64(0x464f499c252eb162), U64(0xcad1dbb96f72cea6), | ||
322 | U64(0xba4dd1eec142e241), U64(0xb00fa37af42f0376) | ||
323 | }, { /* 2 */ | ||
324 | U64(0xcce4cd3aa968b245), U64(0x089d5484e80b7faf), | ||
325 | U64(0x638246c1b3548304), U64(0xd2fe0ec8c2355492), | ||
326 | U64(0xa7fbdf7ff2374eee), U64(0x4df1600c92337a16), | ||
327 | U64(0x84e503ea523b12fb), U64(0x0790bbfd53ab0c4a), | ||
328 | U64(0x198a780f38f6ea9d), U64(0x2ab30c8f55ec48cb), | ||
329 | U64(0xe0f7fed6b2c49db5), U64(0xb6ecf3f422cadbdc), | ||
330 | U64(0x409c9a541358df11), U64(0xd3ce8a56dfde3fe3), | ||
331 | U64(0xc3e9224312c8c1a0), U64(0x0d6dfa58816ba507), | ||
332 | U64(0xddf3e1b179952777), U64(0x04c02a42748bb1d9), | ||
333 | U64(0x94c2abff9f2decb8), U64(0x4f91752da8f8acf4), | ||
334 | U64(0x78682befb169bf7b), U64(0xe1c77a48af2ff6c4), | ||
335 | U64(0x0c5d7ec69c80ce76), U64(0x4cc1e4928fd81167), | ||
336 | U64(0xfeed3d24d9997b62), U64(0x518bb6dfc3a54a23), | ||
337 | U64(0x6dbf2d26151f9b90), U64(0xb5bc624b05ea664f), | ||
338 | U64(0xe86aaa525acfe21a), U64(0x4801ced0fb53a0be), | ||
339 | U64(0xc91463e6c00868ed), U64(0x1027a815cd16fe43), | ||
340 | U64(0xf67069a0319204cd), U64(0xb04ccc976c8abce7), | ||
341 | U64(0xc0b9b3fc35e87c33), U64(0xf380c77c58f2de65), | ||
342 | U64(0x50bb3241de4e2152), U64(0xdf93f490435ef195), | ||
343 | U64(0xf1e0d25d62390887), U64(0xaf668bfb1a3c3141), | ||
344 | U64(0xbc11b251f00a7291), U64(0x73a5eed47e427d47), | ||
345 | U64(0x25bee3f6ee4c3b2e), U64(0x43cc0beb34786282), | ||
346 | U64(0xc824e778dde3039c), U64(0xf97d86d98a327728), | ||
347 | U64(0xf2b043e24519b514), U64(0xe297ebf7880f4b57), | ||
348 | U64(0x3a94a49a98fab688), U64(0x868516cb68f0c419), | ||
349 | U64(0xeffa11af0964ee50), U64(0xa4ab4ec0d517f37d), | ||
350 | U64(0xa9c6b498547c567a), U64(0x8e18424f80fbbbb6), | ||
351 | U64(0x0bcdc53bcf2bc23c), U64(0x137739aaea3643d0), | ||
352 | U64(0x2c1333ec1bac2ff0), U64(0x8d48d3f0a7db0625), | ||
353 | U64(0x1e1ac3f26b5de6d7), U64(0xf520f81f16b2b95e), | ||
354 | U64(0x9f0f6ec450062e84), U64(0x0130849e1deb6b71), | ||
355 | U64(0xd45e31ab8c7533a9), U64(0x652279a2fd14e43f), | ||
356 | U64(0x3209f01e70f1c927), U64(0xbe71a770cac1a473), | ||
357 | U64(0x0e3d6be7a64b1894), U64(0x7ec8148cff29d840), | ||
358 | U64(0xcb7476c7fac3be0f), U64(0x72956a4a63a91636), | ||
359 | U64(0x37f95ec21991138f), U64(0x9e3fea5a4ded45f5), | ||
360 | U64(0x7b38ba50964902e8), U64(0x222e580bbde73764), | ||
361 | U64(0x61e253e0899f55e6), U64(0xfc8d2805e352ad80), | ||
362 | U64(0x35994be3235ac56d), U64(0x09add01af5e014de), | ||
363 | U64(0x5e8659a6780539c6), U64(0xb17c48097161d796), | ||
364 | U64(0x026015213acbd6e2), U64(0xd1ae9f77e515e901), | ||
365 | U64(0xb7dc776a3f21b0ad), U64(0xaba6a1b96eb78098), | ||
366 | U64(0x9bcf4486248d9f5d), U64(0x582666c536455efd), | ||
367 | U64(0xfdbdac9bfeb9c6f1), U64(0xc47999be4163cdea), | ||
368 | U64(0x765540081722a7ef), U64(0x3e548ed8ec710751), | ||
369 | U64(0x3d041f67cb51bac2), U64(0x7958af71ac82d40a), | ||
370 | U64(0x36c9da5c047a78fe), U64(0xed9a048e33af38b2), | ||
371 | U64(0x26ee7249c96c86bd), U64(0x900281bdeba65d61), | ||
372 | U64(0x11172c8bd0fd9532), U64(0xea0abf73600434f8), | ||
373 | U64(0x42fc8f75299309f3), U64(0x34a9cf7d3eb1ae1c), | ||
374 | U64(0x2b838811480723ba), U64(0x5ce64c8742ceef24), | ||
375 | U64(0x1adae9b01fd6570e), U64(0x3c349bf9d6bad1b3), | ||
376 | U64(0x82453c891c7b75c0), U64(0x97923a40b80d512b), | ||
377 | U64(0x4a61dbf1c198765c), U64(0xb48ce6d518010d3e), | ||
378 | U64(0xcfb45c858e480fd6), U64(0xd933cbf30d1e96ae), | ||
379 | U64(0xd70ea014ab558e3a), U64(0xc189376228031742), | ||
380 | U64(0x9262949cd16d8b83), U64(0xeb3a3bed7def5f89), | ||
381 | U64(0x49314a4ee6b8cbcf), U64(0xdcc3652f647e4c06), | ||
382 | U64(0xda635a4c2a3e2b3d), U64(0x470c21a940f3d35b), | ||
383 | U64(0x315961a157d174b4), U64(0x6672e81dda3459ac), | ||
384 | U64(0x5b76f77a1165e36e), U64(0x445cb01667d36ec8), | ||
385 | U64(0xc5491d205c88a69b), U64(0x456c34887a3805b9), | ||
386 | U64(0xffddb9bac4721013), U64(0x99af51a71e4649bf), | ||
387 | U64(0xa15be01cbc7729d5), U64(0x52db2760e485f7b0), | ||
388 | U64(0x8c78576eba306d54), U64(0xae560f6507d75a30), | ||
389 | U64(0x95f22f6182c687c9), U64(0x71c5fbf54489aba5), | ||
390 | U64(0xca44f259e728d57e), U64(0x88b87d2ccebbdc8d), | ||
391 | U64(0xbab18d32be4a15aa), U64(0x8be8ec93e99b611e), | ||
392 | U64(0x17b713e89ebdf209), U64(0xb31c5d284baa0174), | ||
393 | U64(0xeeca9531148f8521), U64(0xb8d198138481c348), | ||
394 | U64(0x8988f9b2d350b7fc), U64(0xb9e11c8d996aa839), | ||
395 | U64(0x5a4673e40c8e881f), U64(0x1687977683569978), | ||
396 | U64(0xbf4123eed72acf02), U64(0x4ea1f1b3b513c785), | ||
397 | U64(0xe767452be16f91ff), U64(0x7505d1b730021a7c), | ||
398 | U64(0xa59bca5ec8fc980c), U64(0xad069eda20f7e7a3), | ||
399 | U64(0x38f4b1bba231606a), U64(0x60d2d77e94743e97), | ||
400 | U64(0x9affc0183966f42c), U64(0x248e6768f3a7505f), | ||
401 | U64(0xcdd449a4b483d934), U64(0x87b59255751baf68), | ||
402 | U64(0x1bea6d2e023d3c7f), U64(0x6b1f12455b5ffcab), | ||
403 | U64(0x743555292de9710d), U64(0xd8034f6d10f5fddf), | ||
404 | U64(0xc6198c9f7ba81b08), U64(0xbb8109aca3a17edb), | ||
405 | U64(0xfa2d1766ad12cabb), U64(0xc729080166437079), | ||
406 | U64(0x9c5fff7b77269317), U64(0x0000000000000000), | ||
407 | U64(0x15d706c9a47624eb), U64(0x6fdf38072fd44d72), | ||
408 | U64(0x5fb6dd3865ee52b7), U64(0xa33bf53d86bcff37), | ||
409 | U64(0xe657c1b5fc84fa8e), U64(0xaa962527735cebe9), | ||
410 | U64(0x39c43525bfda0b1b), U64(0x204e4d2a872ce186), | ||
411 | U64(0x7a083ece8ba26999), U64(0x554b9c9db72efbfa), | ||
412 | U64(0xb22cd9b656416a05), U64(0x96a2bedea5e63a5a), | ||
413 | U64(0x802529a826b0a322), U64(0x8115ad363b5bc853), | ||
414 | U64(0x8375b81701901eb1), U64(0x3069e53f4a3a1fc5), | ||
415 | U64(0xbd2136cfede119e0), U64(0x18bafc91251d81ec), | ||
416 | U64(0x1d4a524d4c7d5b44), U64(0x05f0aedc6960daa8), | ||
417 | U64(0x29e39d3072ccf558), U64(0x70f57f6b5962c0d4), | ||
418 | U64(0x989fd53903ad22ce), U64(0xf84d024797d91c59), | ||
419 | U64(0x547b1803aac5908b), U64(0xf0d056c37fd263f6), | ||
420 | U64(0xd56eb535919e58d8), U64(0x1c7ad6d351963035), | ||
421 | U64(0x2e7326cd2167f912), U64(0xac361a443d1c8cd2), | ||
422 | U64(0x697f076461942a49), U64(0x4b515f6fdc731d2d), | ||
423 | U64(0x8ad8680df4700a6f), U64(0x41ac1eca0eb3b460), | ||
424 | U64(0x7d988533d80965d3), U64(0xa8f6300649973d0b), | ||
425 | U64(0x7765c4960ac9cc9e), U64(0x7ca801adc5e20ea2), | ||
426 | U64(0xdea3700e5eb59ae4), U64(0xa06b6482a19c42a4), | ||
427 | U64(0x6a2f96db46b497da), U64(0x27def6d7d487edcc), | ||
428 | U64(0x463ca5375d18b82a), U64(0xa6cb5be1efdc259f), | ||
429 | U64(0x53eba3fef96e9cc1), U64(0xce84d81b93a364a7), | ||
430 | U64(0xf4107c810b59d22f), U64(0x333974806d1aa256), | ||
431 | U64(0x0f0def79bba073e5), U64(0x231edc95a00c5c15), | ||
432 | U64(0xe437d494c64f2c6c), U64(0x91320523f64d3610), | ||
433 | U64(0x67426c83c7df32dd), U64(0x6eefbc99323f2603), | ||
434 | U64(0x9d6f7be56acdf866), U64(0x5916e25b2bae358c), | ||
435 | U64(0x7ff89012e2c2b331), U64(0x035091bf2720bd93), | ||
436 | U64(0x561b0d22900e4669), U64(0x28d319ae6f279e29), | ||
437 | U64(0x2f43a2533c8c9263), U64(0xd09e1be9f8fe8270), | ||
438 | U64(0xf740ed3e2c796fbc), U64(0xdb53ded237d5404c), | ||
439 | U64(0x62b2c25faebfe875), U64(0x0afd41a5d2c0a94d), | ||
440 | U64(0x6412fd3ce0ff8f4e), U64(0xe3a76f6995e42026), | ||
441 | U64(0x6c8fa9b808f4f0e1), U64(0xc2d9a6dd0f23aad1), | ||
442 | U64(0x8f28c6d19d10d0c7), U64(0x85d587744fd0798a), | ||
443 | U64(0xa20b71a39b579446), U64(0x684f83fa7c7f4138), | ||
444 | U64(0xe507500adba4471d), U64(0x3f640a46f19a6c20), | ||
445 | U64(0x1247bd34f7dd28a1), U64(0x2d23b77206474481), | ||
446 | U64(0x93521002cc86e0f2), U64(0x572b89bc8de52d18), | ||
447 | U64(0xfb1d93f8b0f9a1ca), U64(0xe95a2ecc4724896b), | ||
448 | U64(0x3ba420048511ddf9), U64(0xd63e248ab6bee54b), | ||
449 | U64(0x5dd6c8195f258455), U64(0x06a03f634e40673b), | ||
450 | U64(0x1f2a476c76b68da6), U64(0x217ec9b49ac78af7), | ||
451 | U64(0xecaa80102e4453c3), U64(0x14e78257b99d4f9a) | ||
452 | }, { /* 3 */ | ||
453 | U64(0x20329b2cc87bba05), U64(0x4f5eb6f86546a531), | ||
454 | U64(0xd4f44775f751b6b1), U64(0x8266a47b850dfa8b), | ||
455 | U64(0xbb986aa15a6ca985), U64(0xc979eb08f9ae0f99), | ||
456 | U64(0x2da6f447a2375ea1), U64(0x1e74275dcd7d8576), | ||
457 | U64(0xbc20180a800bc5f8), U64(0xb4a2f701b2dc65be), | ||
458 | U64(0xe726946f981b6d66), U64(0x48e6c453bf21c94c), | ||
459 | U64(0x42cad9930f0a4195), U64(0xefa47b64aacccd20), | ||
460 | U64(0x71180a8960409a42), U64(0x8bb3329bf6a44e0c), | ||
461 | U64(0xd34c35de2d36dacc), U64(0xa92f5b7cbc23dc96), | ||
462 | U64(0xb31a85aa68bb09c3), U64(0x13e04836a73161d2), | ||
463 | U64(0xb24dfc4129c51d02), U64(0x8ae44b70b7da5acd), | ||
464 | U64(0xe671ed84d96579a7), U64(0xa4bb3417d66f3832), | ||
465 | U64(0x4572ab38d56d2de8), U64(0xb1b47761ea47215c), | ||
466 | U64(0xe81c09cf70aba15d), U64(0xffbdb872ce7f90ac), | ||
467 | U64(0xa8782297fd5dc857), U64(0x0d946f6b6a4ce4a4), | ||
468 | U64(0xe4df1f4f5b995138), U64(0x9ebc71edca8c5762), | ||
469 | U64(0x0a2c1dc0b02b88d9), U64(0x3b503c115d9d7b91), | ||
470 | U64(0xc64376a8111ec3a2), U64(0xcec199a323c963e4), | ||
471 | U64(0xdc76a87ec58616f7), U64(0x09d596e073a9b487), | ||
472 | U64(0x14583a9d7d560daf), U64(0xf4c6dc593f2a0cb4), | ||
473 | U64(0xdd21d19584f80236), U64(0x4a4836983ddde1d3), | ||
474 | U64(0xe58866a41ae745f9), U64(0xf591a5b27e541875), | ||
475 | U64(0x891dc05074586693), U64(0x5b068c651810a89e), | ||
476 | U64(0xa30346bc0c08544f), U64(0x3dbf3751c684032d), | ||
477 | U64(0x2a1e86ec785032dc), U64(0xf73f5779fca830ea), | ||
478 | U64(0xb60c05ca30204d21), U64(0x0cc316802b32f065), | ||
479 | U64(0x8770241bdd96be69), U64(0xb861e18199ee95db), | ||
480 | U64(0xf805cad91418fcd1), U64(0x29e70dccbbd20e82), | ||
481 | U64(0xc7140f435060d763), U64(0x0f3a9da0e8b0cc3b), | ||
482 | U64(0xa2543f574d76408e), U64(0xbd7761e1c175d139), | ||
483 | U64(0x4b1f4f737ca3f512), U64(0x6dc2df1f2fc137ab), | ||
484 | U64(0xf1d05c3967b14856), U64(0xa742bf3715ed046c), | ||
485 | U64(0x654030141d1697ed), U64(0x07b872abda676c7d), | ||
486 | U64(0x3ce84eba87fa17ec), U64(0xc1fb0403cb79afdf), | ||
487 | U64(0x3e46bc7105063f73), U64(0x278ae987121cd678), | ||
488 | U64(0xa1adb4778ef47cd0), U64(0x26dd906c5362c2b9), | ||
489 | U64(0x05168060589b44e2), U64(0xfbfc41f9d79ac08f), | ||
490 | U64(0x0e6de44ba9ced8fa), U64(0x9feb08068bf243a3), | ||
491 | U64(0x7b341749d06b129b), U64(0x229c69e74a87929a), | ||
492 | U64(0xe09ee6c4427c011b), U64(0x5692e30e725c4c3a), | ||
493 | U64(0xda99a33e5e9f6e4b), U64(0x353dd85af453a36b), | ||
494 | U64(0x25241b4c90e0fee7), U64(0x5de987258309d022), | ||
495 | U64(0xe230140fc0802984), U64(0x93281e86a0c0b3c6), | ||
496 | U64(0xf229d719a4337408), U64(0x6f6c2dd4ad3d1f34), | ||
497 | U64(0x8ea5b2fbae3f0aee), U64(0x8331dd90c473ee4a), | ||
498 | U64(0x346aa1b1b52db7aa), U64(0xdf8f235e06042aa9), | ||
499 | U64(0xcc6f6b68a1354b7b), U64(0x6c95a6f46ebf236a), | ||
500 | U64(0x52d31a856bb91c19), U64(0x1a35ded6d498d555), | ||
501 | U64(0xf37eaef2e54d60c9), U64(0x72e181a9a3c2a61c), | ||
502 | U64(0x98537aad51952fde), U64(0x16f6c856ffaa2530), | ||
503 | U64(0xd960281e9d1d5215), U64(0x3a0745fa1ce36f50), | ||
504 | U64(0x0b7b642bf1559c18), U64(0x59a87eae9aec8001), | ||
505 | U64(0x5e100c05408bec7c), U64(0x0441f98b19e55023), | ||
506 | U64(0xd70dcc5534d38aef), U64(0x927f676de1bea707), | ||
507 | U64(0x9769e70db925e3e5), U64(0x7a636ea29115065a), | ||
508 | U64(0x468b201816ef11b6), U64(0xab81a9b73edff409), | ||
509 | U64(0xc0ac7de88a07bb1e), U64(0x1f235eb68c0391b7), | ||
510 | U64(0x6056b074458dd30f), U64(0xbe8eeac102f7ed67), | ||
511 | U64(0xcd381283e04b5fba), U64(0x5cbefecec277c4e3), | ||
512 | U64(0xd21b4c356c48ce0d), U64(0x1019c31664b35d8c), | ||
513 | U64(0x247362a7d19eea26), U64(0xebe582efb3299d03), | ||
514 | U64(0x02aef2cb82fc289f), U64(0x86275df09ce8aaa8), | ||
515 | U64(0x28b07427faac1a43), U64(0x38a9b7319e1f47cf), | ||
516 | U64(0xc82e92e3b8d01b58), U64(0x06ef0b409b1978bc), | ||
517 | U64(0x62f842bfc771fb90), U64(0x9904034610eb3b1f), | ||
518 | U64(0xded85ab5477a3e68), U64(0x90d195a663428f98), | ||
519 | U64(0x5384636e2ac708d8), U64(0xcbd719c37b522706), | ||
520 | U64(0xae9729d76644b0eb), U64(0x7c8c65e20a0c7ee6), | ||
521 | U64(0x80c856b007f1d214), U64(0x8c0b40302cc32271), | ||
522 | U64(0xdbcedad51fe17a8a), U64(0x740e8ae938dbdea0), | ||
523 | U64(0xa615c6dc549310ad), U64(0x19cc55f6171ae90b), | ||
524 | U64(0x49b1bdb8fe5fdd8d), U64(0xed0a89af2830e5bf), | ||
525 | U64(0x6a7aadb4f5a65bd6), U64(0x7e22972988f05679), | ||
526 | U64(0xf952b3325566e810), U64(0x39fecedadf61530e), | ||
527 | U64(0x6101c99f04f3c7ce), U64(0x2e5f7f6761b562ff), | ||
528 | U64(0xf08725d226cf5c97), U64(0x63af3b54860fef51), | ||
529 | U64(0x8ff2cb10ef411e2f), U64(0x884ab9bb35267252), | ||
530 | U64(0x4df04433e7ba8dae), U64(0x9afd8866d3690741), | ||
531 | U64(0x66b9bb34de94abb3), U64(0x9baaf18d92171380), | ||
532 | U64(0x543c11c5f0a064a5), U64(0x17a1b1bdbed431f1), | ||
533 | U64(0xb5f58eeaf3a2717f), U64(0xc355f6c849858740), | ||
534 | U64(0xec5df044694ef17e), U64(0xd83751f5dc6346d4), | ||
535 | U64(0xfc4433520dfdacf2), U64(0x0000000000000000), | ||
536 | U64(0x5a51f58e596ebc5f), U64(0x3285aaf12e34cf16), | ||
537 | U64(0x8d5c39db6dbd36b0), U64(0x12b731dde64f7513), | ||
538 | U64(0x94906c2d7aa7dfbb), U64(0x302b583aacc8e789), | ||
539 | U64(0x9d45facd090e6b3c), U64(0x2165e2c78905aec4), | ||
540 | U64(0x68d45f7f775a7349), U64(0x189b2c1d5664fdca), | ||
541 | U64(0xe1c99f2f030215da), U64(0x6983269436246788), | ||
542 | U64(0x8489af3b1e148237), U64(0xe94b702431d5b59c), | ||
543 | U64(0x33d2d31a6f4adbd7), U64(0xbfd9932a4389f9a6), | ||
544 | U64(0xb0e30e8aab39359d), U64(0xd1e2c715afcaf253), | ||
545 | U64(0x150f43763c28196e), U64(0xc4ed846393e2eb3d), | ||
546 | U64(0x03f98b20c3823c5e), U64(0xfd134ab94c83b833), | ||
547 | U64(0x556b682eb1de7064), U64(0x36c4537a37d19f35), | ||
548 | U64(0x7559f30279a5ca61), U64(0x799ae58252973a04), | ||
549 | U64(0x9c12832648707ffd), U64(0x78cd9c6913e92ec5), | ||
550 | U64(0x1d8dac7d0effb928), U64(0x439da0784e745554), | ||
551 | U64(0x413352b3cc887dcb), U64(0xbacf134a1b12bd44), | ||
552 | U64(0x114ebafd25cd494d), U64(0x2f08068c20cb763e), | ||
553 | U64(0x76a07822ba27f63f), U64(0xeab2fb04f25789c2), | ||
554 | U64(0xe3676de481fe3d45), U64(0x1b62a73d95e6c194), | ||
555 | U64(0x641749ff5c68832c), U64(0xa5ec4dfc97112cf3), | ||
556 | U64(0xf6682e92bdd6242b), U64(0x3f11c59a44782bb2), | ||
557 | U64(0x317c21d1edb6f348), U64(0xd65ab5be75ad9e2e), | ||
558 | U64(0x6b2dd45fb4d84f17), U64(0xfaab381296e4d44e), | ||
559 | U64(0xd0b5befeeeb4e692), U64(0x0882ef0b32d7a046), | ||
560 | U64(0x512a91a5a83b2047), U64(0x963e9ee6f85bf724), | ||
561 | U64(0x4e09cf132438b1f0), U64(0x77f701c9fb59e2fe), | ||
562 | U64(0x7ddb1c094b726a27), U64(0x5f4775ee01f5f8bd), | ||
563 | U64(0x9186ec4d223c9b59), U64(0xfeeac1998f01846d), | ||
564 | U64(0xac39db1ce4b89874), U64(0xb75b7c21715e59e0), | ||
565 | U64(0xafc0503c273aa42a), U64(0x6e3b543fec430bf5), | ||
566 | U64(0x704f7362213e8e83), U64(0x58ff0745db9294c0), | ||
567 | U64(0x67eec2df9feabf72), U64(0xa0facd9ccf8a6811), | ||
568 | U64(0xb936986ad890811a), U64(0x95c715c63bd9cb7a), | ||
569 | U64(0xca8060283a2c33c7), U64(0x507de84ee9453486), | ||
570 | U64(0x85ded6d05f6a96f6), U64(0x1cdad5964f81ade9), | ||
571 | U64(0xd5a33e9eb62fa270), U64(0x40642b588df6690a), | ||
572 | U64(0x7f75eec2c98e42b8), U64(0x2cf18dace3494a60), | ||
573 | U64(0x23cb100c0bf9865b), U64(0xeef3028febb2d9e1), | ||
574 | U64(0x4425d2d394133929), U64(0xaad6d05c7fa1e0c8), | ||
575 | U64(0xad6ea2f7a5c68cb5), U64(0xc2028f2308fb9381), | ||
576 | U64(0x819f2f5b468fc6d5), U64(0xc5bafd88d29cfffc), | ||
577 | U64(0x47dc59f357910577), U64(0x2b49ff07392e261d), | ||
578 | U64(0x57c59ae5332258fb), U64(0x73b6f842e2bcb2dd), | ||
579 | U64(0xcf96e04862b77725), U64(0x4ca73dd8a6c4996f), | ||
580 | U64(0x015779eb417e14c1), U64(0x37932a9176af8bf4) | ||
581 | }, { /* 4 */ | ||
582 | U64(0x190a2c9b249df23e), U64(0x2f62f8b62263e1e9), | ||
583 | U64(0x7a7f754740993655), U64(0x330b7ba4d5564d9f), | ||
584 | U64(0x4c17a16a46672582), U64(0xb22f08eb7d05f5b8), | ||
585 | U64(0x535f47f40bc148cc), U64(0x3aec5d27d4883037), | ||
586 | U64(0x10ed0a1825438f96), U64(0x516101f72c233d17), | ||
587 | U64(0x13cc6f949fd04eae), U64(0x739853c441474bfd), | ||
588 | U64(0x653793d90d3f5b1b), U64(0x5240647b96b0fc2f), | ||
589 | U64(0x0c84890ad27623e0), U64(0xd7189b32703aaea3), | ||
590 | U64(0x2685de3523bd9c41), U64(0x99317c5b11bffefa), | ||
591 | U64(0x0d9baa854f079703), U64(0x70b93648fbd48ac5), | ||
592 | U64(0xa80441fce30bc6be), U64(0x7287704bdc36ff1e), | ||
593 | U64(0xb65384ed33dc1f13), U64(0xd36417343ee34408), | ||
594 | U64(0x39cd38ab6e1bf10f), U64(0x5ab861770a1f3564), | ||
595 | U64(0x0ebacf09f594563b), U64(0xd04572b884708530), | ||
596 | U64(0x3cae9722bdb3af47), U64(0x4a556b6f2f5cbaf2), | ||
597 | U64(0xe1704f1f76c4bd74), U64(0x5ec4ed7144c6dfcf), | ||
598 | U64(0x16afc01d4c7810e6), U64(0x283f113cd629ca7a), | ||
599 | U64(0xaf59a8761741ed2d), U64(0xeed5a3991e215fac), | ||
600 | U64(0x3bf37ea849f984d4), U64(0xe413e096a56ce33c), | ||
601 | U64(0x2c439d3a98f020d1), U64(0x637559dc6404c46b), | ||
602 | U64(0x9e6c95d1e5f5d569), U64(0x24bb9836045fe99a), | ||
603 | U64(0x44efa466dac8ecc9), U64(0xc6eab2a5c80895d6), | ||
604 | U64(0x803b50c035220cc4), U64(0x0321658cba93c138), | ||
605 | U64(0x8f9ebc465dc7ee1c), U64(0xd15a5137190131d3), | ||
606 | U64(0x0fa5ec8668e5e2d8), U64(0x91c979578d1037b1), | ||
607 | U64(0x0642ca05693b9f70), U64(0xefca80168350eb4f), | ||
608 | U64(0x38d21b24f36a45ec), U64(0xbeab81e1af73d658), | ||
609 | U64(0x8cbfd9cae7542f24), U64(0xfd19cc0d81f11102), | ||
610 | U64(0x0ac6430fbb4dbc90), U64(0x1d76a09d6a441895), | ||
611 | U64(0x2a01573ff1cbbfa1), U64(0xb572e161894fde2b), | ||
612 | U64(0x8124734fa853b827), U64(0x614b1fdf43e6b1b0), | ||
613 | U64(0x68ac395c4238cc18), U64(0x21d837bfd7f7b7d2), | ||
614 | U64(0x20c714304a860331), U64(0x5cfaab726324aa14), | ||
615 | U64(0x74c5ba4eb50d606e), U64(0xf3a3030474654739), | ||
616 | U64(0x23e671bcf015c209), U64(0x45f087e947b9582a), | ||
617 | U64(0xd8bd77b418df4c7b), U64(0xe06f6c90ebb50997), | ||
618 | U64(0x0bd96080263c0873), U64(0x7e03f9410e40dcfe), | ||
619 | U64(0xb8e94be4c6484928), U64(0xfb5b0608e8ca8e72), | ||
620 | U64(0x1a2b49179e0e3306), U64(0x4e29e76961855059), | ||
621 | U64(0x4f36c4e6fcf4e4ba), U64(0x49740ee395cf7bca), | ||
622 | U64(0xc2963ea386d17f7d), U64(0x90d65ad810618352), | ||
623 | U64(0x12d34c1b02a1fa4d), U64(0xfa44258775bb3a91), | ||
624 | U64(0x18150f14b9ec46dd), U64(0x1491861e6b9a653d), | ||
625 | U64(0x9a1019d7ab2c3fc2), U64(0x3668d42d06fe13d7), | ||
626 | U64(0xdcc1fbb25606a6d0), U64(0x969490dd795a1c22), | ||
627 | U64(0x3549b1a1bc6dd2ef), U64(0xc94f5e23a0ed770e), | ||
628 | U64(0xb9f6686b5b39fdcb), U64(0xc4d4f4a6efeae00d), | ||
629 | U64(0xe732851a1fff2204), U64(0x94aad6de5eb869f9), | ||
630 | U64(0x3f8ff2ae07206e7f), U64(0xfe38a9813b62d03a), | ||
631 | U64(0xa7a1ad7a8bee2466), U64(0x7b6056c8dde882b6), | ||
632 | U64(0x302a1e286fc58ca7), U64(0x8da0fa457a259bc7), | ||
633 | U64(0xb3302b64e074415b), U64(0x5402ae7eff8b635f), | ||
634 | U64(0x08f8050c9cafc94b), U64(0xae468bf98a3059ce), | ||
635 | U64(0x88c355cca98dc58f), U64(0xb10e6d67c7963480), | ||
636 | U64(0xbad70de7e1aa3cf3), U64(0xbfb4a26e320262bb), | ||
637 | U64(0xcb711820870f02d5), U64(0xce12b7a954a75c9d), | ||
638 | U64(0x563ce87dd8691684), U64(0x9f73b65e7884618a), | ||
639 | U64(0x2b1e74b06cba0b42), U64(0x47cec1ea605b2df1), | ||
640 | U64(0x1c698312f735ac76), U64(0x5fdbcefed9b76b2c), | ||
641 | U64(0x831a354c8fb1cdfc), U64(0x820516c312c0791f), | ||
642 | U64(0xb74ca762aeadabf0), U64(0xfc06ef821c80a5e1), | ||
643 | U64(0x5723cbf24518a267), U64(0x9d4df05d5f661451), | ||
644 | U64(0x588627742dfd40bf), U64(0xda8331b73f3d39a0), | ||
645 | U64(0x17b0e392d109a405), U64(0xf965400bcf28fba9), | ||
646 | U64(0x7c3dbf4229a2a925), U64(0x023e460327e275db), | ||
647 | U64(0x6cd0b55a0ce126b3), U64(0xe62da695828e96e7), | ||
648 | U64(0x42ad6e63b3f373b9), U64(0xe50cc319381d57df), | ||
649 | U64(0xc5cbd729729b54ee), U64(0x46d1e265fd2a9912), | ||
650 | U64(0x6428b056904eeff8), U64(0x8be23040131e04b7), | ||
651 | U64(0x6709d5da2add2ec0), U64(0x075de98af44a2b93), | ||
652 | U64(0x8447dcc67bfbe66f), U64(0x6616f655b7ac9a23), | ||
653 | U64(0xd607b8bded4b1a40), U64(0x0563af89d3a85e48), | ||
654 | U64(0x3db1b4ad20c21ba4), U64(0x11f22997b8323b75), | ||
655 | U64(0x292032b34b587e99), U64(0x7f1cdace9331681d), | ||
656 | U64(0x8e819fc9c0b65aff), U64(0xa1e3677fe2d5bb16), | ||
657 | U64(0xcd33d225ee349da5), U64(0xd9a2543b85aef898), | ||
658 | U64(0x795e10cbfa0af76d), U64(0x25a4bbb9992e5d79), | ||
659 | U64(0x78413344677b438e), U64(0xf0826688cef68601), | ||
660 | U64(0xd27b34bba392f0eb), U64(0x551d8df162fad7bc), | ||
661 | U64(0x1e57c511d0d7d9ad), U64(0xdeffbdb171e4d30b), | ||
662 | U64(0xf4feea8e802f6caa), U64(0xa480c8f6317de55e), | ||
663 | U64(0xa0fc44f07fa40ff5), U64(0x95b5f551c3c9dd1a), | ||
664 | U64(0x22f952336d6476ea), U64(0x0000000000000000), | ||
665 | U64(0xa6be8ef5169f9085), U64(0xcc2cf1aa73452946), | ||
666 | U64(0x2e7ddb39bf12550a), U64(0xd526dd3157d8db78), | ||
667 | U64(0x486b2d6c08becf29), U64(0x9b0f3a58365d8b21), | ||
668 | U64(0xac78cdfaadd22c15), U64(0xbc95c7e28891a383), | ||
669 | U64(0x6a927f5f65dab9c3), U64(0xc3891d2c1ba0cb9e), | ||
670 | U64(0xeaa92f9f50f8b507), U64(0xcf0d9426c9d6e87e), | ||
671 | U64(0xca6e3baf1a7eb636), U64(0xab25247059980786), | ||
672 | U64(0x69b31ad3df4978fb), U64(0xe2512a93cc577c4c), | ||
673 | U64(0xff278a0ea61364d9), U64(0x71a615c766a53e26), | ||
674 | U64(0x89dc764334fc716c), U64(0xf87a638452594f4a), | ||
675 | U64(0xf2bc208be914f3da), U64(0x8766b94ac1682757), | ||
676 | U64(0xbbc82e687cdb8810), U64(0x626a7a53f9757088), | ||
677 | U64(0xa2c202f358467a2e), U64(0x4d0882e5db169161), | ||
678 | U64(0x09e7268301de7da8), U64(0xe897699c771ac0dc), | ||
679 | U64(0xc8507dac3d9cc3ed), U64(0xc0a878a0a1330aa6), | ||
680 | U64(0x978bb352e42ba8c1), U64(0xe9884a13ea6b743f), | ||
681 | U64(0x279afdbabecc28a2), U64(0x047c8c064ed9eaab), | ||
682 | U64(0x507e2278b15289f4), U64(0x599904fbb08cf45c), | ||
683 | U64(0xbd8ae46d15e01760), U64(0x31353da7f2b43844), | ||
684 | U64(0x8558ff49e68a528c), U64(0x76fbfc4d92ef15b5), | ||
685 | U64(0x3456922e211c660c), U64(0x86799ac55c1993b4), | ||
686 | U64(0x3e90d1219a51da9c), U64(0x2d5cbeb505819432), | ||
687 | U64(0x982e5fd48cce4a19), U64(0xdb9c1238a24c8d43), | ||
688 | U64(0xd439febecaa96f9b), U64(0x418c0bef0960b281), | ||
689 | U64(0x158ea591f6ebd1de), U64(0x1f48e69e4da66d4e), | ||
690 | U64(0x8afd13cf8e6fb054), U64(0xf5e1c9011d5ed849), | ||
691 | U64(0xe34e091c5126c8af), U64(0xad67ee7530a398f6), | ||
692 | U64(0x43b24dec2e82c75a), U64(0x75da99c1287cd48d), | ||
693 | U64(0x92e81cdb3783f689), U64(0xa3dd217cc537cecd), | ||
694 | U64(0x60543c50de970553), U64(0x93f73f54aaf2426a), | ||
695 | U64(0xa91b62737e7a725d), U64(0xf19d4507538732e2), | ||
696 | U64(0x77e4dfc20f9ea156), U64(0x7d229ccdb4d31dc6), | ||
697 | U64(0x1b346a98037f87e5), U64(0xedf4c615a4b29e94), | ||
698 | U64(0x4093286094110662), U64(0xb0114ee85ae78063), | ||
699 | U64(0x6ff1d0d6b672e78b), U64(0x6dcf96d591909250), | ||
700 | U64(0xdfe09e3eec9567e8), U64(0x3214582b4827f97c), | ||
701 | U64(0xb46dc2ee143e6ac8), U64(0xf6c0ac8da7cd1971), | ||
702 | U64(0xebb60c10cd8901e4), U64(0xf7df8f023abcad92), | ||
703 | U64(0x9c52d3d2c217a0b2), U64(0x6b8d5cd0f8ab0d20), | ||
704 | U64(0x3777f7a29b8fa734), U64(0x011f238f9d71b4e3), | ||
705 | U64(0xc1b75b2f3c42be45), U64(0x5de588fdfe551ef7), | ||
706 | U64(0x6eeef3592b035368), U64(0xaa3a07ffc4e9b365), | ||
707 | U64(0xecebe59a39c32a77), U64(0x5ba742f8976e8187), | ||
708 | U64(0x4b4a48e0b22d0e11), U64(0xddded83dcb771233), | ||
709 | U64(0xa59feb79ac0c51bd), U64(0xc7f5912a55792135) | ||
710 | }, { /* 5 */ | ||
711 | U64(0x6d6ae04668a9b08a), U64(0x3ab3f04b0be8c743), | ||
712 | U64(0xe51e166b54b3c908), U64(0xbe90a9eb35c2f139), | ||
713 | U64(0xb2c7066637f2bec1), U64(0xaa6945613392202c), | ||
714 | U64(0x9a28c36f3b5201eb), U64(0xddce5a93ab536994), | ||
715 | U64(0x0e34133ef6382827), U64(0x52a02ba1ec55048b), | ||
716 | U64(0xa2f88f97c4b2a177), U64(0x8640e513ca2251a5), | ||
717 | U64(0xcdf1d36258137622), U64(0xfe6cb708dedf8ddb), | ||
718 | U64(0x8a174a9ec8121e5d), U64(0x679896036b81560e), | ||
719 | U64(0x59ed033395795fee), U64(0x1dd778ab8b74edaf), | ||
720 | U64(0xee533ef92d9f926d), U64(0x2a8c79baf8a8d8f5), | ||
721 | U64(0x6bcf398e69b119f6), U64(0xe20491742fafdd95), | ||
722 | U64(0x276488e0809c2aec), U64(0xea955b82d88f5cce), | ||
723 | U64(0x7102c63a99d9e0c4), U64(0xf9763017a5c39946), | ||
724 | U64(0x429fa2501f151b3d), U64(0x4659c72bea05d59e), | ||
725 | U64(0x984b7fdccf5a6634), U64(0xf742232953fbb161), | ||
726 | U64(0x3041860e08c021c7), U64(0x747bfd9616cd9386), | ||
727 | U64(0x4bb1367192312787), U64(0x1b72a1638a6c44d3), | ||
728 | U64(0x4a0e68a6e8359a66), U64(0x169a5039f258b6ca), | ||
729 | U64(0xb98a2ef44edee5a4), U64(0xd9083fe85e43a737), | ||
730 | U64(0x967f6ce239624e13), U64(0x8874f62d3c1a7982), | ||
731 | U64(0x3c1629830af06e3f), U64(0x9165ebfd427e5a8e), | ||
732 | U64(0xb5dd81794ceeaa5c), U64(0x0de8f15a7834f219), | ||
733 | U64(0x70bd98ede3dd5d25), U64(0xaccc9ca9328a8950), | ||
734 | U64(0x56664eda1945ca28), U64(0x221db34c0f8859ae), | ||
735 | U64(0x26dbd637fa98970d), U64(0x1acdffb4f068f932), | ||
736 | U64(0x4585254f64090fa0), U64(0x72de245e17d53afa), | ||
737 | U64(0x1546b25d7c546cf4), U64(0x207e0ffffb803e71), | ||
738 | U64(0xfaaad2732bcf4378), U64(0xb462dfae36ea17bd), | ||
739 | U64(0xcf926fd1ac1b11fd), U64(0xe0672dc7dba7ba4a), | ||
740 | U64(0xd3fa49ad5d6b41b3), U64(0x8ba81449b216a3bc), | ||
741 | U64(0x14f9ec8a0650d115), U64(0x40fc1ee3eb1d7ce2), | ||
742 | U64(0x23a2ed9b758ce44f), U64(0x782c521b14fddc7e), | ||
743 | U64(0x1c68267cf170504e), U64(0xbcf31558c1ca96e6), | ||
744 | U64(0xa781b43b4ba6d235), U64(0xf6fd7dfe29ff0c80), | ||
745 | U64(0xb0a4bad5c3fad91e), U64(0xd199f51ea963266c), | ||
746 | U64(0x414340349119c103), U64(0x5405f269ed4dadf7), | ||
747 | U64(0xabd61bb649969dcd), U64(0x6813dbeae7bdc3c8), | ||
748 | U64(0x65fb2ab09f8931d1), U64(0xf1e7fae152e3181d), | ||
749 | U64(0xc1a67cef5a2339da), U64(0x7a4feea8e0f5bba1), | ||
750 | U64(0x1e0b9acf05783791), U64(0x5b8ebf8061713831), | ||
751 | U64(0x80e53cdbcb3af8d9), U64(0x7e898bd315e57502), | ||
752 | U64(0xc6bcfbf0213f2d47), U64(0x95a38e86b76e942d), | ||
753 | U64(0x092e94218d243cba), U64(0x8339debf453622e7), | ||
754 | U64(0xb11be402b9fe64ff), U64(0x57d9100d634177c9), | ||
755 | U64(0xcc4e8db52217cbc3), U64(0x3b0cae9c71ec7aa2), | ||
756 | U64(0xfb158ca451cbfe99), U64(0x2b33276d82ac6514), | ||
757 | U64(0x01bf5ed77a04bde1), U64(0xc5601994af33f779), | ||
758 | U64(0x75c4a3416cc92e67), U64(0xf3844652a6eb7fc2), | ||
759 | U64(0x3487e375fdd0ef64), U64(0x18ae430704609eed), | ||
760 | U64(0x4d14efb993298efb), U64(0x815a620cb13e4538), | ||
761 | U64(0x125c354207487869), U64(0x9eeea614ce42cf48), | ||
762 | U64(0xce2d3106d61fac1c), U64(0xbbe99247bad6827b), | ||
763 | U64(0x071a871f7b1c149d), U64(0x2e4a1cc10db81656), | ||
764 | U64(0x77a71ff298c149b8), U64(0x06a5d9c80118a97c), | ||
765 | U64(0xad73c27e488e34b1), U64(0x443a7b981e0db241), | ||
766 | U64(0xe3bbcfa355ab6074), U64(0x0af276450328e684), | ||
767 | U64(0x73617a896dd1871b), U64(0x58525de4ef7de20f), | ||
768 | U64(0xb7be3dcab8e6cd83), U64(0x19111dd07e64230c), | ||
769 | U64(0x842359a03e2a367a), U64(0x103f89f1f3401fb6), | ||
770 | U64(0xdc710444d157d475), U64(0xb835702334da5845), | ||
771 | U64(0x4320fc876511a6dc), U64(0xd026abc9d3679b8d), | ||
772 | U64(0x17250eee885c0b2b), U64(0x90dab52a387ae76f), | ||
773 | U64(0x31fed8d972c49c26), U64(0x89cba8fa461ec463), | ||
774 | U64(0x2ff5421677bcabb7), U64(0x396f122f85e41d7d), | ||
775 | U64(0xa09b332430bac6a8), U64(0xc888e8ced7070560), | ||
776 | U64(0xaeaf201ac682ee8f), U64(0x1180d7268944a257), | ||
777 | U64(0xf058a43628e7a5fc), U64(0xbd4c4b8fbbce2b07), | ||
778 | U64(0xa1246df34abe7b49), U64(0x7d5569b79be9af3c), | ||
779 | U64(0xa9b5a705bd9efa12), U64(0xdb6b835baa4bc0e8), | ||
780 | U64(0x05793bac8f147342), U64(0x21c1512881848390), | ||
781 | U64(0xfdb0556c50d357e5), U64(0x613d4fcb6a99ff72), | ||
782 | U64(0x03dce2648e0cda3e), U64(0xe949b9e6568386f0), | ||
783 | U64(0xfc0f0bbb2ad7ea04), U64(0x6a70675913b5a417), | ||
784 | U64(0x7f36d5046fe1c8e3), U64(0x0c57af8d02304ff8), | ||
785 | U64(0x32223abdfcc84618), U64(0x0891caf6f720815b), | ||
786 | U64(0xa63eeaec31a26fd4), U64(0x2507345374944d33), | ||
787 | U64(0x49d28ac266394058), U64(0xf5219f9aa7f3d6be), | ||
788 | U64(0x2d96fea583b4cc68), U64(0x5a31e1571b7585d0), | ||
789 | U64(0x8ed12fe53d02d0fe), U64(0xdfade6205f5b0e4b), | ||
790 | U64(0x4cabb16ee92d331a), U64(0x04c6657bf510cea3), | ||
791 | U64(0xd73c2cd6a87b8f10), U64(0xe1d87310a1a307ab), | ||
792 | U64(0x6cd5be9112ad0d6b), U64(0x97c032354366f3f2), | ||
793 | U64(0xd4e0ceb22677552e), U64(0x0000000000000000), | ||
794 | U64(0x29509bde76a402cb), U64(0xc27a9e8bd42fe3e4), | ||
795 | U64(0x5ef7842cee654b73), U64(0xaf107ecdbc86536e), | ||
796 | U64(0x3fcacbe784fcb401), U64(0xd55f90655c73e8cf), | ||
797 | U64(0xe6c2f40fdabf1336), U64(0xe8f6e7312c873b11), | ||
798 | U64(0xeb2a0555a28be12f), U64(0xe4a148bc2eb774e9), | ||
799 | U64(0x9b979db84156bc0a), U64(0x6eb60222e6a56ab4), | ||
800 | U64(0x87ffbbc4b026ec44), U64(0xc703a5275b3b90a6), | ||
801 | U64(0x47e699fc9001687f), U64(0x9c8d1aa73a4aa897), | ||
802 | U64(0x7cea3760e1ed12dd), U64(0x4ec80ddd1d2554c5), | ||
803 | U64(0x13e36b957d4cc588), U64(0x5d2b66486069914d), | ||
804 | U64(0x92b90999cc7280b0), U64(0x517cc9c56259deb5), | ||
805 | U64(0xc937b619ad03b881), U64(0xec30824ad997f5b2), | ||
806 | U64(0xa45d565fc5aa080b), U64(0xd6837201d27f32f1), | ||
807 | U64(0x635ef3789e9198ad), U64(0x531f75769651b96a), | ||
808 | U64(0x4f77530a6721e924), U64(0x486dd4151c3dfdb9), | ||
809 | U64(0x5f48dafb9461f692), U64(0x375b011173dc355a), | ||
810 | U64(0x3da9775470f4d3de), U64(0x8d0dcd81b30e0ac0), | ||
811 | U64(0x36e45fc609d888bb), U64(0x55baacbe97491016), | ||
812 | U64(0x8cb29356c90ab721), U64(0x76184125e2c5f459), | ||
813 | U64(0x99f4210bb55edbd5), U64(0x6f095cf59ca1d755), | ||
814 | U64(0x9f51f8c3b44672a9), U64(0x3538bda287d45285), | ||
815 | U64(0x50c39712185d6354), U64(0xf23b1885dcefc223), | ||
816 | U64(0x79930ccc6ef9619f), U64(0xed8fdc9da3934853), | ||
817 | U64(0xcb540aaa590bdf5e), U64(0x5c94389f1a6d2cac), | ||
818 | U64(0xe77daad8a0bbaed7), U64(0x28efc5090ca0bf2a), | ||
819 | U64(0xbf2ff73c4fc64cd8), U64(0xb37858b14df60320), | ||
820 | U64(0xf8c96ec0dfc724a7), U64(0x828680683f329f06), | ||
821 | U64(0x941cd051cd6a29cc), U64(0xc3c5c05cae2b5e05), | ||
822 | U64(0xb601631dc2e27062), U64(0xc01922382027843b), | ||
823 | U64(0x24b86a840e90f0d2), U64(0xd245177a276ffc52), | ||
824 | U64(0x0f8b4de98c3c95c6), U64(0x3e759530fef809e0), | ||
825 | U64(0x0b4d2892792c5b65), U64(0xc4df4743d5374a98), | ||
826 | U64(0xa5e20888bfaeb5ea), U64(0xba56cc90c0d23f9a), | ||
827 | U64(0x38d04cf8ffe0a09c), U64(0x62e1adafe495254c), | ||
828 | U64(0x0263bcb3f40867df), U64(0xcaeb547d230f62bf), | ||
829 | U64(0x6082111c109d4293), U64(0xdad4dd8cd04f7d09), | ||
830 | U64(0xefec602e579b2f8c), U64(0x1fb4c4187f7c8a70), | ||
831 | U64(0xffd3e9dfa4db303a), U64(0x7bf0b07f9af10640), | ||
832 | U64(0xf49ec14dddf76b5f), U64(0x8f6e713247066d1f), | ||
833 | U64(0x339d646a86ccfbf9), U64(0x64447467e58d8c30), | ||
834 | U64(0x2c29a072f9b07189), U64(0xd8b7613f24471ad6), | ||
835 | U64(0x6627c8d41185ebef), U64(0xa347d140beb61c96), | ||
836 | U64(0xde12b8f7255fb3aa), U64(0x9d324470404e1576), | ||
837 | U64(0x9306574eb6763d51), U64(0xa80af9d2c79a47f3), | ||
838 | U64(0x859c0777442e8b9b), U64(0x69ac853d9db97e29) | ||
839 | }, { /* 6 */ | ||
840 | U64(0xc3407dfc2de6377e), U64(0x5b9e93eea4256f77), | ||
841 | U64(0xadb58fdd50c845e0), U64(0x5219ff11a75bed86), | ||
842 | U64(0x356b61cfd90b1de9), U64(0xfb8f406e25abe037), | ||
843 | U64(0x7a5a0231c0f60796), U64(0x9d3cd216e1f5020b), | ||
844 | U64(0x0c6550fb6b48d8f3), U64(0xf57508c427ff1c62), | ||
845 | U64(0x4ad35ffa71cb407d), U64(0x6290a2da1666aa6d), | ||
846 | U64(0xe284ec2349355f9f), U64(0xb3c307c53d7c84ec), | ||
847 | U64(0x05e23c0468365a02), U64(0x190bac4d6c9ebfa8), | ||
848 | U64(0x94bbbee9e28b80fa), U64(0xa34fc777529cb9b5), | ||
849 | U64(0xcc7b39f095bcd978), U64(0x2426addb0ce532e3), | ||
850 | U64(0x7e79329312ce4fc7), U64(0xab09a72eebec2917), | ||
851 | U64(0xf8d15499f6b9d6c2), U64(0x1a55b8babf8c895d), | ||
852 | U64(0xdb8add17fb769a85), U64(0xb57f2f368658e81b), | ||
853 | U64(0x8acd36f18f3f41f6), U64(0x5ce3b7bba50f11d3), | ||
854 | U64(0x114dcc14d5ee2f0a), U64(0xb91a7fcded1030e8), | ||
855 | U64(0x81d5425fe55de7a1), U64(0xb6213bc1554adeee), | ||
856 | U64(0x80144ef95f53f5f2), U64(0x1e7688186db4c10c), | ||
857 | U64(0x3b912965db5fe1bc), U64(0xc281715a97e8252d), | ||
858 | U64(0x54a5d7e21c7f8171), U64(0x4b12535ccbc5522e), | ||
859 | U64(0x1d289cefbea6f7f9), U64(0x6ef5f2217d2e729e), | ||
860 | U64(0xe6a7dc819b0d17ce), U64(0x1b94b41c05829b0e), | ||
861 | U64(0x33d7493c622f711e), U64(0xdcf7f942fa5ce421), | ||
862 | U64(0x600fba8b7f7a8ecb), U64(0x46b60f011a83988e), | ||
863 | U64(0x235b898e0dcf4c47), U64(0x957ab24f588592a9), | ||
864 | U64(0x4354330572b5c28c), U64(0xa5f3ef84e9b8d542), | ||
865 | U64(0x8c711e02341b2d01), U64(0x0b1874ae6a62a657), | ||
866 | U64(0x1213d8e306fc19ff), U64(0xfe6d7c6a4d9dba35), | ||
867 | U64(0x65ed868f174cd4c9), U64(0x88522ea0e6236550), | ||
868 | U64(0x899322065c2d7703), U64(0xc01e690bfef4018b), | ||
869 | U64(0x915982ed8abddaf8), U64(0xbe675b98ec3a4e4c), | ||
870 | U64(0xa996bf7f82f00db1), U64(0xe1daf8d49a27696a), | ||
871 | U64(0x2effd5d3dc8986e7), U64(0xd153a51f2b1a2e81), | ||
872 | U64(0x18caa0ebd690adfb), U64(0x390e3134b243c51a), | ||
873 | U64(0x2778b92cdff70416), U64(0x029f1851691c24a6), | ||
874 | U64(0x5e7cafeacc133575), U64(0xfa4e4cc89fa5f264), | ||
875 | U64(0x5a5f9f481e2b7d24), U64(0x484c47ab18d764db), | ||
876 | U64(0x400a27f2a1a7f479), U64(0xaeeb9b2a83da7315), | ||
877 | U64(0x721c626879869734), U64(0x042330a2d2384851), | ||
878 | U64(0x85f672fd3765aff0), U64(0xba446b3a3e02061d), | ||
879 | U64(0x73dd6ecec3888567), U64(0xffac70ccf793a866), | ||
880 | U64(0xdfa9edb5294ed2d4), U64(0x6c6aea7014325638), | ||
881 | U64(0x834a5a0e8c41c307), U64(0xcdba35562fb2cb2b), | ||
882 | U64(0x0ad97808d06cb404), U64(0x0f3b440cb85aee06), | ||
883 | U64(0xe5f9c876481f213b), U64(0x98deee1289c35809), | ||
884 | U64(0x59018bbfcd394bd1), U64(0xe01bf47220297b39), | ||
885 | U64(0xde68e1139340c087), U64(0x9fa3ca4788e926ad), | ||
886 | U64(0xbb85679c840c144e), U64(0x53d8f3b71d55ffd5), | ||
887 | U64(0x0da45c5dd146caa0), U64(0x6f34fe87c72060cd), | ||
888 | U64(0x57fbc315cf6db784), U64(0xcee421a1fca0fdde), | ||
889 | U64(0x3d2d0196607b8d4b), U64(0x642c8a29ad42c69a), | ||
890 | U64(0x14aff010bdd87508), U64(0xac74837beac657b3), | ||
891 | U64(0x3216459ad821634d), U64(0x3fb219c70967a9ed), | ||
892 | U64(0x06bc28f3bb246cf7), U64(0xf2082c9126d562c6), | ||
893 | U64(0x66b39278c45ee23c), U64(0xbd394f6f3f2878b9), | ||
894 | U64(0xfd33689d9e8f8cc0), U64(0x37f4799eb017394f), | ||
895 | U64(0x108cc0b26fe03d59), U64(0xda4bd1b1417888d6), | ||
896 | U64(0xb09d1332ee6eb219), U64(0x2f3ed975668794b4), | ||
897 | U64(0x58c0871977375982), U64(0x7561463d78ace990), | ||
898 | U64(0x09876cff037e82f1), U64(0x7fb83e35a8c05d94), | ||
899 | U64(0x26b9b58a65f91645), U64(0xef20b07e9873953f), | ||
900 | U64(0x3148516d0b3355b8), U64(0x41cb2b541ba9e62a), | ||
901 | U64(0x790416c613e43163), U64(0xa011d380818e8f40), | ||
902 | U64(0x3a5025c36151f3ef), U64(0xd57095bdf92266d0), | ||
903 | U64(0x498d4b0da2d97688), U64(0x8b0c3a57353153a5), | ||
904 | U64(0x21c491df64d368e1), U64(0x8f2f0af5e7091bf4), | ||
905 | U64(0x2da1c1240f9bb012), U64(0xc43d59a92ccc49da), | ||
906 | U64(0xbfa6573e56345c1f), U64(0x828b56a8364fd154), | ||
907 | U64(0x9a41f643e0df7caf), U64(0xbcf843c985266aea), | ||
908 | U64(0x2b1de9d7b4bfdce5), U64(0x20059d79dedd7ab2), | ||
909 | U64(0x6dabe6d6ae3c446b), U64(0x45e81bf6c991ae7b), | ||
910 | U64(0x6351ae7cac68b83e), U64(0xa432e32253b6c711), | ||
911 | U64(0xd092a9b991143cd2), U64(0xcac711032e98b58f), | ||
912 | U64(0xd8d4c9e02864ac70), U64(0xc5fc550f96c25b89), | ||
913 | U64(0xd7ef8dec903e4276), U64(0x67729ede7e50f06f), | ||
914 | U64(0xeac28c7af045cf3d), U64(0xb15c1f945460a04a), | ||
915 | U64(0x9cfddeb05bfb1058), U64(0x93c69abce3a1fe5e), | ||
916 | U64(0xeb0380dc4a4bdd6e), U64(0xd20db1e8f8081874), | ||
917 | U64(0x229a8528b7c15e14), U64(0x44291750739fbc28), | ||
918 | U64(0xd3ccbd4e42060a27), U64(0xf62b1c33f4ed2a97), | ||
919 | U64(0x86a8660ae4779905), U64(0xd62e814a2a305025), | ||
920 | U64(0x477703a7a08d8add), U64(0x7b9b0e977af815c5), | ||
921 | U64(0x78c51a60a9ea2330), U64(0xa6adfb733aaae3b7), | ||
922 | U64(0x97e5aa1e3199b60f), U64(0x0000000000000000), | ||
923 | U64(0xf4b404629df10e31), U64(0x5564db44a6719322), | ||
924 | U64(0x9207961a59afec0d), U64(0x9624a6b88b97a45c), | ||
925 | U64(0x363575380a192b1c), U64(0x2c60cd82b595a241), | ||
926 | U64(0x7d272664c1dc7932), U64(0x7142769faa94a1c1), | ||
927 | U64(0xa1d0df263b809d13), U64(0x1630e841d4c451ae), | ||
928 | U64(0xc1df65ad44fa13d8), U64(0x13d2d445bcf20bac), | ||
929 | U64(0xd915c546926abe23), U64(0x38cf3d92084dd749), | ||
930 | U64(0xe766d0272103059d), U64(0xc7634d5effde7f2f), | ||
931 | U64(0x077d2455012a7ea4), U64(0xedbfa82ff16fb199), | ||
932 | U64(0xaf2a978c39d46146), U64(0x42953fa3c8bbd0df), | ||
933 | U64(0xcb061da59496a7dc), U64(0x25e7a17db6eb20b0), | ||
934 | U64(0x34aa6d6963050fba), U64(0xa76cf7d580a4f1e4), | ||
935 | U64(0xf7ea10954ee338c4), U64(0xfcf2643b24819e93), | ||
936 | U64(0xcf252d0746aeef8d), U64(0x4ef06f58a3f3082c), | ||
937 | U64(0x563acfb37563a5d7), U64(0x5086e740ce47c920), | ||
938 | U64(0x2982f186dda3f843), U64(0x87696aac5e798b56), | ||
939 | U64(0x5d22bb1d1f010380), U64(0x035e14f7d31236f5), | ||
940 | U64(0x3cec0d30da759f18), U64(0xf3c920379cdb7095), | ||
941 | U64(0xb8db736b571e22bb), U64(0xdd36f5e44052f672), | ||
942 | U64(0xaac8ab8851e23b44), U64(0xa857b3d938fe1fe2), | ||
943 | U64(0x17f1e4e76eca43fd), U64(0xec7ea4894b61a3ca), | ||
944 | U64(0x9e62c6e132e734fe), U64(0xd4b1991b432c7483), | ||
945 | U64(0x6ad6c283af163acf), U64(0x1ce9904904a8e5aa), | ||
946 | U64(0x5fbda34c761d2726), U64(0xf910583f4cb7c491), | ||
947 | U64(0xc6a241f845d06d7c), U64(0x4f3163fe19fd1a7f), | ||
948 | U64(0xe99c988d2357f9c8), U64(0x8eee06535d0709a7), | ||
949 | U64(0x0efa48aa0254fc55), U64(0xb4be23903c56fa48), | ||
950 | U64(0x763f52caabbedf65), U64(0xeee1bcd8227d876c), | ||
951 | U64(0xe345e085f33b4dcc), U64(0x3e731561b369bbbe), | ||
952 | U64(0x2843fd2067adea10), U64(0x2adce5710eb1ceb6), | ||
953 | U64(0xb7e03767ef44ccbd), U64(0x8db012a48e153f52), | ||
954 | U64(0x61ceb62dc5749c98), U64(0xe85d942b9959eb9b), | ||
955 | U64(0x4c6f7709caef2c8a), U64(0x84377e5b8d6bbda3), | ||
956 | U64(0x30895dcbb13d47eb), U64(0x74a04a9bc2a2fbc3), | ||
957 | U64(0x6b17ce251518289c), U64(0xe438c4d0f2113368), | ||
958 | U64(0x1fb784bed7bad35f), U64(0x9b80fae55ad16efc), | ||
959 | U64(0x77fe5e6c11b0cd36), U64(0xc858095247849129), | ||
960 | U64(0x08466059b97090a2), U64(0x01c10ca6ba0e1253), | ||
961 | U64(0x6988d6747c040c3a), U64(0x6849dad2c60a1e69), | ||
962 | U64(0x5147ebe67449db73), U64(0xc99905f4fd8a837a), | ||
963 | U64(0x991fe2b433cd4a5a), U64(0xf09734c04fc94660), | ||
964 | U64(0xa28ecbd1e892abe6), U64(0xf1563866f5c75433), | ||
965 | U64(0x4dae7baf70e13ed9), U64(0x7ce62ac27bd26b61), | ||
966 | U64(0x70837a39109ab392), U64(0x90988e4b30b3c8ab), | ||
967 | U64(0xb2020b63877296bf), U64(0x156efcb607d6675b) | ||
968 | }, { /* 7 */ | ||
969 | U64(0xe63f55ce97c331d0), U64(0x25b506b0015bba16), | ||
970 | U64(0xc8706e29e6ad9ba8), U64(0x5b43d3775d521f6a), | ||
971 | U64(0x0bfa3d577035106e), U64(0xab95fc172afb0e66), | ||
972 | U64(0xf64b63979e7a3276), U64(0xf58b4562649dad4b), | ||
973 | U64(0x48f7c3dbae0c83f1), U64(0xff31916642f5c8c5), | ||
974 | U64(0xcbb048dc1c4a0495), U64(0x66b8f83cdf622989), | ||
975 | U64(0x35c130e908e2b9b0), U64(0x7c761a61f0b34fa1), | ||
976 | U64(0x3601161cf205268d), U64(0x9e54ccfe2219b7d6), | ||
977 | U64(0x8b7d90a538940837), U64(0x9cd403588ea35d0b), | ||
978 | U64(0xbc3c6fea9ccc5b5a), U64(0xe5ff733b6d24aeed), | ||
979 | U64(0xceed22de0f7eb8d2), U64(0xec8581cab1ab545e), | ||
980 | U64(0xb96105e88ff8e71d), U64(0x8ca03501871a5ead), | ||
981 | U64(0x76ccce65d6db2a2f), U64(0x5883f582a7b58057), | ||
982 | U64(0x3f7be4ed2e8adc3e), U64(0x0fe7be06355cd9c9), | ||
983 | U64(0xee054e6c1d11be83), U64(0x1074365909b903a6), | ||
984 | U64(0x5dde9f80b4813c10), U64(0x4a770c7d02b6692c), | ||
985 | U64(0x5379c8d5d7809039), U64(0xb4067448161ed409), | ||
986 | U64(0x5f5e5026183bd6cd), U64(0xe898029bf4c29df9), | ||
987 | U64(0x7fb63c940a54d09c), U64(0xc5171f897f4ba8bc), | ||
988 | U64(0xa6f28db7b31d3d72), U64(0x2e4f3be7716eaa78), | ||
989 | U64(0x0d6771a099e63314), U64(0x82076254e41bf284), | ||
990 | U64(0x2f0fd2b42733df98), U64(0x5c9e76d3e2dc49f0), | ||
991 | U64(0x7aeb569619606cdb), U64(0x83478b07b2468764), | ||
992 | U64(0xcfadcb8d5923cd32), U64(0x85dac7f05b95a41e), | ||
993 | U64(0xb5469d1b4043a1e9), U64(0xb821ecbbd9a592fd), | ||
994 | U64(0x1b8e0b0e798c13c8), U64(0x62a57b6d9a0be02e), | ||
995 | U64(0xfcf1b793b81257f8), U64(0x9d94ea0bd8fe28eb), | ||
996 | U64(0x4cea408aeb654a56), U64(0x23284a47e888996c), | ||
997 | U64(0x2d8f1d128b893545), U64(0xf4cbac3132c0d8ab), | ||
998 | U64(0xbd7c86b9ca912eba), U64(0x3a268eef3dbe6079), | ||
999 | U64(0xf0d62f6077a9110c), U64(0x2735c916ade150cb), | ||
1000 | U64(0x89fd5f03942ee2ea), U64(0x1acee25d2fd16628), | ||
1001 | U64(0x90f39bab41181bff), U64(0x430dfe8cde39939f), | ||
1002 | U64(0xf70b8ac4c8274796), U64(0x1c53aeaac6024552), | ||
1003 | U64(0x13b410acf35e9c9b), U64(0xa532ab4249faa24f), | ||
1004 | U64(0x2b1251e5625a163f), U64(0xd7e3e676da4841c7), | ||
1005 | U64(0xa7b264e4e5404892), U64(0xda8497d643ae72d3), | ||
1006 | U64(0x861ae105a1723b23), U64(0x38a6414991048aa4), | ||
1007 | U64(0x6578dec92585b6b4), U64(0x0280cfa6acbaeadd), | ||
1008 | U64(0x88bdb650c273970a), U64(0x9333bd5ebbff84c2), | ||
1009 | U64(0x4e6a8f2c47dfa08b), U64(0x321c954db76cef2a), | ||
1010 | U64(0x418d312a72837942), U64(0xb29b38bfffcdf773), | ||
1011 | U64(0x6c022c38f90a4c07), U64(0x5a033a240b0f6a8a), | ||
1012 | U64(0x1f93885f3ce5da6f), U64(0xc38a537e96988bc6), | ||
1013 | U64(0x39e6a81ac759ff44), U64(0x29929e43cee0fce2), | ||
1014 | U64(0x40cdd87924de0ca2), U64(0xe9d8ebc8a29fe819), | ||
1015 | U64(0x0c2798f3cfbb46f4), U64(0x55e484223e53b343), | ||
1016 | U64(0x4650948ecd0d2fd8), U64(0x20e86cb2126f0651), | ||
1017 | U64(0x6d42c56baf5739e7), U64(0xa06fc1405ace1e08), | ||
1018 | U64(0x7babbfc54f3d193b), U64(0x424d17df8864e67f), | ||
1019 | U64(0xd8045870ef14980e), U64(0xc6d7397c85ac3781), | ||
1020 | U64(0x21a885e1443273b1), U64(0x67f8116f893f5c69), | ||
1021 | U64(0x24f5efe35706cff6), U64(0xd56329d076f2ab1a), | ||
1022 | U64(0x5e1eb9754e66a32d), U64(0x28d2771098bd8902), | ||
1023 | U64(0x8f6013f47dfdc190), U64(0x17a993fdb637553c), | ||
1024 | U64(0xe0a219397e1012aa), U64(0x786b9930b5da8606), | ||
1025 | U64(0x6e82e39e55b0a6da), U64(0x875a0856f72f4ec3), | ||
1026 | U64(0x3741ff4fa458536d), U64(0xac4859b3957558fc), | ||
1027 | U64(0x7ef6d5c75c09a57c), U64(0xc04a758b6c7f14fb), | ||
1028 | U64(0xf9acdd91ab26ebbf), U64(0x7391a467c5ef9668), | ||
1029 | U64(0x335c7c1ee1319aca), U64(0xa91533b18641e4bb), | ||
1030 | U64(0xe4bf9a683b79db0d), U64(0x8e20faa72ba0b470), | ||
1031 | U64(0x51f907737b3a7ae4), U64(0x2268a314bed5ec8c), | ||
1032 | U64(0xd944b123b949edee), U64(0x31dcb3b84d8b7017), | ||
1033 | U64(0xd3fe65279f218860), U64(0x097af2f1dc8ffab3), | ||
1034 | U64(0x9b09a6fc312d0b91), U64(0xcc6ded78a3c4520f), | ||
1035 | U64(0x3481d9ba5ebfcc50), U64(0x4f2a667f1182d56b), | ||
1036 | U64(0xdfd9fdd4509ace94), U64(0x26752045fbbc252b), | ||
1037 | U64(0xbffc491f662bc467), U64(0xdd593272fc202449), | ||
1038 | U64(0x3cbbc218d46d4303), U64(0x91b372f817456e1f), | ||
1039 | U64(0x681faf69bc6385a0), U64(0xb686bbeebaa43ed4), | ||
1040 | U64(0x1469b5084cd0ca01), U64(0x98c98009cbca94ac), | ||
1041 | U64(0x6438379a73d8c354), U64(0xc2caba2dc0c5fe26), | ||
1042 | U64(0x3e3b0dbe78d7a9de), U64(0x50b9ee202d670f04), | ||
1043 | U64(0x4590b27b37eab0e5), U64(0x6025b4cb36b10af3), | ||
1044 | U64(0xfb2c1237079c0162), U64(0xa12f28130c936be8), | ||
1045 | U64(0x4b37e52e54eb1ccc), U64(0x083a1ba28ad28f53), | ||
1046 | U64(0xc10a9cd83a22611b), U64(0x9f1425ad7444c236), | ||
1047 | U64(0x069d4cf7e9d3237a), U64(0xedc56899e7f621be), | ||
1048 | U64(0x778c273680865fcf), U64(0x309c5aeb1bd605f7), | ||
1049 | U64(0x8de0dc52d1472b4d), U64(0xf8ec34c2fd7b9e5f), | ||
1050 | U64(0xea18cd3d58787724), U64(0xaad515447ca67b86), | ||
1051 | U64(0x9989695a9d97e14c), U64(0x0000000000000000), | ||
1052 | U64(0xf196c63321f464ec), U64(0x71116bc169557cb5), | ||
1053 | U64(0xaf887f466f92c7c1), U64(0x972e3e0ffe964d65), | ||
1054 | U64(0x190ec4a8d536f915), U64(0x95aef1a9522ca7b8), | ||
1055 | U64(0xdc19db21aa7d51a9), U64(0x94ee18fa0471d258), | ||
1056 | U64(0x8087adf248a11859), U64(0xc457f6da2916dd5c), | ||
1057 | U64(0xfa6cfb6451c17482), U64(0xf256e0c6db13fbd1), | ||
1058 | U64(0x6a9f60cf10d96f7d), U64(0x4daaa9d9bd383fb6), | ||
1059 | U64(0x03c026f5fae79f3d), U64(0xde99148706c7bb74), | ||
1060 | U64(0x2a52b8b6340763df), U64(0x6fc20acd03edd33a), | ||
1061 | U64(0xd423c08320afdefa), U64(0xbbe1ca4e23420dc0), | ||
1062 | U64(0x966ed75ca8cb3885), U64(0xeb58246e0e2502c4), | ||
1063 | U64(0x055d6a021334bc47), U64(0xa47242111fa7d7af), | ||
1064 | U64(0xe3623fcc84f78d97), U64(0x81c744a11efc6db9), | ||
1065 | U64(0xaec8961539cfb221), U64(0xf31609958d4e8e31), | ||
1066 | U64(0x63e5923ecc5695ce), U64(0x47107ddd9b505a38), | ||
1067 | U64(0xa3afe7b5a0298135), U64(0x792b7063e387f3e6), | ||
1068 | U64(0x0140e953565d75e0), U64(0x12f4f9ffa503e97b), | ||
1069 | U64(0x750ce8902c3cb512), U64(0xdbc47e8515f30733), | ||
1070 | U64(0x1ed3610c6ab8af8f), U64(0x5239218681dde5d9), | ||
1071 | U64(0xe222d69fd2aaf877), U64(0xfe71783514a8bd25), | ||
1072 | U64(0xcaf0a18f4a177175), U64(0x61655d9860ec7f13), | ||
1073 | U64(0xe77fbc9dc19e4430), U64(0x2ccff441ddd440a5), | ||
1074 | U64(0x16e97aaee06a20dc), U64(0xa855dae2d01c915b), | ||
1075 | U64(0x1d1347f9905f30b2), U64(0xb7c652bdecf94b34), | ||
1076 | U64(0xd03e43d265c6175d), U64(0xfdb15ec0ee4f2218), | ||
1077 | U64(0x57644b8492e9599e), U64(0x07dda5a4bf8e569a), | ||
1078 | U64(0x54a46d71680ec6a3), U64(0x5624a2d7c4b42c7e), | ||
1079 | U64(0xbebca04c3076b187), U64(0x7d36f332a6ee3a41), | ||
1080 | U64(0x3b6667bc6be31599), U64(0x695f463aea3ef040), | ||
1081 | U64(0xad08b0e0c3282d1c), U64(0xb15b1e4a052a684e), | ||
1082 | U64(0x44d05b2861b7c505), U64(0x15295c5b1a8dbfe1), | ||
1083 | U64(0x744c01c37a61c0f2), U64(0x59c31cd1f1e8f5b7), | ||
1084 | U64(0xef45a73f4b4ccb63), U64(0x6bdf899c46841a9d), | ||
1085 | U64(0x3dfb2b4b823036e3), U64(0xa2ef0ee6f674f4d5), | ||
1086 | U64(0x184e2dfb836b8cf5), U64(0x1134df0a5fe47646), | ||
1087 | U64(0xbaa1231d751f7820), U64(0xd17eaa81339b62bd), | ||
1088 | U64(0xb01bf71953771dae), U64(0x849a2ea30dc8d1fe), | ||
1089 | U64(0x705182923f080955), U64(0x0ea757556301ac29), | ||
1090 | U64(0x041d83514569c9a7), U64(0x0abad4042668658e), | ||
1091 | U64(0x49b72a88f851f611), U64(0x8a3d79f66ec97dd7), | ||
1092 | U64(0xcd2d042bf59927ef), U64(0xc930877ab0f0ee48), | ||
1093 | U64(0x9273540deda2f122), U64(0xc797d02fd3f14261), | ||
1094 | U64(0xe1e2f06a284d674a), U64(0xd2be8c74c97cfd80), | ||
1095 | U64(0x9a494faf67707e71), U64(0xb3dbd1eca9908293), | ||
1096 | U64(0x72d14d3493b2e388), U64(0xd6a30f258c153427) | ||
1097 | }, | ||
1098 | }; | ||
1099 | |||
1100 | static const STREEBOG_LONG64 C16[12][8] = | ||
1101 | { | ||
1102 | { | ||
1103 | U64(0xdd806559f2a64507), U64(0x05767436cc744d23), | ||
1104 | U64(0xa2422a08a460d315), U64(0x4b7ce09192676901), | ||
1105 | U64(0x714eb88d7585c4fc), U64(0x2f6a76432e45d016), | ||
1106 | U64(0xebcb2f81c0657c1f), U64(0xb1085bda1ecadae9) | ||
1107 | }, { | ||
1108 | U64(0xe679047021b19bb7), U64(0x55dda21bd7cbcd56), | ||
1109 | U64(0x5cb561c2db0aa7ca), U64(0x9ab5176b12d69958), | ||
1110 | U64(0x61d55e0f16b50131), U64(0xf3feea720a232b98), | ||
1111 | U64(0x4fe39d460f70b5d7), U64(0x6fa3b58aa99d2f1a) | ||
1112 | }, { | ||
1113 | U64(0x991e96f50aba0ab2), U64(0xc2b6f443867adb31), | ||
1114 | U64(0xc1c93a376062db09), U64(0xd3e20fe490359eb1), | ||
1115 | U64(0xf2ea7514b1297b7b), U64(0x06f15e5f529c1f8b), | ||
1116 | U64(0x0a39fc286a3d8435), U64(0xf574dcac2bce2fc7) | ||
1117 | }, { | ||
1118 | U64(0x220cbebc84e3d12e), U64(0x3453eaa193e837f1), | ||
1119 | U64(0xd8b71333935203be), U64(0xa9d72c82ed03d675), | ||
1120 | U64(0x9d721cad685e353f), U64(0x488e857e335c3c7d), | ||
1121 | U64(0xf948e1a05d71e4dd), U64(0xef1fdfb3e81566d2) | ||
1122 | }, { | ||
1123 | U64(0x601758fd7c6cfe57), U64(0x7a56a27ea9ea63f5), | ||
1124 | U64(0xdfff00b723271a16), U64(0xbfcd1747253af5a3), | ||
1125 | U64(0x359e35d7800fffbd), U64(0x7f151c1f1686104a), | ||
1126 | U64(0x9a3f410c6ca92363), U64(0x4bea6bacad474799) | ||
1127 | }, { | ||
1128 | U64(0xfa68407a46647d6e), U64(0xbf71c57236904f35), | ||
1129 | U64(0x0af21f66c2bec6b6), U64(0xcffaa6b71c9ab7b4), | ||
1130 | U64(0x187f9ab49af08ec6), U64(0x2d66c4f95142a46c), | ||
1131 | U64(0x6fa4c33b7a3039c0), U64(0xae4faeae1d3ad3d9) | ||
1132 | }, { | ||
1133 | U64(0x8886564d3a14d493), U64(0x3517454ca23c4af3), | ||
1134 | U64(0x06476983284a0504), U64(0x0992abc52d822c37), | ||
1135 | U64(0xd3473e33197a93c9), U64(0x399ec6c7e6bf87c9), | ||
1136 | U64(0x51ac86febf240954), U64(0xf4c70e16eeaac5ec) | ||
1137 | }, { | ||
1138 | U64(0xa47f0dd4bf02e71e), U64(0x36acc2355951a8d9), | ||
1139 | U64(0x69d18d2bd1a5c42f), U64(0xf4892bcb929b0690), | ||
1140 | U64(0x89b4443b4ddbc49a), U64(0x4eb7f8719c36de1e), | ||
1141 | U64(0x03e7aa020c6e4141), U64(0x9b1f5b424d93c9a7) | ||
1142 | }, { | ||
1143 | U64(0x7261445183235adb), U64(0x0e38dc92cb1f2a60), | ||
1144 | U64(0x7b2b8a9aa6079c54), U64(0x800a440bdbb2ceb1), | ||
1145 | U64(0x3cd955b7e00d0984), U64(0x3a7d3a1b25894224), | ||
1146 | U64(0x944c9ad8ec165fde), U64(0x378f5a541631229b) | ||
1147 | }, { | ||
1148 | U64(0x74b4c7fb98459ced), U64(0x3698fad1153bb6c3), | ||
1149 | U64(0x7a1e6c303b7652f4), U64(0x9fe76702af69334b), | ||
1150 | U64(0x1fffe18a1b336103), U64(0x8941e71cff8a78db), | ||
1151 | U64(0x382ae548b2e4f3f3), U64(0xabbedea680056f52) | ||
1152 | }, { | ||
1153 | U64(0x6bcaa4cd81f32d1b), U64(0xdea2594ac06fd85d), | ||
1154 | U64(0xefbacd1d7d476e98), U64(0x8a1d71efea48b9ca), | ||
1155 | U64(0x2001802114846679), U64(0xd8fa6bbbebab0761), | ||
1156 | U64(0x3002c6cd635afe94), U64(0x7bcd9ed0efc889fb) | ||
1157 | }, { | ||
1158 | U64(0x48bc924af11bd720), U64(0xfaf417d5d9b21b99), | ||
1159 | U64(0xe71da4aa88e12852), U64(0x5d80ef9d1891cc86), | ||
1160 | U64(0xf82012d430219f9b), U64(0xcda43c32bcdf1d77), | ||
1161 | U64(0xd21380b00449b17a), U64(0x378ee767f11631ba) | ||
1162 | }, | ||
1163 | }; | ||
1164 | |||
1165 | #define B(x,i,j) (((STREEBOG_LONG64)(*(((const unsigned char *)(&x))+i)))<<(j*8)) | ||
1166 | #define PULL64(x) (B(x,0,0)|B(x,1,1)|B(x,2,2)|B(x,3,3)|B(x,4,4)|B(x,5,5)|B(x,6,6)|B(x,7,7)) | ||
1167 | #define SWAB64(x) (B(x,0,7)|B(x,1,6)|B(x,2,5)|B(x,3,4)|B(x,4,3)|B(x,5,2)|B(x,6,1)|B(x,7,0)) | ||
1168 | |||
1169 | static inline STREEBOG_LONG64 multipermute(const STREEBOG_LONG64 *in, int i) { | ||
1170 | STREEBOG_LONG64 t = 0; | ||
1171 | |||
1172 | t ^= A_PI_table[0][(in[0] >> (i * 8)) & 0xff]; | ||
1173 | t ^= A_PI_table[1][(in[1] >> (i * 8)) & 0xff]; | ||
1174 | t ^= A_PI_table[2][(in[2] >> (i * 8)) & 0xff]; | ||
1175 | t ^= A_PI_table[3][(in[3] >> (i * 8)) & 0xff]; | ||
1176 | t ^= A_PI_table[4][(in[4] >> (i * 8)) & 0xff]; | ||
1177 | t ^= A_PI_table[5][(in[5] >> (i * 8)) & 0xff]; | ||
1178 | t ^= A_PI_table[6][(in[6] >> (i * 8)) & 0xff]; | ||
1179 | t ^= A_PI_table[7][(in[7] >> (i * 8)) & 0xff]; | ||
1180 | |||
1181 | return t; | ||
1182 | } | ||
1183 | |||
1184 | static void transform(STREEBOG_LONG64 *out, const STREEBOG_LONG64 *a, const STREEBOG_LONG64 *b) | ||
1185 | { | ||
1186 | STREEBOG_LONG64 tmp[8]; | ||
1187 | |||
1188 | tmp[0] = a[0] ^ b[0]; | ||
1189 | tmp[1] = a[1] ^ b[1]; | ||
1190 | tmp[2] = a[2] ^ b[2]; | ||
1191 | tmp[3] = a[3] ^ b[3]; | ||
1192 | tmp[4] = a[4] ^ b[4]; | ||
1193 | tmp[5] = a[5] ^ b[5]; | ||
1194 | tmp[6] = a[6] ^ b[6]; | ||
1195 | tmp[7] = a[7] ^ b[7]; | ||
1196 | |||
1197 | out[0] = multipermute(tmp, 0); | ||
1198 | out[1] = multipermute(tmp, 1); | ||
1199 | out[2] = multipermute(tmp, 2); | ||
1200 | out[3] = multipermute(tmp, 3); | ||
1201 | out[4] = multipermute(tmp, 4); | ||
1202 | out[5] = multipermute(tmp, 5); | ||
1203 | out[6] = multipermute(tmp, 6); | ||
1204 | out[7] = multipermute(tmp, 7); | ||
1205 | } | ||
1206 | |||
1207 | static inline void gN(STREEBOG_LONG64 *h, STREEBOG_LONG64 *m, STREEBOG_LONG64 *N) | ||
1208 | { | ||
1209 | STREEBOG_LONG64 K[8]; | ||
1210 | STREEBOG_LONG64 T[8]; | ||
1211 | int i; | ||
1212 | |||
1213 | transform(K, h, N); | ||
1214 | |||
1215 | transform(T, K, m); | ||
1216 | transform(K, K, C16[0]); | ||
1217 | for (i = 1; i < 12; i++) { | ||
1218 | transform(T, K, T); | ||
1219 | transform(K, K, C16[i]); | ||
1220 | } | ||
1221 | |||
1222 | h[0] ^= T[0] ^ K[0] ^ m[0]; | ||
1223 | h[1] ^= T[1] ^ K[1] ^ m[1]; | ||
1224 | h[2] ^= T[2] ^ K[2] ^ m[2]; | ||
1225 | h[3] ^= T[3] ^ K[3] ^ m[3]; | ||
1226 | h[4] ^= T[4] ^ K[4] ^ m[4]; | ||
1227 | h[5] ^= T[5] ^ K[5] ^ m[5]; | ||
1228 | h[6] ^= T[6] ^ K[6] ^ m[6]; | ||
1229 | h[7] ^= T[7] ^ K[7] ^ m[7]; | ||
1230 | } | ||
1231 | |||
1232 | |||
1233 | static void streebog_single_block(STREEBOG_CTX * ctx, const unsigned char *in, size_t num) | ||
1234 | { | ||
1235 | STREEBOG_LONG64 M[8], l; | ||
1236 | int i; | ||
1237 | |||
1238 | for (i = 0; i < 8; i++) | ||
1239 | M[i] = PULL64(in[i*8]); | ||
1240 | |||
1241 | gN(ctx->h, M, ctx->N); | ||
1242 | |||
1243 | l = ctx->N[0]; | ||
1244 | ctx->N[0] += num; | ||
1245 | |||
1246 | if (ctx->N[0] < l || ctx->N[0] < num) { | ||
1247 | for (i = 1; i < 8; i++) { | ||
1248 | ctx->N[i]++; | ||
1249 | if (ctx->N[i] != 0) | ||
1250 | break; | ||
1251 | } | ||
1252 | } | ||
1253 | |||
1254 | ctx->Sigma[0] += M[0]; | ||
1255 | for (i = 1; i < 8; i++) | ||
1256 | if (ctx->Sigma[i-1] < M[i-1]) | ||
1257 | ctx->Sigma[i] += M[i] + 1; | ||
1258 | else | ||
1259 | ctx->Sigma[i] += M[i]; | ||
1260 | } | ||
1261 | |||
1262 | |||
1263 | |||
1264 | static void streebog_block_data_order(STREEBOG_CTX * ctx, const void *in, size_t num) | ||
1265 | { | ||
1266 | int i; | ||
1267 | for (i = 0; i < num; i++) | ||
1268 | streebog_single_block(ctx, in + i * STREEBOG_CBLOCK, 64 * 8); | ||
1269 | } | ||
1270 | |||
1271 | int STREEBOG512_Final(unsigned char *md, STREEBOG_CTX * c) | ||
1272 | { | ||
1273 | int n; | ||
1274 | unsigned char *p = (unsigned char *)c->data; | ||
1275 | STREEBOG_LONG64 Z[STREEBOG_LBLOCK] = {}; | ||
1276 | |||
1277 | if (c->num == STREEBOG_CBLOCK) { | ||
1278 | streebog_block_data_order(c, c->data, 1); | ||
1279 | c->num -= STREEBOG_CBLOCK; | ||
1280 | } | ||
1281 | |||
1282 | n = c->num; | ||
1283 | p[n++] = 1; | ||
1284 | memset(p+n, 0, STREEBOG_CBLOCK - n); | ||
1285 | |||
1286 | streebog_single_block(c, p, c->num * 8); | ||
1287 | |||
1288 | gN(c->h, c->N, Z); | ||
1289 | gN(c->h, c->Sigma, Z); | ||
1290 | |||
1291 | for (n = 0; n < STREEBOG_LBLOCK; n++) | ||
1292 | c->h[n] = SWAB64(c->h[n]); | ||
1293 | |||
1294 | if (md == 0) | ||
1295 | return 0; | ||
1296 | |||
1297 | switch (c->md_len) { | ||
1298 | /* Let compiler decide if it's appropriate to unroll... */ | ||
1299 | case STREEBOG256_LENGTH: | ||
1300 | for (n = 0; n < STREEBOG256_LENGTH / 8; n++) { | ||
1301 | STREEBOG_LONG64 t = c->h[4+n]; | ||
1302 | |||
1303 | *(md++) = (unsigned char)(t >> 56); | ||
1304 | *(md++) = (unsigned char)(t >> 48); | ||
1305 | *(md++) = (unsigned char)(t >> 40); | ||
1306 | *(md++) = (unsigned char)(t >> 32); | ||
1307 | *(md++) = (unsigned char)(t >> 24); | ||
1308 | *(md++) = (unsigned char)(t >> 16); | ||
1309 | *(md++) = (unsigned char)(t >> 8); | ||
1310 | *(md++) = (unsigned char)(t); | ||
1311 | } | ||
1312 | break; | ||
1313 | case STREEBOG512_LENGTH: | ||
1314 | for (n = 0; n < STREEBOG512_LENGTH / 8; n++) { | ||
1315 | STREEBOG_LONG64 t = c->h[n]; | ||
1316 | |||
1317 | *(md++) = (unsigned char)(t >> 56); | ||
1318 | *(md++) = (unsigned char)(t >> 48); | ||
1319 | *(md++) = (unsigned char)(t >> 40); | ||
1320 | *(md++) = (unsigned char)(t >> 32); | ||
1321 | *(md++) = (unsigned char)(t >> 24); | ||
1322 | *(md++) = (unsigned char)(t >> 16); | ||
1323 | *(md++) = (unsigned char)(t >> 8); | ||
1324 | *(md++) = (unsigned char)(t); | ||
1325 | } | ||
1326 | break; | ||
1327 | /* ... as well as make sure md_len is not abused. */ | ||
1328 | default: | ||
1329 | return 0; | ||
1330 | } | ||
1331 | |||
1332 | return 1; | ||
1333 | } | ||
1334 | |||
1335 | int STREEBOG256_Final(unsigned char *md, STREEBOG_CTX * c) | ||
1336 | { | ||
1337 | return STREEBOG512_Final(md, c); | ||
1338 | } | ||
1339 | |||
1340 | int STREEBOG512_Update(STREEBOG_CTX * c, const void *_data, size_t len) | ||
1341 | { | ||
1342 | unsigned char *p = (unsigned char *)c->data; | ||
1343 | const unsigned char *data = (const unsigned char *)_data; | ||
1344 | |||
1345 | if (len == 0) | ||
1346 | return 1; | ||
1347 | |||
1348 | if (c->num != 0) { | ||
1349 | size_t n = STREEBOG_CBLOCK - c->num; | ||
1350 | |||
1351 | if (len < n) { | ||
1352 | memcpy(p + c->num, data, len); | ||
1353 | c->num += (unsigned int)len; | ||
1354 | return 1; | ||
1355 | } else { | ||
1356 | memcpy(p + c->num, data, n); | ||
1357 | c->num = 0; | ||
1358 | len -= n; | ||
1359 | data += n; | ||
1360 | streebog_block_data_order(c, p, 1); | ||
1361 | } | ||
1362 | } | ||
1363 | |||
1364 | if (len >= STREEBOG_CBLOCK) { | ||
1365 | streebog_block_data_order(c, data, len / STREEBOG_CBLOCK); | ||
1366 | data += len; | ||
1367 | len %= STREEBOG_CBLOCK; | ||
1368 | data -= len; | ||
1369 | } | ||
1370 | |||
1371 | if (len != 0) { | ||
1372 | memcpy(p, data, len); | ||
1373 | c->num = (int)len; | ||
1374 | } | ||
1375 | |||
1376 | return 1; | ||
1377 | } | ||
1378 | |||
1379 | int STREEBOG256_Update(STREEBOG_CTX * c, const void *data, size_t len) | ||
1380 | { | ||
1381 | return STREEBOG512_Update(c, data, len); | ||
1382 | } | ||
1383 | |||
1384 | void STREEBOG512_Transform(STREEBOG_CTX * c, const unsigned char *data) | ||
1385 | { | ||
1386 | streebog_block_data_order(c, data, 1); | ||
1387 | } | ||
1388 | |||
1389 | int STREEBOG256_Init(STREEBOG_CTX * c) | ||
1390 | { | ||
1391 | memset(c, 0, sizeof(*c)); | ||
1392 | memset(c->h, 1, sizeof(c->h)); | ||
1393 | |||
1394 | c->md_len = STREEBOG256_LENGTH; | ||
1395 | return 1; | ||
1396 | } | ||
1397 | |||
1398 | int STREEBOG512_Init(STREEBOG_CTX * c) | ||
1399 | { | ||
1400 | memset(c, 0, sizeof(*c)); | ||
1401 | memset(c->h, 0, sizeof(c->h)); | ||
1402 | |||
1403 | c->num = 0; | ||
1404 | c->md_len = STREEBOG512_LENGTH; | ||
1405 | return 1; | ||
1406 | } | ||
1407 | |||
1408 | unsigned char *STREEBOG256(const unsigned char *d, size_t n, unsigned char *md) | ||
1409 | { | ||
1410 | STREEBOG_CTX c; | ||
1411 | static unsigned char m[STREEBOG256_LENGTH]; | ||
1412 | |||
1413 | if (md == NULL) | ||
1414 | md = m; | ||
1415 | STREEBOG256_Init(&c); | ||
1416 | STREEBOG256_Update(&c, d, n); | ||
1417 | STREEBOG256_Final(md, &c); | ||
1418 | OPENSSL_cleanse(&c, sizeof(c)); | ||
1419 | return (md); | ||
1420 | } | ||
1421 | |||
1422 | unsigned char *STREEBOG512(const unsigned char *d, size_t n, unsigned char *md) | ||
1423 | { | ||
1424 | STREEBOG_CTX c; | ||
1425 | static unsigned char m[STREEBOG512_LENGTH]; | ||
1426 | |||
1427 | if (md == NULL) | ||
1428 | md = m; | ||
1429 | STREEBOG512_Init(&c); | ||
1430 | STREEBOG512_Update(&c, d, n); | ||
1431 | STREEBOG512_Final(md, &c); | ||
1432 | OPENSSL_cleanse(&c, sizeof(c)); | ||
1433 | return (md); | ||
1434 | } | ||
1435 | |||
1436 | #endif | ||
diff --git a/src/lib/libcrypto/objects/obj_mac.num b/src/lib/libcrypto/objects/obj_mac.num index bcdda5163e..d3a658e59c 100644 --- a/src/lib/libcrypto/objects/obj_mac.num +++ b/src/lib/libcrypto/objects/obj_mac.num | |||
@@ -935,3 +935,15 @@ brainpoolP512r1 934 | |||
935 | brainpoolP512t1 935 | 935 | brainpoolP512t1 935 |
936 | FRP256v1 936 | 936 | FRP256v1 936 |
937 | chacha20 937 | 937 | chacha20 937 |
938 | gost89_ecb 938 | ||
939 | gost89_cbc 939 | ||
940 | tc26 940 | ||
941 | id_tc26_gost3411_2012_256 941 | ||
942 | id_tc26_gost3411_2012_512 942 | ||
943 | id_tc26_gost_3410_2012_512_paramSetA 943 | ||
944 | id_tc26_gost_3410_2012_512_paramSetB 944 | ||
945 | id_tc26_gost_28147_param_Z 945 | ||
946 | id_tc26_gost3410_2012_256 946 | ||
947 | id_tc26_gost3410_2012_512 947 | ||
948 | id_tc26_signwithdigest_gost3410_2012_256 948 | ||
949 | id_tc26_signwithdigest_gost3410_2012_512 949 | ||
diff --git a/src/lib/libcrypto/objects/obj_xref.h b/src/lib/libcrypto/objects/obj_xref.h index fec28d1127..4499456694 100644 --- a/src/lib/libcrypto/objects/obj_xref.h +++ b/src/lib/libcrypto/objects/obj_xref.h | |||
@@ -1,4 +1,4 @@ | |||
1 | /* $OpenBSD: obj_xref.h,v 1.2 2014/06/12 15:49:30 deraadt Exp $ */ | 1 | /* $OpenBSD: obj_xref.h,v 1.3 2014/11/09 19:17:13 miod Exp $ */ |
2 | /* AUTOGENERATED BY objxref.pl, DO NOT EDIT */ | 2 | /* AUTOGENERATED BY objxref.pl, DO NOT EDIT */ |
3 | 3 | ||
4 | typedef struct | 4 | typedef struct |
@@ -40,6 +40,8 @@ static const nid_triple sigoid_srt[] = | |||
40 | {NID_id_GostR3411_94_with_GostR3410_94_cc, NID_id_GostR3411_94, NID_id_GostR3410_94_cc}, | 40 | {NID_id_GostR3411_94_with_GostR3410_94_cc, NID_id_GostR3411_94, NID_id_GostR3410_94_cc}, |
41 | {NID_id_GostR3411_94_with_GostR3410_2001_cc, NID_id_GostR3411_94, NID_id_GostR3410_2001_cc}, | 41 | {NID_id_GostR3411_94_with_GostR3410_2001_cc, NID_id_GostR3411_94, NID_id_GostR3410_2001_cc}, |
42 | {NID_rsassaPss, NID_undef, NID_rsaEncryption}, | 42 | {NID_rsassaPss, NID_undef, NID_rsaEncryption}, |
43 | {NID_id_tc26_signwithdigest_gost3410_2012_256, NID_id_tc26_gost3411_2012_256, NID_id_GostR3410_2001}, | ||
44 | {NID_id_tc26_signwithdigest_gost3410_2012_512, NID_id_tc26_gost3411_2012_512, NID_id_GostR3410_2001}, | ||
43 | }; | 45 | }; |
44 | 46 | ||
45 | static const nid_triple * const sigoid_srt_xref[] = | 47 | static const nid_triple * const sigoid_srt_xref[] = |
@@ -74,5 +76,7 @@ static const nid_triple * const sigoid_srt_xref[] = | |||
74 | &sigoid_srt[26], | 76 | &sigoid_srt[26], |
75 | &sigoid_srt[27], | 77 | &sigoid_srt[27], |
76 | &sigoid_srt[28], | 78 | &sigoid_srt[28], |
79 | &sigoid_srt[30], | ||
80 | &sigoid_srt[31], | ||
77 | }; | 81 | }; |
78 | 82 | ||
diff --git a/src/lib/libcrypto/objects/obj_xref.txt b/src/lib/libcrypto/objects/obj_xref.txt index cb917182ee..dde52d8143 100644 --- a/src/lib/libcrypto/objects/obj_xref.txt +++ b/src/lib/libcrypto/objects/obj_xref.txt | |||
@@ -44,3 +44,5 @@ id_GostR3411_94_with_GostR3410_2001 id_GostR3411_94 id_GostR3410_2001 | |||
44 | id_GostR3411_94_with_GostR3410_94 id_GostR3411_94 id_GostR3410_94 | 44 | id_GostR3411_94_with_GostR3410_94 id_GostR3411_94 id_GostR3410_94 |
45 | id_GostR3411_94_with_GostR3410_94_cc id_GostR3411_94 id_GostR3410_94_cc | 45 | id_GostR3411_94_with_GostR3410_94_cc id_GostR3411_94 id_GostR3410_94_cc |
46 | id_GostR3411_94_with_GostR3410_2001_cc id_GostR3411_94 id_GostR3410_2001_cc | 46 | id_GostR3411_94_with_GostR3410_2001_cc id_GostR3411_94 id_GostR3410_2001_cc |
47 | id_tc26_signwithdigest_gost3410_2012_256 id_tc26_gost3411_2012_256 id_tc26_gost3410_2012_256 | ||
48 | id_tc26_signwithdigest_gost3410_2012_512 id_tc26_gost3411_2012_512 id_tc26_gost3410_2012_512 | ||
diff --git a/src/lib/libcrypto/objects/objects.txt b/src/lib/libcrypto/objects/objects.txt index bb44aa77a3..1ce73cc984 100644 --- a/src/lib/libcrypto/objects/objects.txt +++ b/src/lib/libcrypto/objects/objects.txt | |||
@@ -1313,3 +1313,18 @@ brainpool 1 14 : brainpoolP512t1 | |||
1313 | # ChaCha Stream Cipher | 1313 | # ChaCha Stream Cipher |
1314 | !Cname chacha20 | 1314 | !Cname chacha20 |
1315 | : ChaCha : chacha | 1315 | : ChaCha : chacha |
1316 | : gost89-ecb | ||
1317 | : gost89-cbc | ||
1318 | |||
1319 | member-body 643 7 1 : tc26 | ||
1320 | !Cname id-tc26-gost3411-2012-256 | ||
1321 | tc26 1 2 2 : streebog256 : GOST R 34.11-2012 (256 bit) | ||
1322 | !Cname id-tc26-gost3411-2012-512 | ||
1323 | tc26 1 2 3 : streebog512 : GOST R 34-11-2012 (512 bit) | ||
1324 | tc26 2 1 2 1 : id-tc26-gost-3410-2012-512-paramSetA | ||
1325 | tc26 2 1 2 2 : id-tc26-gost-3410-2012-512-paramSetB | ||
1326 | tc26 2 5 1 1 : id-tc26-gost-28147-param-Z | ||
1327 | tc26 1 1 1 : id-tc26-gost3410-2012-256 : GOST R 34.10-2012 (256 bit) | ||
1328 | tc26 1 1 2 : id-tc26-gost3410-2012-512 : GOST R 34.10-2012 (512 bit) | ||
1329 | tc26 1 3 2 : id-tc26-signwithdigest-gost3410-2012-256 : GOST R 34.11-2012 with GOST R 34.10-2012 (256 bit) | ||
1330 | tc26 1 3 3 : id-tc26-signwithdigest-gost3410-2012-512 : GOST R 34.11-2012 with GOST R 34.10-2012 (512 bit) | ||
diff --git a/src/lib/libcrypto/pkcs7/pk7_smime.c b/src/lib/libcrypto/pkcs7/pk7_smime.c index b76e2b1915..576866f5c2 100644 --- a/src/lib/libcrypto/pkcs7/pk7_smime.c +++ b/src/lib/libcrypto/pkcs7/pk7_smime.c | |||
@@ -1,4 +1,4 @@ | |||
1 | /* $OpenBSD: pk7_smime.c,v 1.18 2014/07/11 08:44:49 jsing Exp $ */ | 1 | /* $OpenBSD: pk7_smime.c,v 1.19 2014/11/09 19:17:13 miod Exp $ */ |
2 | /* Written by Dr Stephen N Henson (steve@openssl.org) for the OpenSSL | 2 | /* Written by Dr Stephen N Henson (steve@openssl.org) for the OpenSSL |
3 | * project. | 3 | * project. |
4 | */ | 4 | */ |
@@ -192,6 +192,8 @@ PKCS7_sign_add_signer(PKCS7 *p7, X509 *signcert, EVP_PKEY *pkey, | |||
192 | } | 192 | } |
193 | if (!add_cipher_smcap(smcap, NID_aes_256_cbc, -1) || | 193 | if (!add_cipher_smcap(smcap, NID_aes_256_cbc, -1) || |
194 | !add_digest_smcap(smcap, NID_id_GostR3411_94, -1) || | 194 | !add_digest_smcap(smcap, NID_id_GostR3411_94, -1) || |
195 | !add_digest_smcap(smcap, NID_id_tc26_gost3411_2012_256, -1) || | ||
196 | !add_digest_smcap(smcap, NID_id_tc26_gost3411_2012_512, -1) || | ||
195 | !add_cipher_smcap(smcap, NID_id_Gost28147_89, -1) || | 197 | !add_cipher_smcap(smcap, NID_id_Gost28147_89, -1) || |
196 | !add_cipher_smcap(smcap, NID_aes_192_cbc, -1) || | 198 | !add_cipher_smcap(smcap, NID_aes_192_cbc, -1) || |
197 | !add_cipher_smcap(smcap, NID_aes_128_cbc, -1) || | 199 | !add_cipher_smcap(smcap, NID_aes_128_cbc, -1) || |
diff --git a/src/lib/libssl/src/crypto/asn1/ameth_lib.c b/src/lib/libssl/src/crypto/asn1/ameth_lib.c index e88496cc9d..168321618c 100644 --- a/src/lib/libssl/src/crypto/asn1/ameth_lib.c +++ b/src/lib/libssl/src/crypto/asn1/ameth_lib.c | |||
@@ -1,4 +1,4 @@ | |||
1 | /* $OpenBSD: ameth_lib.c,v 1.14 2014/07/13 16:03:09 beck Exp $ */ | 1 | /* $OpenBSD: ameth_lib.c,v 1.15 2014/11/09 19:17:13 miod Exp $ */ |
2 | /* Written by Dr Stephen N Henson (steve@openssl.org) for the OpenSSL | 2 | /* Written by Dr Stephen N Henson (steve@openssl.org) for the OpenSSL |
3 | * project 2006. | 3 | * project 2006. |
4 | */ | 4 | */ |
@@ -74,6 +74,8 @@ extern const EVP_PKEY_ASN1_METHOD rsa_asn1_meths[]; | |||
74 | extern const EVP_PKEY_ASN1_METHOD dsa_asn1_meths[]; | 74 | extern const EVP_PKEY_ASN1_METHOD dsa_asn1_meths[]; |
75 | extern const EVP_PKEY_ASN1_METHOD dh_asn1_meth; | 75 | extern const EVP_PKEY_ASN1_METHOD dh_asn1_meth; |
76 | extern const EVP_PKEY_ASN1_METHOD eckey_asn1_meth; | 76 | extern const EVP_PKEY_ASN1_METHOD eckey_asn1_meth; |
77 | extern const EVP_PKEY_ASN1_METHOD gostr01_asn1_meths[]; | ||
78 | extern const EVP_PKEY_ASN1_METHOD gostimit_asn1_meth; | ||
77 | extern const EVP_PKEY_ASN1_METHOD hmac_asn1_meth; | 79 | extern const EVP_PKEY_ASN1_METHOD hmac_asn1_meth; |
78 | extern const EVP_PKEY_ASN1_METHOD cmac_asn1_meth; | 80 | extern const EVP_PKEY_ASN1_METHOD cmac_asn1_meth; |
79 | 81 | ||
@@ -96,8 +98,16 @@ static const EVP_PKEY_ASN1_METHOD *standard_methods[] = { | |||
96 | #ifndef OPENSSL_NO_EC | 98 | #ifndef OPENSSL_NO_EC |
97 | &eckey_asn1_meth, | 99 | &eckey_asn1_meth, |
98 | #endif | 100 | #endif |
101 | #ifndef OPENSSL_NO_GOST | ||
102 | &gostr01_asn1_meths[0], | ||
103 | &gostimit_asn1_meth, | ||
104 | #endif | ||
99 | &hmac_asn1_meth, | 105 | &hmac_asn1_meth, |
100 | &cmac_asn1_meth | 106 | &cmac_asn1_meth, |
107 | #ifndef OPENSSL_NO_GOST | ||
108 | &gostr01_asn1_meths[1], | ||
109 | &gostr01_asn1_meths[2], | ||
110 | #endif | ||
101 | }; | 111 | }; |
102 | 112 | ||
103 | typedef int sk_cmp_fn_type(const char * const *a, const char * const *b); | 113 | typedef int sk_cmp_fn_type(const char * const *a, const char * const *b); |
diff --git a/src/lib/libssl/src/crypto/cms/cms_sd.c b/src/lib/libssl/src/crypto/cms/cms_sd.c index 70ad897bda..f4119f7a1c 100644 --- a/src/lib/libssl/src/crypto/cms/cms_sd.c +++ b/src/lib/libssl/src/crypto/cms/cms_sd.c | |||
@@ -1,4 +1,4 @@ | |||
1 | /* $OpenBSD: cms_sd.c,v 1.8 2014/07/12 16:03:37 miod Exp $ */ | 1 | /* $OpenBSD: cms_sd.c,v 1.9 2014/11/09 19:17:13 miod Exp $ */ |
2 | /* Written by Dr Stephen N Henson (steve@openssl.org) for the OpenSSL | 2 | /* Written by Dr Stephen N Henson (steve@openssl.org) for the OpenSSL |
3 | * project. | 3 | * project. |
4 | */ | 4 | */ |
@@ -920,6 +920,8 @@ CMS_add_standard_smimecap(STACK_OF(X509_ALGOR) **smcap) | |||
920 | { | 920 | { |
921 | if (!cms_add_cipher_smcap(smcap, NID_aes_256_cbc, -1) || | 921 | if (!cms_add_cipher_smcap(smcap, NID_aes_256_cbc, -1) || |
922 | !cms_add_digest_smcap(smcap, NID_id_GostR3411_94, -1) || | 922 | !cms_add_digest_smcap(smcap, NID_id_GostR3411_94, -1) || |
923 | !cms_add_digest_smcap(smcap, NID_id_tc26_gost3411_2012_256, -1) || | ||
924 | !cms_add_digest_smcap(smcap, NID_id_tc26_gost3411_2012_512, -1) || | ||
923 | !cms_add_cipher_smcap(smcap, NID_id_Gost28147_89, -1) || | 925 | !cms_add_cipher_smcap(smcap, NID_id_Gost28147_89, -1) || |
924 | !cms_add_cipher_smcap(smcap, NID_aes_192_cbc, -1) || | 926 | !cms_add_cipher_smcap(smcap, NID_aes_192_cbc, -1) || |
925 | !cms_add_cipher_smcap(smcap, NID_aes_128_cbc, -1) || | 927 | !cms_add_cipher_smcap(smcap, NID_aes_128_cbc, -1) || |
diff --git a/src/lib/libssl/src/crypto/ec/ec_curve.c b/src/lib/libssl/src/crypto/ec/ec_curve.c index 9d36d0bf22..0159dbe530 100644 --- a/src/lib/libssl/src/crypto/ec/ec_curve.c +++ b/src/lib/libssl/src/crypto/ec/ec_curve.c | |||
@@ -1,4 +1,4 @@ | |||
1 | /* $OpenBSD: ec_curve.c,v 1.7 2014/07/12 16:03:37 miod Exp $ */ | 1 | /* $OpenBSD: ec_curve.c,v 1.8 2014/11/09 19:17:13 miod Exp $ */ |
2 | /* | 2 | /* |
3 | * Written by Nils Larsch for the OpenSSL project. | 3 | * Written by Nils Larsch for the OpenSSL project. |
4 | */ | 4 | */ |
@@ -2766,6 +2766,315 @@ static const struct { | |||
2766 | } | 2766 | } |
2767 | }; | 2767 | }; |
2768 | 2768 | ||
2769 | #ifndef OPENSSL_NO_GOST | ||
2770 | static const struct { | ||
2771 | EC_CURVE_DATA h; | ||
2772 | unsigned char data[0 + 32 * 6]; | ||
2773 | } | ||
2774 | _EC_GOST_2001_Test = { | ||
2775 | { | ||
2776 | NID_X9_62_prime_field, 0, 32, 1 | ||
2777 | }, | ||
2778 | { /* no seed */ | ||
2779 | 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* p */ | ||
2780 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, | ||
2781 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, | ||
2782 | 0x04, 0x31, | ||
2783 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* a */ | ||
2784 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, | ||
2785 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, | ||
2786 | 0x00, 0x07, | ||
2787 | 0x5F, 0xBF, 0xF4, 0x98, 0xAA, 0x93, 0x8C, 0xE7, 0x39, 0xB8, /* b */ | ||
2788 | 0xE0, 0x22, 0xFB, 0xAF, 0xEF, 0x40, 0x56, 0x3F, 0x6E, 0x6A, | ||
2789 | 0x34, 0x72, 0xFC, 0x2A, 0x51, 0x4C, 0x0C, 0xE9, 0xDA, 0xE2, | ||
2790 | 0x3B, 0x7E, | ||
2791 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* x */ | ||
2792 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, | ||
2793 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, | ||
2794 | 0x00, 0x02, | ||
2795 | 0x08, 0xE2, 0xA8, 0xA0, 0xE6, 0x51, 0x47, 0xD4, 0xBD, 0x63, /* y */ | ||
2796 | 0x16, 0x03, 0x0E, 0x16, 0xD1, 0x9C, 0x85, 0xC9, 0x7F, 0x0A, | ||
2797 | 0x9C, 0xA2, 0x67, 0x12, 0x2B, 0x96, 0xAB, 0xBC, 0xEA, 0x7E, | ||
2798 | 0x8F, 0xC8, | ||
2799 | 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* order */ | ||
2800 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x50, 0xFE, 0x8A, 0x18, | ||
2801 | 0x92, 0x97, 0x61, 0x54, 0xC5, 0x9C, 0xFC, 0x19, 0x3A, 0xCC, | ||
2802 | 0xF5, 0xB3, | ||
2803 | } | ||
2804 | }; | ||
2805 | |||
2806 | static const struct { | ||
2807 | EC_CURVE_DATA h; | ||
2808 | unsigned char data[0 + 32 * 6]; | ||
2809 | } | ||
2810 | _EC_GOST_2001_CryptoPro_A = { | ||
2811 | { | ||
2812 | NID_X9_62_prime_field, 0, 32, 1 | ||
2813 | }, | ||
2814 | { /* no seed */ | ||
2815 | 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, /* p */ | ||
2816 | 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, | ||
2817 | 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, | ||
2818 | 0xFD, 0x97, | ||
2819 | 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, /* a */ | ||
2820 | 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, | ||
2821 | 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, | ||
2822 | 0xFD, 0x94, | ||
2823 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* b */ | ||
2824 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, | ||
2825 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, | ||
2826 | 0x00, 0xA6, | ||
2827 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* x */ | ||
2828 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, | ||
2829 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, | ||
2830 | 0x00, 0x01, | ||
2831 | 0x8D, 0x91, 0xE4, 0x71, 0xE0, 0x98, 0x9C, 0xDA, 0x27, 0xDF, /* y */ | ||
2832 | 0x50, 0x5A, 0x45, 0x3F, 0x2B, 0x76, 0x35, 0x29, 0x4F, 0x2D, | ||
2833 | 0xDF, 0x23, 0xE3, 0xB1, 0x22, 0xAC, 0xC9, 0x9C, 0x9E, 0x9F, | ||
2834 | 0x1E, 0x14, | ||
2835 | 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, /* order */ | ||
2836 | 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0x6C, 0x61, 0x10, 0x70, | ||
2837 | 0x99, 0x5A, 0xD1, 0x00, 0x45, 0x84, 0x1B, 0x09, 0xB7, 0x61, | ||
2838 | 0xB8, 0x93, | ||
2839 | } | ||
2840 | }; | ||
2841 | |||
2842 | static const struct { | ||
2843 | EC_CURVE_DATA h; | ||
2844 | unsigned char data[0 + 32 * 6]; | ||
2845 | } | ||
2846 | _EC_GOST_2001_CryptoPro_B = { | ||
2847 | { | ||
2848 | NID_X9_62_prime_field, 0, 32, 1 | ||
2849 | }, | ||
2850 | { /* no seed */ | ||
2851 | 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* p */ | ||
2852 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, | ||
2853 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, | ||
2854 | 0x0C, 0x99, | ||
2855 | 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* a */ | ||
2856 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, | ||
2857 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, | ||
2858 | 0x0C, 0x96, | ||
2859 | 0x3E, 0x1A, 0xF4, 0x19, 0xA2, 0x69, 0xA5, 0xF8, 0x66, 0xA7, /* b */ | ||
2860 | 0xD3, 0xC2, 0x5C, 0x3D, 0xF8, 0x0A, 0xE9, 0x79, 0x25, 0x93, | ||
2861 | 0x73, 0xFF, 0x2B, 0x18, 0x2F, 0x49, 0xD4, 0xCE, 0x7E, 0x1B, | ||
2862 | 0xBC, 0x8B, | ||
2863 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* x */ | ||
2864 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, | ||
2865 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, | ||
2866 | 0x00, 0x01, | ||
2867 | 0x3F, 0xA8, 0x12, 0x43, 0x59, 0xF9, 0x66, 0x80, 0xB8, 0x3D, /* y */ | ||
2868 | 0x1C, 0x3E, 0xB2, 0xC0, 0x70, 0xE5, 0xC5, 0x45, 0xC9, 0x85, | ||
2869 | 0x8D, 0x03, 0xEC, 0xFB, 0x74, 0x4B, 0xF8, 0xD7, 0x17, 0x71, | ||
2870 | 0x7E, 0xFC, | ||
2871 | 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* order */ | ||
2872 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x5F, 0x70, 0x0C, 0xFF, | ||
2873 | 0xF1, 0xA6, 0x24, 0xE5, 0xE4, 0x97, 0x16, 0x1B, 0xCC, 0x8A, | ||
2874 | 0x19, 0x8F, | ||
2875 | } | ||
2876 | }; | ||
2877 | |||
2878 | static const struct { | ||
2879 | EC_CURVE_DATA h; | ||
2880 | unsigned char data[0 + 32 * 6]; | ||
2881 | } | ||
2882 | _EC_GOST_2001_CryptoPro_C = { | ||
2883 | { | ||
2884 | NID_X9_62_prime_field, 0, 32, 1 | ||
2885 | }, | ||
2886 | { /* no seed */ | ||
2887 | 0x9B, 0x9F, 0x60, 0x5F, 0x5A, 0x85, 0x81, 0x07, 0xAB, 0x1E, /* p */ | ||
2888 | 0xC8, 0x5E, 0x6B, 0x41, 0xC8, 0xAA, 0xCF, 0x84, 0x6E, 0x86, | ||
2889 | 0x78, 0x90, 0x51, 0xD3, 0x79, 0x98, 0xF7, 0xB9, 0x02, 0x2D, | ||
2890 | 0x75, 0x9B, | ||
2891 | 0x9B, 0x9F, 0x60, 0x5F, 0x5A, 0x85, 0x81, 0x07, 0xAB, 0x1E, /* a */ | ||
2892 | 0xC8, 0x5E, 0x6B, 0x41, 0xC8, 0xAA, 0xCF, 0x84, 0x6E, 0x86, | ||
2893 | 0x78, 0x90, 0x51, 0xD3, 0x79, 0x98, 0xF7, 0xB9, 0x02, 0x2D, | ||
2894 | 0x75, 0x98, | ||
2895 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* b */ | ||
2896 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, | ||
2897 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, | ||
2898 | 0x80, 0x5A, | ||
2899 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* x */ | ||
2900 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, | ||
2901 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, | ||
2902 | 0x00, 0x00, | ||
2903 | 0x41, 0xEC, 0xE5, 0x57, 0x43, 0x71, 0x1A, 0x8C, 0x3C, 0xBF, /* y */ | ||
2904 | 0x37, 0x83, 0xCD, 0x08, 0xC0, 0xEE, 0x4D, 0x4D, 0xC4, 0x40, | ||
2905 | 0xD4, 0x64, 0x1A, 0x8F, 0x36, 0x6E, 0x55, 0x0D, 0xFD, 0xB3, | ||
2906 | 0xBB, 0x67, | ||
2907 | 0x9B, 0x9F, 0x60, 0x5F, 0x5A, 0x85, 0x81, 0x07, 0xAB, 0x1E, /* order */ | ||
2908 | 0xC8, 0x5E, 0x6B, 0x41, 0xC8, 0xAA, 0x58, 0x2C, 0xA3, 0x51, | ||
2909 | 0x1E, 0xDD, 0xFB, 0x74, 0xF0, 0x2F, 0x3A, 0x65, 0x98, 0x98, | ||
2910 | 0x0B, 0xB9, | ||
2911 | } | ||
2912 | }; | ||
2913 | |||
2914 | static const struct { | ||
2915 | EC_CURVE_DATA h; | ||
2916 | unsigned char data[0 + 64 * 6]; | ||
2917 | } | ||
2918 | _EC_GOST_2012_Test = { | ||
2919 | { | ||
2920 | NID_X9_62_prime_field, 0, 64, 1 | ||
2921 | }, | ||
2922 | { /* no seed */ | ||
2923 | 0x45, 0x31, 0xac, 0xd1, 0xfe, 0x00, 0x23, 0xc7, 0x55, 0x0d, /* p */ | ||
2924 | 0x26, 0x7b, 0x6b, 0x2f, 0xee, 0x80, 0x92, 0x2b, 0x14, 0xb2, | ||
2925 | 0xff, 0xb9, 0x0f, 0x04, 0xd4, 0xeb, 0x7c, 0x09, 0xb5, 0xd2, | ||
2926 | 0xd1, 0x5d, 0xf1, 0xd8, 0x52, 0x74, 0x1a, 0xf4, 0x70, 0x4a, | ||
2927 | 0x04, 0x58, 0x04, 0x7e, 0x80, 0xe4, 0x54, 0x6d, 0x35, 0xb8, | ||
2928 | 0x33, 0x6f, 0xac, 0x22, 0x4d, 0xd8, 0x16, 0x64, 0xbb, 0xf5, | ||
2929 | 0x28, 0xbe, 0x63, 0x73, | ||
2930 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* a */ | ||
2931 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, | ||
2932 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, | ||
2933 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, | ||
2934 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, | ||
2935 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, | ||
2936 | 0x00, 0x00, 0x00, 0x07, | ||
2937 | 0x1c, 0xff, 0x08, 0x06, 0xa3, 0x11, 0x16, 0xda, 0x29, 0xd8, /* b */ | ||
2938 | 0xcf, 0xa5, 0x4e, 0x57, 0xeb, 0x74, 0x8b, 0xc5, 0xf3, 0x77, | ||
2939 | 0xe4, 0x94, 0x00, 0xfd, 0xd7, 0x88, 0xb6, 0x49, 0xec, 0xa1, | ||
2940 | 0xac, 0x43, 0x61, 0x83, 0x40, 0x13, 0xb2, 0xad, 0x73, 0x22, | ||
2941 | 0x48, 0x0a, 0x89, 0xca, 0x58, 0xe0, 0xcf, 0x74, 0xbc, 0x9e, | ||
2942 | 0x54, 0x0c, 0x2a, 0xdd, 0x68, 0x97, 0xfa, 0xd0, 0xa3, 0x08, | ||
2943 | 0x4f, 0x30, 0x2a, 0xdc, | ||
2944 | 0x24, 0xd1, 0x9c, 0xc6, 0x45, 0x72, 0xee, 0x30, 0xf3, 0x96, /* x */ | ||
2945 | 0xbf, 0x6e, 0xbb, 0xfd, 0x7a, 0x6c, 0x52, 0x13, 0xb3, 0xb3, | ||
2946 | 0xd7, 0x05, 0x7c, 0xc8, 0x25, 0xf9, 0x10, 0x93, 0xa6, 0x8c, | ||
2947 | 0xd7, 0x62, 0xfd, 0x60, 0x61, 0x12, 0x62, 0xcd, 0x83, 0x8d, | ||
2948 | 0xc6, 0xb6, 0x0a, 0xa7, 0xee, 0xe8, 0x04, 0xe2, 0x8b, 0xc8, | ||
2949 | 0x49, 0x97, 0x7f, 0xac, 0x33, 0xb4, 0xb5, 0x30, 0xf1, 0xb1, | ||
2950 | 0x20, 0x24, 0x8a, 0x9a, | ||
2951 | 0x2b, 0xb3, 0x12, 0xa4, 0x3b, 0xd2, 0xce, 0x6e, 0x0d, 0x02, /* y */ | ||
2952 | 0x06, 0x13, 0xc8, 0x57, 0xac, 0xdd, 0xcf, 0xbf, 0x06, 0x1e, | ||
2953 | 0x91, 0xe5, 0xf2, 0xc3, 0xf3, 0x24, 0x47, 0xc2, 0x59, 0xf3, | ||
2954 | 0x9b, 0x2c, 0x83, 0xab, 0x15, 0x6d, 0x77, 0xf1, 0x49, 0x6b, | ||
2955 | 0xf7, 0xeb, 0x33, 0x51, 0xe1, 0xee, 0x4e, 0x43, 0xdc, 0x1a, | ||
2956 | 0x18, 0xb9, 0x1b, 0x24, 0x64, 0x0b, 0x6d, 0xbb, 0x92, 0xcb, | ||
2957 | 0x1a, 0xdd, 0x37, 0x1e, | ||
2958 | 0x45, 0x31, 0xac, 0xd1, 0xfe, 0x00, 0x23, 0xc7, 0x55, 0x0d, /* order */ | ||
2959 | 0x26, 0x7b, 0x6b, 0x2f, 0xee, 0x80, 0x92, 0x2b, 0x14, 0xb2, | ||
2960 | 0xff, 0xb9, 0x0f, 0x04, 0xd4, 0xeb, 0x7c, 0x09, 0xb5, 0xd2, | ||
2961 | 0xd1, 0x5d, 0xa8, 0x2f, 0x2d, 0x7e, 0xcb, 0x1d, 0xba, 0xc7, | ||
2962 | 0x19, 0x90, 0x5c, 0x5e, 0xec, 0xc4, 0x23, 0xf1, 0xd8, 0x6e, | ||
2963 | 0x25, 0xed, 0xbe, 0x23, 0xc5, 0x95, 0xd6, 0x44, 0xaa, 0xf1, | ||
2964 | 0x87, 0xe6, 0xe6, 0xdf, | ||
2965 | } | ||
2966 | }; | ||
2967 | |||
2968 | static const struct { | ||
2969 | EC_CURVE_DATA h; | ||
2970 | unsigned char data[0 + 64 * 6]; | ||
2971 | } | ||
2972 | _EC_GOST_2012_TC26_A = { | ||
2973 | { | ||
2974 | NID_X9_62_prime_field, 0, 64, 1 | ||
2975 | }, | ||
2976 | { /* no seed */ | ||
2977 | 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, /* p */ | ||
2978 | 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, | ||
2979 | 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, | ||
2980 | 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, | ||
2981 | 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, | ||
2982 | 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, | ||
2983 | 0xff, 0xff, 0xfd, 0xc7, | ||
2984 | 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, /* a */ | ||
2985 | 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, | ||
2986 | 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, | ||
2987 | 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, | ||
2988 | 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, | ||
2989 | 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, | ||
2990 | 0xff, 0xff, 0xfd, 0xc4, | ||
2991 | 0xe8, 0xc2, 0x50, 0x5d, 0xed, 0xfc, 0x86, 0xdd, 0xc1, 0xbd, /* b */ | ||
2992 | 0x0b, 0x2b, 0x66, 0x67, 0xf1, 0xda, 0x34, 0xb8, 0x25, 0x74, | ||
2993 | 0x76, 0x1c, 0xb0, 0xe8, 0x79, 0xbd, 0x08, 0x1c, 0xfd, 0x0b, | ||
2994 | 0x62, 0x65, 0xee, 0x3c, 0xb0, 0x90, 0xf3, 0x0d, 0x27, 0x61, | ||
2995 | 0x4c, 0xb4, 0x57, 0x40, 0x10, 0xda, 0x90, 0xdd, 0x86, 0x2e, | ||
2996 | 0xf9, 0xd4, 0xeb, 0xee, 0x47, 0x61, 0x50, 0x31, 0x90, 0x78, | ||
2997 | 0x5a, 0x71, 0xc7, 0x60, | ||
2998 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* x */ | ||
2999 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, | ||
3000 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, | ||
3001 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, | ||
3002 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, | ||
3003 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, | ||
3004 | 0x00, 0x00, 0x00, 0x03, | ||
3005 | 0x75, 0x03, 0xcf, 0xe8, 0x7a, 0x83, 0x6a, 0xe3, 0xa6, 0x1b, /* y */ | ||
3006 | 0x88, 0x16, 0xe2, 0x54, 0x50, 0xe6, 0xce, 0x5e, 0x1c, 0x93, | ||
3007 | 0xac, 0xf1, 0xab, 0xc1, 0x77, 0x80, 0x64, 0xfd, 0xcb, 0xef, | ||
3008 | 0xa9, 0x21, 0xdf, 0x16, 0x26, 0xbe, 0x4f, 0xd0, 0x36, 0xe9, | ||
3009 | 0x3d, 0x75, 0xe6, 0xa5, 0x0e, 0x3a, 0x41, 0xe9, 0x80, 0x28, | ||
3010 | 0xfe, 0x5f, 0xc2, 0x35, 0xf5, 0xb8, 0x89, 0xa5, 0x89, 0xcb, | ||
3011 | 0x52, 0x15, 0xf2, 0xa4, | ||
3012 | 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, /* order */ | ||
3013 | 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, | ||
3014 | 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, | ||
3015 | 0xff, 0xff, 0x27, 0xe6, 0x95, 0x32, 0xf4, 0x8d, 0x89, 0x11, | ||
3016 | 0x6f, 0xf2, 0x2b, 0x8d, 0x4e, 0x05, 0x60, 0x60, 0x9b, 0x4b, | ||
3017 | 0x38, 0xab, 0xfa, 0xd2, 0xb8, 0x5d, 0xca, 0xcd, 0xb1, 0x41, | ||
3018 | 0x1f, 0x10, 0xb2, 0x75 | ||
3019 | } | ||
3020 | }; | ||
3021 | |||
3022 | static const struct { | ||
3023 | EC_CURVE_DATA h; | ||
3024 | unsigned char data[0 + 64 * 6]; | ||
3025 | } | ||
3026 | _EC_GOST_2012_TC26_B = { | ||
3027 | { | ||
3028 | NID_X9_62_prime_field, 0, 64, 1 | ||
3029 | }, | ||
3030 | { /* no seed */ | ||
3031 | 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* p */ | ||
3032 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, | ||
3033 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, | ||
3034 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, | ||
3035 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, | ||
3036 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, | ||
3037 | 0x00, 0x00, 0x00, 0x6f, | ||
3038 | 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* a */ | ||
3039 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, | ||
3040 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, | ||
3041 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, | ||
3042 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, | ||
3043 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, | ||
3044 | 0x00, 0x00, 0x00, 0x6c, | ||
3045 | 0x68, 0x7d, 0x1b, 0x45, 0x9d, 0xc8, 0x41, 0x45, 0x7e, 0x3e, /* b */ | ||
3046 | 0x06, 0xcf, 0x6f, 0x5e, 0x25, 0x17, 0xb9, 0x7c, 0x7d, 0x61, | ||
3047 | 0x4a, 0xf1, 0x38, 0xbc, 0xbf, 0x85, 0xdc, 0x80, 0x6c, 0x4b, | ||
3048 | 0x28, 0x9f, 0x3e, 0x96, 0x5d, 0x2d, 0xb1, 0x41, 0x6d, 0x21, | ||
3049 | 0x7f, 0x8b, 0x27, 0x6f, 0xad, 0x1a, 0xb6, 0x9c, 0x50, 0xf7, | ||
3050 | 0x8b, 0xee, 0x1f, 0xa3, 0x10, 0x6e, 0xfb, 0x8c, 0xcb, 0xc7, | ||
3051 | 0xc5, 0x14, 0x01, 0x16, | ||
3052 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* x */ | ||
3053 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, | ||
3054 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, | ||
3055 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, | ||
3056 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, | ||
3057 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, | ||
3058 | 0x00, 0x00, 0x00, 0x02, | ||
3059 | 0x1a, 0x8f, 0x7e, 0xda, 0x38, 0x9b, 0x09, 0x4c, 0x2c, 0x07, /* y */ | ||
3060 | 0x1e, 0x36, 0x47, 0xa8, 0x94, 0x0f, 0x3c, 0x12, 0x3b, 0x69, | ||
3061 | 0x75, 0x78, 0xc2, 0x13, 0xbe, 0x6d, 0xd9, 0xe6, 0xc8, 0xec, | ||
3062 | 0x73, 0x35, 0xdc, 0xb2, 0x28, 0xfd, 0x1e, 0xdf, 0x4a, 0x39, | ||
3063 | 0x15, 0x2c, 0xbc, 0xaa, 0xf8, 0xc0, 0x39, 0x88, 0x28, 0x04, | ||
3064 | 0x10, 0x55, 0xf9, 0x4c, 0xee, 0xec, 0x7e, 0x21, 0x34, 0x07, | ||
3065 | 0x80, 0xfe, 0x41, 0xbd, | ||
3066 | 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* order */ | ||
3067 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, | ||
3068 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, | ||
3069 | 0x00, 0x01, 0x49, 0xa1, 0xec, 0x14, 0x25, 0x65, 0xa5, 0x45, | ||
3070 | 0xac, 0xfd, 0xb7, 0x7b, 0xd9, 0xd4, 0x0c, 0xfa, 0x8b, 0x99, | ||
3071 | 0x67, 0x12, 0x10, 0x1b, 0xea, 0x0e, 0xc6, 0x34, 0x6c, 0x54, | ||
3072 | 0x37, 0x4f, 0x25, 0xbd | ||
3073 | } | ||
3074 | }; | ||
3075 | |||
3076 | #endif | ||
3077 | |||
2769 | typedef struct _ec_list_element_st { | 3078 | typedef struct _ec_list_element_st { |
2770 | int nid; | 3079 | int nid; |
2771 | const EC_CURVE_DATA *data; | 3080 | const EC_CURVE_DATA *data; |
@@ -2890,7 +3199,18 @@ static const ec_list_element curve_list[] = { | |||
2890 | {NID_brainpoolP512r1, &_EC_brainpoolP512r1.h, 0, "RFC 5639 curve over a 512 bit prime field"}, | 3199 | {NID_brainpoolP512r1, &_EC_brainpoolP512r1.h, 0, "RFC 5639 curve over a 512 bit prime field"}, |
2891 | {NID_brainpoolP512t1, &_EC_brainpoolP512t1.h, 0, "RFC 5639 curve over a 512 bit prime field"}, | 3200 | {NID_brainpoolP512t1, &_EC_brainpoolP512t1.h, 0, "RFC 5639 curve over a 512 bit prime field"}, |
2892 | /* ANSSI */ | 3201 | /* ANSSI */ |
2893 | {NID_FRP256v1, &_EC_FRP256v1.h, 0, "FRP256v1"} | 3202 | {NID_FRP256v1, &_EC_FRP256v1.h, 0, "FRP256v1"}, |
3203 | #ifndef OPENSSL_NO_GOST | ||
3204 | /* GOST R 34.10-2001 */ | ||
3205 | {NID_id_GostR3410_2001_TestParamSet, &_EC_GOST_2001_Test.h, 0, "GOST R 34.10-2001 Test Curve"}, | ||
3206 | {NID_id_GostR3410_2001_CryptoPro_A_ParamSet, &_EC_GOST_2001_CryptoPro_A.h, 0, "GOST R 34.10-2001 CryptoPro-A"}, | ||
3207 | {NID_id_GostR3410_2001_CryptoPro_B_ParamSet, &_EC_GOST_2001_CryptoPro_B.h, 0, "GOST R 34.10-2001 CryptoPro-B"}, | ||
3208 | {NID_id_GostR3410_2001_CryptoPro_C_ParamSet, &_EC_GOST_2001_CryptoPro_C.h, 0, "GOST R 34.10-2001 CryptoPro-C"}, | ||
3209 | {NID_id_GostR3410_2001_CryptoPro_XchA_ParamSet, &_EC_GOST_2001_CryptoPro_A.h, 0, "GOST R 34.10-2001 CryptoPro-XchA"}, | ||
3210 | {NID_id_GostR3410_2001_CryptoPro_XchB_ParamSet, &_EC_GOST_2001_CryptoPro_C.h, 0, "GOST R 34.10-2001 CryptoPro-XchB"}, | ||
3211 | {NID_id_tc26_gost_3410_2012_512_paramSetA, &_EC_GOST_2012_TC26_A.h, 0, "GOST R 34.10-2012 TC26-A"}, | ||
3212 | {NID_id_tc26_gost_3410_2012_512_paramSetB, &_EC_GOST_2012_TC26_B.h, 0, "GOST R 34.10-2012 TC26-A"}, | ||
3213 | #endif | ||
2894 | }; | 3214 | }; |
2895 | 3215 | ||
2896 | #define curve_list_length (sizeof(curve_list)/sizeof(ec_list_element)) | 3216 | #define curve_list_length (sizeof(curve_list)/sizeof(ec_list_element)) |
diff --git a/src/lib/libssl/src/crypto/err/err.c b/src/lib/libssl/src/crypto/err/err.c index 75a1d0181e..f06320247c 100644 --- a/src/lib/libssl/src/crypto/err/err.c +++ b/src/lib/libssl/src/crypto/err/err.c | |||
@@ -1,4 +1,4 @@ | |||
1 | /* $OpenBSD: err.c,v 1.40 2014/10/05 15:21:48 deraadt Exp $ */ | 1 | /* $OpenBSD: err.c,v 1.41 2014/11/09 19:17:13 miod Exp $ */ |
2 | /* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) | 2 | /* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) |
3 | * All rights reserved. | 3 | * All rights reserved. |
4 | * | 4 | * |
@@ -157,6 +157,7 @@ static ERR_STRING_DATA ERR_str_libraries[] = { | |||
157 | {ERR_PACK(ERR_LIB_FIPS,0,0), "FIPS routines"}, | 157 | {ERR_PACK(ERR_LIB_FIPS,0,0), "FIPS routines"}, |
158 | {ERR_PACK(ERR_LIB_CMS,0,0), "CMS routines"}, | 158 | {ERR_PACK(ERR_LIB_CMS,0,0), "CMS routines"}, |
159 | {ERR_PACK(ERR_LIB_HMAC,0,0), "HMAC routines"}, | 159 | {ERR_PACK(ERR_LIB_HMAC,0,0), "HMAC routines"}, |
160 | {ERR_PACK(ERR_LIB_GOST,0,0), "GOST routines"}, | ||
160 | {0, NULL}, | 161 | {0, NULL}, |
161 | }; | 162 | }; |
162 | 163 | ||
diff --git a/src/lib/libssl/src/crypto/err/err.h b/src/lib/libssl/src/crypto/err/err.h index ced340ea80..87bb96eec7 100644 --- a/src/lib/libssl/src/crypto/err/err.h +++ b/src/lib/libssl/src/crypto/err/err.h | |||
@@ -1,4 +1,4 @@ | |||
1 | /* $OpenBSD: err.h,v 1.21 2014/07/11 09:25:24 jsing Exp $ */ | 1 | /* $OpenBSD: err.h,v 1.22 2014/11/09 19:17:13 miod Exp $ */ |
2 | /* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) | 2 | /* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) |
3 | * All rights reserved. | 3 | * All rights reserved. |
4 | * | 4 | * |
@@ -195,6 +195,7 @@ typedef struct err_state_st { | |||
195 | #define ERR_LIB_TS 47 | 195 | #define ERR_LIB_TS 47 |
196 | #define ERR_LIB_HMAC 48 | 196 | #define ERR_LIB_HMAC 48 |
197 | #define ERR_LIB_JPAKE 49 | 197 | #define ERR_LIB_JPAKE 49 |
198 | #define ERR_LIB_GOST 50 | ||
198 | 199 | ||
199 | #define ERR_LIB_USER 128 | 200 | #define ERR_LIB_USER 128 |
200 | 201 | ||
@@ -231,6 +232,7 @@ typedef struct err_state_st { | |||
231 | #define TSerr(f,r) ERR_PUT_error(ERR_LIB_TS,(f),(r),__FILE__,__LINE__) | 232 | #define TSerr(f,r) ERR_PUT_error(ERR_LIB_TS,(f),(r),__FILE__,__LINE__) |
232 | #define HMACerr(f,r) ERR_PUT_error(ERR_LIB_HMAC,(f),(r),__FILE__,__LINE__) | 233 | #define HMACerr(f,r) ERR_PUT_error(ERR_LIB_HMAC,(f),(r),__FILE__,__LINE__) |
233 | #define JPAKEerr(f,r) ERR_PUT_error(ERR_LIB_JPAKE,(f),(r),__FILE__,__LINE__) | 234 | #define JPAKEerr(f,r) ERR_PUT_error(ERR_LIB_JPAKE,(f),(r),__FILE__,__LINE__) |
235 | #define GOSTerr(f,r) ERR_PUT_error(ERR_LIB_GOST,(f),(r),__FILE__,__LINE__) | ||
234 | 236 | ||
235 | #define ERR_PACK(l,f,r) (((((unsigned long)l)&0xffL)<<24L)| \ | 237 | #define ERR_PACK(l,f,r) (((((unsigned long)l)&0xffL)<<24L)| \ |
236 | ((((unsigned long)f)&0xfffL)<<12L)| \ | 238 | ((((unsigned long)f)&0xfffL)<<12L)| \ |
diff --git a/src/lib/libssl/src/crypto/err/err_all.c b/src/lib/libssl/src/crypto/err/err_all.c index 7362220824..c880f1fbf3 100644 --- a/src/lib/libssl/src/crypto/err/err_all.c +++ b/src/lib/libssl/src/crypto/err/err_all.c | |||
@@ -1,4 +1,4 @@ | |||
1 | /* $OpenBSD: err_all.c,v 1.18 2014/10/18 17:08:32 jsing Exp $ */ | 1 | /* $OpenBSD: err_all.c,v 1.19 2014/11/09 19:17:13 miod Exp $ */ |
2 | /* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) | 2 | /* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) |
3 | * All rights reserved. | 3 | * All rights reserved. |
4 | * | 4 | * |
@@ -105,6 +105,9 @@ | |||
105 | #ifndef OPENSSL_NO_RSA | 105 | #ifndef OPENSSL_NO_RSA |
106 | #include <openssl/rsa.h> | 106 | #include <openssl/rsa.h> |
107 | #endif | 107 | #endif |
108 | #ifndef OPENSSL_NO_GOST | ||
109 | #include <openssl/gost.h> | ||
110 | #endif | ||
108 | 111 | ||
109 | void | 112 | void |
110 | ERR_load_crypto_strings(void) | 113 | ERR_load_crypto_strings(void) |
@@ -157,5 +160,8 @@ ERR_load_crypto_strings(void) | |||
157 | #ifndef OPENSSL_NO_CMS | 160 | #ifndef OPENSSL_NO_CMS |
158 | ERR_load_CMS_strings(); | 161 | ERR_load_CMS_strings(); |
159 | #endif | 162 | #endif |
163 | #ifndef OPENSSL_NO_GOST | ||
164 | ERR_load_GOST_strings(); | ||
165 | #endif | ||
160 | #endif | 166 | #endif |
161 | } | 167 | } |
diff --git a/src/lib/libssl/src/crypto/err/openssl.ec b/src/lib/libssl/src/crypto/err/openssl.ec index c513734e94..dcebbba6c4 100644 --- a/src/lib/libssl/src/crypto/err/openssl.ec +++ b/src/lib/libssl/src/crypto/err/openssl.ec | |||
@@ -34,6 +34,7 @@ L STORE crypto/store/store.h crypto/store/str_err.c | |||
34 | L TS crypto/ts/ts.h crypto/ts/ts_err.c | 34 | L TS crypto/ts/ts.h crypto/ts/ts_err.c |
35 | L HMAC crypto/hmac/hmac.h crypto/hmac/hmac_err.c | 35 | L HMAC crypto/hmac/hmac.h crypto/hmac/hmac_err.c |
36 | L CMS crypto/cms/cms.h crypto/cms/cms_err.c | 36 | L CMS crypto/cms/cms.h crypto/cms/cms_err.c |
37 | L GOST crypto/gost/gost.h crypto/gost/gost_err.c | ||
37 | 38 | ||
38 | # additional header files to be scanned for function names | 39 | # additional header files to be scanned for function names |
39 | L NONE crypto/x509/x509_vfy.h NONE | 40 | L NONE crypto/x509/x509_vfy.h NONE |
diff --git a/src/lib/libssl/src/crypto/evp/c_allc.c b/src/lib/libssl/src/crypto/evp/c_allc.c index 657e14f86f..26a5cc6179 100644 --- a/src/lib/libssl/src/crypto/evp/c_allc.c +++ b/src/lib/libssl/src/crypto/evp/c_allc.c | |||
@@ -1,4 +1,4 @@ | |||
1 | /* $OpenBSD: c_allc.c,v 1.13 2014/07/11 08:44:48 jsing Exp $ */ | 1 | /* $OpenBSD: c_allc.c,v 1.14 2014/11/09 19:17:13 miod Exp $ */ |
2 | /* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) | 2 | /* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) |
3 | * All rights reserved. | 3 | * All rights reserved. |
4 | * | 4 | * |
@@ -225,4 +225,10 @@ OpenSSL_add_all_ciphers(void) | |||
225 | #ifndef OPENSSL_NO_CHACHA | 225 | #ifndef OPENSSL_NO_CHACHA |
226 | EVP_add_cipher(EVP_chacha20()); | 226 | EVP_add_cipher(EVP_chacha20()); |
227 | #endif | 227 | #endif |
228 | |||
229 | #ifndef OPENSSL_NO_GOST | ||
230 | EVP_add_cipher(EVP_gost2814789_ecb()); | ||
231 | EVP_add_cipher(EVP_gost2814789_cfb64()); | ||
232 | EVP_add_cipher(EVP_gost2814789_cnt()); | ||
233 | #endif | ||
228 | } | 234 | } |
diff --git a/src/lib/libssl/src/crypto/evp/c_alld.c b/src/lib/libssl/src/crypto/evp/c_alld.c index 8f59100caa..99da8acdae 100644 --- a/src/lib/libssl/src/crypto/evp/c_alld.c +++ b/src/lib/libssl/src/crypto/evp/c_alld.c | |||
@@ -1,4 +1,4 @@ | |||
1 | /* $OpenBSD: c_alld.c,v 1.11 2014/07/11 08:44:48 jsing Exp $ */ | 1 | /* $OpenBSD: c_alld.c,v 1.12 2014/11/09 19:17:13 miod Exp $ */ |
2 | /* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) | 2 | /* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) |
3 | * All rights reserved. | 3 | * All rights reserved. |
4 | * | 4 | * |
@@ -95,6 +95,12 @@ OpenSSL_add_all_digests(void) | |||
95 | EVP_add_digest(EVP_ecdsa()); | 95 | EVP_add_digest(EVP_ecdsa()); |
96 | #endif | 96 | #endif |
97 | #endif | 97 | #endif |
98 | #ifndef OPENSSL_NO_GOST | ||
99 | EVP_add_digest(EVP_gostr341194()); | ||
100 | EVP_add_digest(EVP_gost2814789imit()); | ||
101 | EVP_add_digest(EVP_streebog256()); | ||
102 | EVP_add_digest(EVP_streebog512()); | ||
103 | #endif | ||
98 | #if !defined(OPENSSL_NO_MDC2) && !defined(OPENSSL_NO_DES) | 104 | #if !defined(OPENSSL_NO_MDC2) && !defined(OPENSSL_NO_DES) |
99 | EVP_add_digest(EVP_mdc2()); | 105 | EVP_add_digest(EVP_mdc2()); |
100 | #endif | 106 | #endif |
diff --git a/src/lib/libssl/src/crypto/evp/e_gost2814789.c b/src/lib/libssl/src/crypto/evp/e_gost2814789.c new file mode 100644 index 0000000000..678c7af09d --- /dev/null +++ b/src/lib/libssl/src/crypto/evp/e_gost2814789.c | |||
@@ -0,0 +1,216 @@ | |||
1 | /* $OpenBSD: e_gost2814789.c,v 1.1 2014/11/09 19:17:13 miod Exp $ */ | ||
2 | /* | ||
3 | * Copyright (c) 2014 Dmitry Eremin-Solenikov <dbaryshkov@gmail.com> | ||
4 | * Copyright (c) 2005-2006 Cryptocom LTD | ||
5 | * | ||
6 | * Redistribution and use in source and binary forms, with or without | ||
7 | * modification, are permitted provided that the following conditions | ||
8 | * are met: | ||
9 | * | ||
10 | * 1. Redistributions of source code must retain the above copyright | ||
11 | * notice, this list of conditions and the following disclaimer. | ||
12 | * | ||
13 | * 2. Redistributions in binary form must reproduce the above copyright | ||
14 | * notice, this list of conditions and the following disclaimer in | ||
15 | * the documentation and/or other materials provided with the | ||
16 | * distribution. | ||
17 | * | ||
18 | * 3. All advertising materials mentioning features or use of this | ||
19 | * software must display the following acknowledgment: | ||
20 | * "This product includes software developed by the OpenSSL Project | ||
21 | * for use in the OpenSSL Toolkit. (http://www.openssl.org/)" | ||
22 | * | ||
23 | * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to | ||
24 | * endorse or promote products derived from this software without | ||
25 | * prior written permission. For written permission, please contact | ||
26 | * openssl-core@openssl.org. | ||
27 | * | ||
28 | * 5. Products derived from this software may not be called "OpenSSL" | ||
29 | * nor may "OpenSSL" appear in their names without prior written | ||
30 | * permission of the OpenSSL Project. | ||
31 | * | ||
32 | * 6. Redistributions of any form whatsoever must retain the following | ||
33 | * acknowledgment: | ||
34 | * "This product includes software developed by the OpenSSL Project | ||
35 | * for use in the OpenSSL Toolkit (http://www.openssl.org/)" | ||
36 | * | ||
37 | * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY | ||
38 | * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | ||
39 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR | ||
40 | * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR | ||
41 | * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, | ||
42 | * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT | ||
43 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; | ||
44 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | ||
45 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, | ||
46 | * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) | ||
47 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED | ||
48 | * OF THE POSSIBILITY OF SUCH DAMAGE. | ||
49 | * ==================================================================== | ||
50 | */ | ||
51 | #include <string.h> | ||
52 | |||
53 | #include <openssl/opensslconf.h> | ||
54 | |||
55 | #ifndef OPENSSL_NO_GOST | ||
56 | #include <openssl/evp.h> | ||
57 | #include <openssl/err.h> | ||
58 | #include <openssl/gost.h> | ||
59 | #include "evp_locl.h" | ||
60 | |||
61 | typedef struct { | ||
62 | GOST2814789_KEY ks; | ||
63 | int param_nid; | ||
64 | } EVP_GOST2814789_CTX; | ||
65 | |||
66 | static int gost2814789_ctl(EVP_CIPHER_CTX *ctx,int type,int arg,void *ptr) | ||
67 | { | ||
68 | EVP_GOST2814789_CTX *c = ctx->cipher_data; | ||
69 | |||
70 | switch (type) { | ||
71 | case EVP_CTRL_PBE_PRF_NID: | ||
72 | if (ptr) { | ||
73 | *((int *)ptr) = NID_id_HMACGostR3411_94; | ||
74 | return 1; | ||
75 | } else { | ||
76 | return 0; | ||
77 | } | ||
78 | case EVP_CTRL_INIT: | ||
79 | /* Default value to have any s-box set at all */ | ||
80 | c->param_nid = NID_id_Gost28147_89_CryptoPro_A_ParamSet; | ||
81 | return Gost2814789_set_sbox(&c->ks, c->param_nid); | ||
82 | case EVP_CTRL_GOST_SET_SBOX: | ||
83 | return Gost2814789_set_sbox(&c->ks, arg); | ||
84 | default: | ||
85 | return -1; | ||
86 | } | ||
87 | } | ||
88 | |||
89 | static int gost2814789_init_key(EVP_CIPHER_CTX *ctx, const unsigned char *key, | ||
90 | const unsigned char *iv, int enc) | ||
91 | { | ||
92 | EVP_GOST2814789_CTX *c = ctx->cipher_data; | ||
93 | |||
94 | return Gost2814789_set_key(&c->ks, key, ctx->key_len * 8); | ||
95 | } | ||
96 | |||
97 | int gost2814789_set_asn1_params(EVP_CIPHER_CTX * ctx, ASN1_TYPE * params) | ||
98 | { | ||
99 | int len = 0; | ||
100 | unsigned char *buf = NULL; | ||
101 | unsigned char *p = NULL; | ||
102 | EVP_GOST2814789_CTX *c = ctx->cipher_data; | ||
103 | GOST_CIPHER_PARAMS *gcp = GOST_CIPHER_PARAMS_new(); | ||
104 | ASN1_OCTET_STRING *os = NULL; | ||
105 | if (!gcp) { | ||
106 | GOSTerr(GOST_F_GOST89_SET_ASN1_PARAMETERS, ERR_R_MALLOC_FAILURE); | ||
107 | return 0; | ||
108 | } | ||
109 | if (!ASN1_OCTET_STRING_set(gcp->iv, ctx->iv, ctx->cipher->iv_len)) { | ||
110 | GOST_CIPHER_PARAMS_free(gcp); | ||
111 | GOSTerr(GOST_F_GOST89_SET_ASN1_PARAMETERS, ERR_R_ASN1_LIB); | ||
112 | return 0; | ||
113 | } | ||
114 | ASN1_OBJECT_free(gcp->enc_param_set); | ||
115 | gcp->enc_param_set = OBJ_nid2obj(c->param_nid); | ||
116 | |||
117 | len = i2d_GOST_CIPHER_PARAMS(gcp, NULL); | ||
118 | p = buf = malloc(len); | ||
119 | if (!buf) { | ||
120 | GOST_CIPHER_PARAMS_free(gcp); | ||
121 | GOSTerr(GOST_F_GOST89_SET_ASN1_PARAMETERS, ERR_R_MALLOC_FAILURE); | ||
122 | return 0; | ||
123 | } | ||
124 | i2d_GOST_CIPHER_PARAMS(gcp, &p); | ||
125 | GOST_CIPHER_PARAMS_free(gcp); | ||
126 | |||
127 | os = ASN1_OCTET_STRING_new(); | ||
128 | |||
129 | if (!os || !ASN1_OCTET_STRING_set(os, buf, len)) { | ||
130 | free(buf); | ||
131 | GOSTerr(GOST_F_GOST89_SET_ASN1_PARAMETERS, ERR_R_ASN1_LIB); | ||
132 | return 0; | ||
133 | } | ||
134 | free(buf); | ||
135 | |||
136 | ASN1_TYPE_set(params, V_ASN1_SEQUENCE, os); | ||
137 | return 1; | ||
138 | } | ||
139 | |||
140 | int gost2814789_get_asn1_params(EVP_CIPHER_CTX * ctx, ASN1_TYPE * params) | ||
141 | { | ||
142 | int ret = -1; | ||
143 | int len; | ||
144 | GOST_CIPHER_PARAMS *gcp = NULL; | ||
145 | EVP_GOST2814789_CTX *c = ctx->cipher_data; | ||
146 | unsigned char *p; | ||
147 | |||
148 | if (ASN1_TYPE_get(params) != V_ASN1_SEQUENCE) { | ||
149 | return ret; | ||
150 | } | ||
151 | |||
152 | p = params->value.sequence->data; | ||
153 | |||
154 | gcp = d2i_GOST_CIPHER_PARAMS(NULL, (const unsigned char **)&p, | ||
155 | params->value.sequence->length); | ||
156 | |||
157 | len = gcp->iv->length; | ||
158 | if (len != ctx->cipher->iv_len) { | ||
159 | GOST_CIPHER_PARAMS_free(gcp); | ||
160 | GOSTerr(GOST_F_GOST89_GET_ASN1_PARAMETERS, | ||
161 | GOST_R_INVALID_IV_LENGTH); | ||
162 | return -1; | ||
163 | } | ||
164 | |||
165 | if (!Gost2814789_set_sbox(&c->ks, OBJ_obj2nid(gcp->enc_param_set))) { | ||
166 | GOST_CIPHER_PARAMS_free(gcp); | ||
167 | return -1; | ||
168 | } | ||
169 | c->param_nid = OBJ_obj2nid(gcp->enc_param_set); | ||
170 | |||
171 | memcpy(ctx->oiv, gcp->iv->data, len); | ||
172 | memcpy(ctx->iv, gcp->iv->data, len); | ||
173 | |||
174 | GOST_CIPHER_PARAMS_free(gcp); | ||
175 | |||
176 | return 1; | ||
177 | } | ||
178 | |||
179 | BLOCK_CIPHER_func_ecb(gost2814789, Gost2814789, EVP_GOST2814789_CTX, ks) | ||
180 | BLOCK_CIPHER_func_cfb(gost2814789, Gost2814789, 64, EVP_GOST2814789_CTX, ks) | ||
181 | |||
182 | static int gost2814789_cnt_cipher(EVP_CIPHER_CTX * ctx, unsigned char *out, | ||
183 | const unsigned char *in, size_t inl) | ||
184 | { | ||
185 | EVP_GOST2814789_CTX *c = ctx->cipher_data; | ||
186 | |||
187 | while (inl >= EVP_MAXCHUNK) { | ||
188 | Gost2814789_cnt_encrypt(in, out, (long)EVP_MAXCHUNK, &c->ks, | ||
189 | ctx->iv, ctx->buf, &ctx->num); | ||
190 | inl -= EVP_MAXCHUNK; | ||
191 | in += EVP_MAXCHUNK; | ||
192 | out += EVP_MAXCHUNK; | ||
193 | } | ||
194 | |||
195 | if (inl) | ||
196 | Gost2814789_cnt_encrypt(in, out, inl, &c->ks, | ||
197 | ctx->iv, ctx->buf, &ctx->num); | ||
198 | return 1; | ||
199 | } | ||
200 | |||
201 | /* gost89 is CFB-64 */ | ||
202 | #define NID_gost89_cfb64 NID_id_Gost28147_89 | ||
203 | |||
204 | BLOCK_CIPHER_def_ecb(gost2814789, EVP_GOST2814789_CTX, NID_gost89, 8, 32, | ||
205 | EVP_CIPH_NO_PADDING | EVP_CIPH_CTRL_INIT, | ||
206 | gost2814789_init_key, NULL, gost2814789_set_asn1_params, | ||
207 | gost2814789_get_asn1_params, gost2814789_ctl) | ||
208 | BLOCK_CIPHER_def_cfb(gost2814789, EVP_GOST2814789_CTX, NID_gost89, 32, 8, 64, | ||
209 | EVP_CIPH_NO_PADDING | EVP_CIPH_CTRL_INIT, | ||
210 | gost2814789_init_key, NULL, gost2814789_set_asn1_params, | ||
211 | gost2814789_get_asn1_params, gost2814789_ctl) | ||
212 | BLOCK_CIPHER_def1(gost2814789, cnt, cnt, OFB, EVP_GOST2814789_CTX, NID_gost89, | ||
213 | 1, 32, 8, EVP_CIPH_NO_PADDING | EVP_CIPH_CTRL_INIT, | ||
214 | gost2814789_init_key, NULL, gost2814789_set_asn1_params, | ||
215 | gost2814789_get_asn1_params, gost2814789_ctl) | ||
216 | #endif | ||
diff --git a/src/lib/libssl/src/crypto/evp/evp.h b/src/lib/libssl/src/crypto/evp/evp.h index 9de7c3f9ef..6c1bf6c7cd 100644 --- a/src/lib/libssl/src/crypto/evp/evp.h +++ b/src/lib/libssl/src/crypto/evp/evp.h | |||
@@ -1,4 +1,4 @@ | |||
1 | /* $OpenBSD: evp.h,v 1.39 2014/07/11 15:28:27 tedu Exp $ */ | 1 | /* $OpenBSD: evp.h,v 1.40 2014/11/09 19:17:13 miod Exp $ */ |
2 | /* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) | 2 | /* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) |
3 | * All rights reserved. | 3 | * All rights reserved. |
4 | * | 4 | * |
@@ -107,8 +107,12 @@ | |||
107 | #define EVP_PKEY_DSA4 NID_dsaWithSHA1_2 | 107 | #define EVP_PKEY_DSA4 NID_dsaWithSHA1_2 |
108 | #define EVP_PKEY_DH NID_dhKeyAgreement | 108 | #define EVP_PKEY_DH NID_dhKeyAgreement |
109 | #define EVP_PKEY_EC NID_X9_62_id_ecPublicKey | 109 | #define EVP_PKEY_EC NID_X9_62_id_ecPublicKey |
110 | #define EVP_PKEY_GOSTR01 NID_id_GostR3410_2001 | ||
111 | #define EVP_PKEY_GOSTIMIT NID_id_Gost28147_89_MAC | ||
110 | #define EVP_PKEY_HMAC NID_hmac | 112 | #define EVP_PKEY_HMAC NID_hmac |
111 | #define EVP_PKEY_CMAC NID_cmac | 113 | #define EVP_PKEY_CMAC NID_cmac |
114 | #define EVP_PKEY_GOSTR12_256 NID_id_tc26_gost3410_2012_256 | ||
115 | #define EVP_PKEY_GOSTR12_512 NID_id_tc26_gost3410_2012_512 | ||
112 | 116 | ||
113 | #ifdef __cplusplus | 117 | #ifdef __cplusplus |
114 | extern "C" { | 118 | extern "C" { |
@@ -137,6 +141,9 @@ struct evp_pkey_st { | |||
137 | #ifndef OPENSSL_NO_EC | 141 | #ifndef OPENSSL_NO_EC |
138 | struct ec_key_st *ec; /* ECC */ | 142 | struct ec_key_st *ec; /* ECC */ |
139 | #endif | 143 | #endif |
144 | #ifndef OPENSSL_NO_GOST | ||
145 | struct gost_key_st *gost; /* GOST */ | ||
146 | #endif | ||
140 | } pkey; | 147 | } pkey; |
141 | int save_parameters; | 148 | int save_parameters; |
142 | STACK_OF(X509_ATTRIBUTE) *attributes; /* [ 0 ] */ | 149 | STACK_OF(X509_ATTRIBUTE) *attributes; /* [ 0 ] */ |
@@ -213,6 +220,8 @@ typedef int evp_verify_method(int type, const unsigned char *m, | |||
213 | 220 | ||
214 | #define EVP_MD_CTRL_DIGALGID 0x1 | 221 | #define EVP_MD_CTRL_DIGALGID 0x1 |
215 | #define EVP_MD_CTRL_MICALG 0x2 | 222 | #define EVP_MD_CTRL_MICALG 0x2 |
223 | #define EVP_MD_CTRL_SET_KEY 0x3 | ||
224 | #define EVP_MD_CTRL_GOST_SET_SBOX 0x4 | ||
216 | 225 | ||
217 | /* Minimum Algorithm specific ctrl value */ | 226 | /* Minimum Algorithm specific ctrl value */ |
218 | 227 | ||
@@ -381,6 +390,8 @@ struct evp_cipher_st { | |||
381 | #define EVP_CTRL_AEAD_SET_MAC_KEY 0x17 | 390 | #define EVP_CTRL_AEAD_SET_MAC_KEY 0x17 |
382 | /* Set the GCM invocation field, decrypt only */ | 391 | /* Set the GCM invocation field, decrypt only */ |
383 | #define EVP_CTRL_GCM_SET_IV_INV 0x18 | 392 | #define EVP_CTRL_GCM_SET_IV_INV 0x18 |
393 | /* Set the S-BOX NID for GOST ciphers */ | ||
394 | #define EVP_CTRL_GOST_SET_SBOX 0x19 | ||
384 | 395 | ||
385 | /* GCM TLS constants */ | 396 | /* GCM TLS constants */ |
386 | /* Length of fixed part of IV derived from PRF */ | 397 | /* Length of fixed part of IV derived from PRF */ |
@@ -451,6 +462,11 @@ typedef int (EVP_PBE_KEYGEN)(EVP_CIPHER_CTX *ctx, const char *pass, int passlen, | |||
451 | (char *)(eckey)) | 462 | (char *)(eckey)) |
452 | #endif | 463 | #endif |
453 | 464 | ||
465 | #ifndef OPENSSL_NO_GOST | ||
466 | #define EVP_PKEY_assign_GOST(pkey,gostkey) EVP_PKEY_assign((pkey),EVP_PKEY_GOSTR01,\ | ||
467 | (char *)(gostkey)) | ||
468 | #endif | ||
469 | |||
454 | /* Add some extra combinations */ | 470 | /* Add some extra combinations */ |
455 | #define EVP_get_digestbynid(a) EVP_get_digestbyname(OBJ_nid2sn(a)) | 471 | #define EVP_get_digestbynid(a) EVP_get_digestbyname(OBJ_nid2sn(a)) |
456 | #define EVP_get_digestbyobj(a) EVP_get_digestbynid(OBJ_obj2nid(a)) | 472 | #define EVP_get_digestbyobj(a) EVP_get_digestbynid(OBJ_obj2nid(a)) |
@@ -530,6 +546,7 @@ void EVP_MD_CTX_destroy(EVP_MD_CTX *ctx); | |||
530 | int EVP_MD_CTX_copy_ex(EVP_MD_CTX *out, const EVP_MD_CTX *in); | 546 | int EVP_MD_CTX_copy_ex(EVP_MD_CTX *out, const EVP_MD_CTX *in); |
531 | void EVP_MD_CTX_set_flags(EVP_MD_CTX *ctx, int flags); | 547 | void EVP_MD_CTX_set_flags(EVP_MD_CTX *ctx, int flags); |
532 | void EVP_MD_CTX_clear_flags(EVP_MD_CTX *ctx, int flags); | 548 | void EVP_MD_CTX_clear_flags(EVP_MD_CTX *ctx, int flags); |
549 | int EVP_MD_CTX_ctrl(EVP_MD_CTX *ctx, int type, int arg, void *ptr); | ||
533 | int EVP_MD_CTX_test_flags(const EVP_MD_CTX *ctx, int flags); | 550 | int EVP_MD_CTX_test_flags(const EVP_MD_CTX *ctx, int flags); |
534 | int EVP_DigestInit_ex(EVP_MD_CTX *ctx, const EVP_MD *type, ENGINE *impl); | 551 | int EVP_DigestInit_ex(EVP_MD_CTX *ctx, const EVP_MD *type, ENGINE *impl); |
535 | int EVP_DigestUpdate(EVP_MD_CTX *ctx, const void *d, size_t cnt); | 552 | int EVP_DigestUpdate(EVP_MD_CTX *ctx, const void *d, size_t cnt); |
@@ -665,6 +682,12 @@ const EVP_MD *EVP_ripemd160(void); | |||
665 | #ifndef OPENSSL_NO_WHIRLPOOL | 682 | #ifndef OPENSSL_NO_WHIRLPOOL |
666 | const EVP_MD *EVP_whirlpool(void); | 683 | const EVP_MD *EVP_whirlpool(void); |
667 | #endif | 684 | #endif |
685 | #ifndef OPENSSL_NO_GOST | ||
686 | const EVP_MD *EVP_gostr341194(void); | ||
687 | const EVP_MD *EVP_gost2814789imit(void); | ||
688 | const EVP_MD *EVP_streebog256(void); | ||
689 | const EVP_MD *EVP_streebog512(void); | ||
690 | #endif | ||
668 | const EVP_CIPHER *EVP_enc_null(void); /* does nothing :-) */ | 691 | const EVP_CIPHER *EVP_enc_null(void); /* does nothing :-) */ |
669 | #ifndef OPENSSL_NO_DES | 692 | #ifndef OPENSSL_NO_DES |
670 | const EVP_CIPHER *EVP_des_ecb(void); | 693 | const EVP_CIPHER *EVP_des_ecb(void); |
@@ -804,6 +827,12 @@ const EVP_CIPHER *EVP_camellia_256_ofb(void); | |||
804 | const EVP_CIPHER *EVP_chacha20(void); | 827 | const EVP_CIPHER *EVP_chacha20(void); |
805 | #endif | 828 | #endif |
806 | 829 | ||
830 | #ifndef OPENSSL_NO_GOST | ||
831 | const EVP_CIPHER *EVP_gost2814789_ecb(void); | ||
832 | const EVP_CIPHER *EVP_gost2814789_cfb64(void); | ||
833 | const EVP_CIPHER *EVP_gost2814789_cnt(void); | ||
834 | #endif | ||
835 | |||
807 | void OPENSSL_add_all_algorithms_noconf(void); | 836 | void OPENSSL_add_all_algorithms_noconf(void); |
808 | void OPENSSL_add_all_algorithms_conf(void); | 837 | void OPENSSL_add_all_algorithms_conf(void); |
809 | 838 | ||
@@ -871,6 +900,9 @@ struct ec_key_st; | |||
871 | int EVP_PKEY_set1_EC_KEY(EVP_PKEY *pkey, struct ec_key_st *key); | 900 | int EVP_PKEY_set1_EC_KEY(EVP_PKEY *pkey, struct ec_key_st *key); |
872 | struct ec_key_st *EVP_PKEY_get1_EC_KEY(EVP_PKEY *pkey); | 901 | struct ec_key_st *EVP_PKEY_get1_EC_KEY(EVP_PKEY *pkey); |
873 | #endif | 902 | #endif |
903 | #ifndef OPENSSL_NO_GOST | ||
904 | struct gost_key_st; | ||
905 | #endif | ||
874 | 906 | ||
875 | EVP_PKEY *EVP_PKEY_new(void); | 907 | EVP_PKEY *EVP_PKEY_new(void); |
876 | void EVP_PKEY_free(EVP_PKEY *pkey); | 908 | void EVP_PKEY_free(EVP_PKEY *pkey); |
@@ -1337,6 +1369,7 @@ void ERR_load_EVP_strings(void); | |||
1337 | #define EVP_F_EVP_DIGESTINIT_EX 128 | 1369 | #define EVP_F_EVP_DIGESTINIT_EX 128 |
1338 | #define EVP_F_EVP_ENCRYPTFINAL_EX 127 | 1370 | #define EVP_F_EVP_ENCRYPTFINAL_EX 127 |
1339 | #define EVP_F_EVP_MD_CTX_COPY_EX 110 | 1371 | #define EVP_F_EVP_MD_CTX_COPY_EX 110 |
1372 | #define EVP_F_EVP_MD_CTX_CTRL 195 | ||
1340 | #define EVP_F_EVP_MD_SIZE 162 | 1373 | #define EVP_F_EVP_MD_SIZE 162 |
1341 | #define EVP_F_EVP_OPENINIT 102 | 1374 | #define EVP_F_EVP_OPENINIT 102 |
1342 | #define EVP_F_EVP_PBE_ALG_ADD 115 | 1375 | #define EVP_F_EVP_PBE_ALG_ADD 115 |
diff --git a/src/lib/libssl/src/crypto/evp/m_gost2814789.c b/src/lib/libssl/src/crypto/evp/m_gost2814789.c new file mode 100644 index 0000000000..ff3f489e46 --- /dev/null +++ b/src/lib/libssl/src/crypto/evp/m_gost2814789.c | |||
@@ -0,0 +1,105 @@ | |||
1 | /* $OpenBSD: m_gost2814789.c,v 1.1 2014/11/09 19:17:13 miod Exp $ */ | ||
2 | /* | ||
3 | * Copyright (c) 2014 Dmitry Eremin-Solenikov <dbaryshkov@gmail.com> | ||
4 | * Copyright (c) 2005-2006 Cryptocom LTD | ||
5 | * | ||
6 | * Redistribution and use in source and binary forms, with or without | ||
7 | * modification, are permitted provided that the following conditions | ||
8 | * are met: | ||
9 | * | ||
10 | * 1. Redistributions of source code must retain the above copyright | ||
11 | * notice, this list of conditions and the following disclaimer. | ||
12 | * | ||
13 | * 2. Redistributions in binary form must reproduce the above copyright | ||
14 | * notice, this list of conditions and the following disclaimer in | ||
15 | * the documentation and/or other materials provided with the | ||
16 | * distribution. | ||
17 | * | ||
18 | * 3. All advertising materials mentioning features or use of this | ||
19 | * software must display the following acknowledgment: | ||
20 | * "This product includes software developed by the OpenSSL Project | ||
21 | * for use in the OpenSSL Toolkit. (http://www.openssl.org/)" | ||
22 | * | ||
23 | * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to | ||
24 | * endorse or promote products derived from this software without | ||
25 | * prior written permission. For written permission, please contact | ||
26 | * openssl-core@openssl.org. | ||
27 | * | ||
28 | * 5. Products derived from this software may not be called "OpenSSL" | ||
29 | * nor may "OpenSSL" appear in their names without prior written | ||
30 | * permission of the OpenSSL Project. | ||
31 | * | ||
32 | * 6. Redistributions of any form whatsoever must retain the following | ||
33 | * acknowledgment: | ||
34 | * "This product includes software developed by the OpenSSL Project | ||
35 | * for use in the OpenSSL Toolkit (http://www.openssl.org/)" | ||
36 | * | ||
37 | * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY | ||
38 | * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | ||
39 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR | ||
40 | * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR | ||
41 | * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, | ||
42 | * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT | ||
43 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; | ||
44 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | ||
45 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, | ||
46 | * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) | ||
47 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED | ||
48 | * OF THE POSSIBILITY OF SUCH DAMAGE. | ||
49 | * ==================================================================== | ||
50 | */ | ||
51 | #include <openssl/opensslconf.h> | ||
52 | |||
53 | #ifndef OPENSSL_NO_GOST | ||
54 | |||
55 | #include <openssl/evp.h> | ||
56 | #include <openssl/gost.h> | ||
57 | #include <openssl/objects.h> | ||
58 | |||
59 | static int init(EVP_MD_CTX *ctx) | ||
60 | { | ||
61 | return GOST2814789IMIT_Init(ctx->md_data, NID_id_Gost28147_89_CryptoPro_A_ParamSet); | ||
62 | } | ||
63 | |||
64 | static int update(EVP_MD_CTX *ctx, const void *data, size_t count) | ||
65 | { | ||
66 | return GOST2814789IMIT_Update(ctx->md_data, data, count); | ||
67 | } | ||
68 | |||
69 | static int final(EVP_MD_CTX *ctx, unsigned char *md) | ||
70 | { | ||
71 | return GOST2814789IMIT_Final(md, ctx->md_data); | ||
72 | } | ||
73 | |||
74 | static int md_ctrl(EVP_MD_CTX *ctx, int cmd, int p1, void *p2) | ||
75 | { | ||
76 | GOST2814789IMIT_CTX *gctx = ctx->md_data; | ||
77 | |||
78 | switch (cmd) { | ||
79 | case EVP_MD_CTRL_SET_KEY: | ||
80 | return Gost2814789_set_key(&gctx->cipher, p2, p1); | ||
81 | case EVP_MD_CTRL_GOST_SET_SBOX: | ||
82 | return Gost2814789_set_sbox(&gctx->cipher, p1); | ||
83 | } | ||
84 | return -2; | ||
85 | } | ||
86 | |||
87 | static const EVP_MD gost2814789imit_md = { | ||
88 | .type = NID_id_Gost28147_89_MAC, | ||
89 | .pkey_type = NID_undef, | ||
90 | .md_size = GOST2814789IMIT_LENGTH, | ||
91 | .flags = 0, | ||
92 | .init = init, | ||
93 | .update = update, | ||
94 | .final = final, | ||
95 | .block_size = GOST2814789IMIT_CBLOCK, | ||
96 | .ctx_size = sizeof(EVP_MD *) + sizeof(GOST2814789IMIT_CTX), | ||
97 | .md_ctrl = md_ctrl, | ||
98 | }; | ||
99 | |||
100 | const EVP_MD * | ||
101 | EVP_gost2814789imit(void) | ||
102 | { | ||
103 | return (&gost2814789imit_md); | ||
104 | } | ||
105 | #endif | ||
diff --git a/src/lib/libssl/src/crypto/evp/m_gostr341194.c b/src/lib/libssl/src/crypto/evp/m_gostr341194.c new file mode 100644 index 0000000000..380d92d508 --- /dev/null +++ b/src/lib/libssl/src/crypto/evp/m_gostr341194.c | |||
@@ -0,0 +1,93 @@ | |||
1 | /* $OpenBSD: m_gostr341194.c,v 1.1 2014/11/09 19:17:13 miod Exp $ */ | ||
2 | /* | ||
3 | * Copyright (c) 2014 Dmitry Eremin-Solenikov <dbaryshkov@gmail.com> | ||
4 | * Copyright (c) 2005-2006 Cryptocom LTD | ||
5 | * | ||
6 | * Redistribution and use in source and binary forms, with or without | ||
7 | * modification, are permitted provided that the following conditions | ||
8 | * are met: | ||
9 | * | ||
10 | * 1. Redistributions of source code must retain the above copyright | ||
11 | * notice, this list of conditions and the following disclaimer. | ||
12 | * | ||
13 | * 2. Redistributions in binary form must reproduce the above copyright | ||
14 | * notice, this list of conditions and the following disclaimer in | ||
15 | * the documentation and/or other materials provided with the | ||
16 | * distribution. | ||
17 | * | ||
18 | * 3. All advertising materials mentioning features or use of this | ||
19 | * software must display the following acknowledgment: | ||
20 | * "This product includes software developed by the OpenSSL Project | ||
21 | * for use in the OpenSSL Toolkit. (http://www.openssl.org/)" | ||
22 | * | ||
23 | * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to | ||
24 | * endorse or promote products derived from this software without | ||
25 | * prior written permission. For written permission, please contact | ||
26 | * openssl-core@openssl.org. | ||
27 | * | ||
28 | * 5. Products derived from this software may not be called "OpenSSL" | ||
29 | * nor may "OpenSSL" appear in their names without prior written | ||
30 | * permission of the OpenSSL Project. | ||
31 | * | ||
32 | * 6. Redistributions of any form whatsoever must retain the following | ||
33 | * acknowledgment: | ||
34 | * "This product includes software developed by the OpenSSL Project | ||
35 | * for use in the OpenSSL Toolkit (http://www.openssl.org/)" | ||
36 | * | ||
37 | * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY | ||
38 | * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | ||
39 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR | ||
40 | * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR | ||
41 | * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, | ||
42 | * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT | ||
43 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; | ||
44 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | ||
45 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, | ||
46 | * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) | ||
47 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED | ||
48 | * OF THE POSSIBILITY OF SUCH DAMAGE. | ||
49 | * ==================================================================== | ||
50 | */ | ||
51 | #include <stdio.h> | ||
52 | |||
53 | #include <openssl/opensslconf.h> | ||
54 | |||
55 | #ifndef OPENSSL_NO_GOST | ||
56 | |||
57 | #include <openssl/evp.h> | ||
58 | #include <openssl/gost.h> | ||
59 | #include <openssl/objects.h> | ||
60 | |||
61 | static int init(EVP_MD_CTX *ctx) | ||
62 | { | ||
63 | return GOSTR341194_Init(ctx->md_data, NID_id_GostR3411_94_CryptoProParamSet); | ||
64 | } | ||
65 | |||
66 | static int update(EVP_MD_CTX *ctx, const void *data, size_t count) | ||
67 | { | ||
68 | return GOSTR341194_Update(ctx->md_data, data, count); | ||
69 | } | ||
70 | |||
71 | static int final(EVP_MD_CTX *ctx, unsigned char *md) | ||
72 | { | ||
73 | return GOSTR341194_Final(md, ctx->md_data); | ||
74 | } | ||
75 | |||
76 | static const EVP_MD gostr341194_md = { | ||
77 | .type = NID_id_GostR3411_94, | ||
78 | .pkey_type = NID_undef, | ||
79 | .md_size = GOSTR341194_LENGTH, | ||
80 | .flags = EVP_MD_FLAG_PKEY_METHOD_SIGNATURE, | ||
81 | .init = init, | ||
82 | .update = update, | ||
83 | .final = final, | ||
84 | .block_size = GOSTR341194_CBLOCK, | ||
85 | .ctx_size = sizeof(EVP_MD *) + sizeof(GOSTR341194_CTX), | ||
86 | }; | ||
87 | |||
88 | const EVP_MD * | ||
89 | EVP_gostr341194(void) | ||
90 | { | ||
91 | return (&gostr341194_md); | ||
92 | } | ||
93 | #endif | ||
diff --git a/src/lib/libssl/src/crypto/evp/m_streebog.c b/src/lib/libssl/src/crypto/evp/m_streebog.c new file mode 100644 index 0000000000..cf4b159f43 --- /dev/null +++ b/src/lib/libssl/src/crypto/evp/m_streebog.c | |||
@@ -0,0 +1,125 @@ | |||
1 | /* $OpenBSD: m_streebog.c,v 1.1 2014/11/09 19:17:13 miod Exp $ */ | ||
2 | /* | ||
3 | * Copyright (c) 2014 Dmitry Eremin-Solenikov <dbaryshkov@gmail.com> | ||
4 | * Copyright (c) 2005-2006 Cryptocom LTD | ||
5 | * | ||
6 | * Redistribution and use in source and binary forms, with or without | ||
7 | * modification, are permitted provided that the following conditions | ||
8 | * are met: | ||
9 | * | ||
10 | * 1. Redistributions of source code must retain the above copyright | ||
11 | * notice, this list of conditions and the following disclaimer. | ||
12 | * | ||
13 | * 2. Redistributions in binary form must reproduce the above copyright | ||
14 | * notice, this list of conditions and the following disclaimer in | ||
15 | * the documentation and/or other materials provided with the | ||
16 | * distribution. | ||
17 | * | ||
18 | * 3. All advertising materials mentioning features or use of this | ||
19 | * software must display the following acknowledgment: | ||
20 | * "This product includes software developed by the OpenSSL Project | ||
21 | * for use in the OpenSSL Toolkit. (http://www.openssl.org/)" | ||
22 | * | ||
23 | * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to | ||
24 | * endorse or promote products derived from this software without | ||
25 | * prior written permission. For written permission, please contact | ||
26 | * openssl-core@openssl.org. | ||
27 | * | ||
28 | * 5. Products derived from this software may not be called "OpenSSL" | ||
29 | * nor may "OpenSSL" appear in their names without prior written | ||
30 | * permission of the OpenSSL Project. | ||
31 | * | ||
32 | * 6. Redistributions of any form whatsoever must retain the following | ||
33 | * acknowledgment: | ||
34 | * "This product includes software developed by the OpenSSL Project | ||
35 | * for use in the OpenSSL Toolkit (http://www.openssl.org/)" | ||
36 | * | ||
37 | * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY | ||
38 | * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | ||
39 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR | ||
40 | * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR | ||
41 | * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, | ||
42 | * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT | ||
43 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; | ||
44 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | ||
45 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, | ||
46 | * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) | ||
47 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED | ||
48 | * OF THE POSSIBILITY OF SUCH DAMAGE. | ||
49 | * ==================================================================== | ||
50 | */ | ||
51 | |||
52 | #include <openssl/opensslconf.h> | ||
53 | |||
54 | #ifndef OPENSSL_NO_GOST | ||
55 | |||
56 | #include <openssl/evp.h> | ||
57 | #include <openssl/gost.h> | ||
58 | #include <openssl/objects.h> | ||
59 | |||
60 | static int init256(EVP_MD_CTX *ctx) | ||
61 | { | ||
62 | return STREEBOG256_Init(ctx->md_data); | ||
63 | } | ||
64 | |||
65 | static int update256(EVP_MD_CTX *ctx, const void *data, size_t count) | ||
66 | { | ||
67 | return STREEBOG256_Update(ctx->md_data, data, count); | ||
68 | } | ||
69 | |||
70 | static int final256(EVP_MD_CTX *ctx, unsigned char *md) | ||
71 | { | ||
72 | return STREEBOG256_Final(md, ctx->md_data); | ||
73 | } | ||
74 | |||
75 | static int init512(EVP_MD_CTX *ctx) | ||
76 | { | ||
77 | return STREEBOG512_Init(ctx->md_data); | ||
78 | } | ||
79 | |||
80 | static int update512(EVP_MD_CTX *ctx, const void *data, size_t count) | ||
81 | { | ||
82 | return STREEBOG512_Update(ctx->md_data, data, count); | ||
83 | } | ||
84 | |||
85 | static int final512(EVP_MD_CTX *ctx, unsigned char *md) | ||
86 | { | ||
87 | return STREEBOG512_Final(md, ctx->md_data); | ||
88 | } | ||
89 | |||
90 | static const EVP_MD streebog256_md = { | ||
91 | .type = NID_id_tc26_gost3411_2012_256, | ||
92 | .pkey_type = NID_undef, | ||
93 | .md_size = STREEBOG256_LENGTH, | ||
94 | .flags = EVP_MD_FLAG_PKEY_METHOD_SIGNATURE, | ||
95 | .init = init256, | ||
96 | .update = update256, | ||
97 | .final = final256, | ||
98 | .block_size = STREEBOG_CBLOCK, | ||
99 | .ctx_size = sizeof(EVP_MD *) + sizeof(STREEBOG_CTX), | ||
100 | }; | ||
101 | |||
102 | static const EVP_MD streebog512_md = { | ||
103 | .type = NID_id_tc26_gost3411_2012_512, | ||
104 | .pkey_type = NID_undef, | ||
105 | .md_size = STREEBOG512_LENGTH, | ||
106 | .flags = EVP_MD_FLAG_PKEY_METHOD_SIGNATURE, | ||
107 | .init = init512, | ||
108 | .update = update512, | ||
109 | .final = final512, | ||
110 | .block_size = STREEBOG_CBLOCK, | ||
111 | .ctx_size = sizeof(EVP_MD *) + sizeof(STREEBOG_CTX), | ||
112 | }; | ||
113 | |||
114 | const EVP_MD * | ||
115 | EVP_streebog256(void) | ||
116 | { | ||
117 | return (&streebog256_md); | ||
118 | } | ||
119 | |||
120 | const EVP_MD * | ||
121 | EVP_streebog512(void) | ||
122 | { | ||
123 | return (&streebog512_md); | ||
124 | } | ||
125 | #endif | ||
diff --git a/src/lib/libssl/src/crypto/evp/pmeth_lib.c b/src/lib/libssl/src/crypto/evp/pmeth_lib.c index 12267a6d93..24cdfdd1d0 100644 --- a/src/lib/libssl/src/crypto/evp/pmeth_lib.c +++ b/src/lib/libssl/src/crypto/evp/pmeth_lib.c | |||
@@ -1,4 +1,4 @@ | |||
1 | /* $OpenBSD: pmeth_lib.c,v 1.9 2014/07/12 16:03:37 miod Exp $ */ | 1 | /* $OpenBSD: pmeth_lib.c,v 1.10 2014/11/09 19:17:13 miod Exp $ */ |
2 | /* Written by Dr Stephen N Henson (steve@openssl.org) for the OpenSSL | 2 | /* Written by Dr Stephen N Henson (steve@openssl.org) for the OpenSSL |
3 | * project 2006. | 3 | * project 2006. |
4 | */ | 4 | */ |
@@ -79,6 +79,7 @@ STACK_OF(EVP_PKEY_METHOD) *app_pkey_methods = NULL; | |||
79 | 79 | ||
80 | extern const EVP_PKEY_METHOD rsa_pkey_meth, dh_pkey_meth, dsa_pkey_meth; | 80 | extern const EVP_PKEY_METHOD rsa_pkey_meth, dh_pkey_meth, dsa_pkey_meth; |
81 | extern const EVP_PKEY_METHOD ec_pkey_meth, hmac_pkey_meth, cmac_pkey_meth; | 81 | extern const EVP_PKEY_METHOD ec_pkey_meth, hmac_pkey_meth, cmac_pkey_meth; |
82 | extern const EVP_PKEY_METHOD gostimit_pkey_meth, gostr01_pkey_meth; | ||
82 | 83 | ||
83 | static const EVP_PKEY_METHOD *standard_methods[] = { | 84 | static const EVP_PKEY_METHOD *standard_methods[] = { |
84 | #ifndef OPENSSL_NO_RSA | 85 | #ifndef OPENSSL_NO_RSA |
@@ -93,8 +94,12 @@ static const EVP_PKEY_METHOD *standard_methods[] = { | |||
93 | #ifndef OPENSSL_NO_EC | 94 | #ifndef OPENSSL_NO_EC |
94 | &ec_pkey_meth, | 95 | &ec_pkey_meth, |
95 | #endif | 96 | #endif |
97 | #ifndef OPENSSL_NO_GOST | ||
98 | &gostr01_pkey_meth, | ||
99 | &gostimit_pkey_meth, | ||
100 | #endif | ||
96 | &hmac_pkey_meth, | 101 | &hmac_pkey_meth, |
97 | &cmac_pkey_meth | 102 | &cmac_pkey_meth, |
98 | }; | 103 | }; |
99 | 104 | ||
100 | DECLARE_OBJ_BSEARCH_CMP_FN(const EVP_PKEY_METHOD *, const EVP_PKEY_METHOD *, | 105 | DECLARE_OBJ_BSEARCH_CMP_FN(const EVP_PKEY_METHOD *, const EVP_PKEY_METHOD *, |
diff --git a/src/lib/libssl/src/crypto/gost/gost.h b/src/lib/libssl/src/crypto/gost/gost.h new file mode 100644 index 0000000000..5296e7b9c2 --- /dev/null +++ b/src/lib/libssl/src/crypto/gost/gost.h | |||
@@ -0,0 +1,263 @@ | |||
1 | /* $OpenBSD: gost.h,v 1.1 2014/11/09 19:17:13 miod Exp $ */ | ||
2 | /* | ||
3 | * Copyright (c) 2014 Dmitry Eremin-Solenikov <dbaryshkov@gmail.com> | ||
4 | * Copyright (c) 2005-2006 Cryptocom LTD | ||
5 | * | ||
6 | * Redistribution and use in source and binary forms, with or without | ||
7 | * modification, are permitted provided that the following conditions | ||
8 | * are met: | ||
9 | * | ||
10 | * 1. Redistributions of source code must retain the above copyright | ||
11 | * notice, this list of conditions and the following disclaimer. | ||
12 | * | ||
13 | * 2. Redistributions in binary form must reproduce the above copyright | ||
14 | * notice, this list of conditions and the following disclaimer in | ||
15 | * the documentation and/or other materials provided with the | ||
16 | * distribution. | ||
17 | * | ||
18 | * 3. All advertising materials mentioning features or use of this | ||
19 | * software must display the following acknowledgment: | ||
20 | * "This product includes software developed by the OpenSSL Project | ||
21 | * for use in the OpenSSL Toolkit. (http://www.openssl.org/)" | ||
22 | * | ||
23 | * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to | ||
24 | * endorse or promote products derived from this software without | ||
25 | * prior written permission. For written permission, please contact | ||
26 | * openssl-core@openssl.org. | ||
27 | * | ||
28 | * 5. Products derived from this software may not be called "OpenSSL" | ||
29 | * nor may "OpenSSL" appear in their names without prior written | ||
30 | * permission of the OpenSSL Project. | ||
31 | * | ||
32 | * 6. Redistributions of any form whatsoever must retain the following | ||
33 | * acknowledgment: | ||
34 | * "This product includes software developed by the OpenSSL Project | ||
35 | * for use in the OpenSSL Toolkit (http://www.openssl.org/)" | ||
36 | * | ||
37 | * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY | ||
38 | * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | ||
39 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR | ||
40 | * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR | ||
41 | * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, | ||
42 | * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT | ||
43 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; | ||
44 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | ||
45 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, | ||
46 | * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) | ||
47 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED | ||
48 | * OF THE POSSIBILITY OF SUCH DAMAGE. | ||
49 | * ==================================================================== | ||
50 | */ | ||
51 | |||
52 | #ifndef HEADER_GOST_H | ||
53 | #define HEADER_GOST_H | ||
54 | |||
55 | #include <openssl/opensslconf.h> | ||
56 | |||
57 | #ifdef OPENSSL_NO_GOST | ||
58 | #error GOST is disabled. | ||
59 | #endif | ||
60 | |||
61 | #include <openssl/asn1t.h> | ||
62 | #include <openssl/ec.h> | ||
63 | |||
64 | #ifdef __cplusplus | ||
65 | extern "C" { | ||
66 | #endif | ||
67 | |||
68 | typedef struct gost2814789_key_st { | ||
69 | unsigned int key[8]; | ||
70 | unsigned int k87[256],k65[256],k43[256],k21[256]; | ||
71 | unsigned int count; | ||
72 | unsigned key_meshing : 1; | ||
73 | } GOST2814789_KEY; | ||
74 | |||
75 | int Gost2814789_set_sbox(GOST2814789_KEY *key, int nid); | ||
76 | int Gost2814789_set_key(GOST2814789_KEY *key, | ||
77 | const unsigned char *userKey, const int bits); | ||
78 | void Gost2814789_ecb_encrypt(const unsigned char *in, unsigned char *out, | ||
79 | GOST2814789_KEY *key, const int enc); | ||
80 | void Gost2814789_cfb64_encrypt(const unsigned char *in, unsigned char *out, | ||
81 | size_t length, GOST2814789_KEY *key, | ||
82 | unsigned char *ivec, int *num, const int enc); | ||
83 | void Gost2814789_cnt_encrypt(const unsigned char *in, unsigned char *out, | ||
84 | size_t length, GOST2814789_KEY *key, | ||
85 | unsigned char *ivec, unsigned char *cnt_buf, int *num); | ||
86 | |||
87 | typedef struct { | ||
88 | ASN1_OCTET_STRING *iv; | ||
89 | ASN1_OBJECT *enc_param_set; | ||
90 | } GOST_CIPHER_PARAMS; | ||
91 | |||
92 | DECLARE_ASN1_FUNCTIONS(GOST_CIPHER_PARAMS) | ||
93 | |||
94 | #define GOST2814789IMIT_LENGTH 4 | ||
95 | #define GOST2814789IMIT_CBLOCK 8 | ||
96 | #define GOST2814789IMIT_LONG unsigned int | ||
97 | |||
98 | typedef struct GOST2814789IMITstate_st { | ||
99 | GOST2814789IMIT_LONG Nl, Nh; | ||
100 | unsigned char data[GOST2814789IMIT_CBLOCK]; | ||
101 | unsigned int num; | ||
102 | |||
103 | GOST2814789_KEY cipher; | ||
104 | unsigned char mac[GOST2814789IMIT_CBLOCK]; | ||
105 | } GOST2814789IMIT_CTX; | ||
106 | |||
107 | /* Note, also removed second parameter and removed dctx->cipher setting */ | ||
108 | int GOST2814789IMIT_Init(GOST2814789IMIT_CTX *c, int nid); | ||
109 | int GOST2814789IMIT_Update(GOST2814789IMIT_CTX *c, const void *data, size_t len); | ||
110 | int GOST2814789IMIT_Final(unsigned char *md, GOST2814789IMIT_CTX *c); | ||
111 | void GOST2814789IMIT_Transform(GOST2814789IMIT_CTX *c, const unsigned char *data); | ||
112 | unsigned char *GOST2814789IMIT(const unsigned char *d, size_t n, | ||
113 | unsigned char *md, int nid, | ||
114 | const unsigned char *key, const unsigned char *iv); | ||
115 | |||
116 | #define GOSTR341194_LONG unsigned int | ||
117 | |||
118 | #define GOSTR341194_LENGTH 32 | ||
119 | #define GOSTR341194_CBLOCK 32 | ||
120 | #define GOSTR341194_LBLOCK (GOSTR341194_CBLOCK/4) | ||
121 | |||
122 | typedef struct GOSTR341194state_st { | ||
123 | GOSTR341194_LONG Nl, Nh; | ||
124 | GOSTR341194_LONG data[GOSTR341194_LBLOCK]; | ||
125 | unsigned int num; | ||
126 | |||
127 | GOST2814789_KEY cipher; | ||
128 | unsigned char H[GOSTR341194_CBLOCK]; | ||
129 | unsigned char S[GOSTR341194_CBLOCK]; | ||
130 | } GOSTR341194_CTX; | ||
131 | |||
132 | /* Note, also removed second parameter and removed dctx->cipher setting */ | ||
133 | int GOSTR341194_Init(GOSTR341194_CTX *c, int nid); | ||
134 | int GOSTR341194_Update(GOSTR341194_CTX *c, const void *data, size_t len); | ||
135 | int GOSTR341194_Final(unsigned char *md, GOSTR341194_CTX *c); | ||
136 | void GOSTR341194_Transform(GOSTR341194_CTX *c, const unsigned char *data); | ||
137 | unsigned char *GOSTR341194(const unsigned char *d, size_t n,unsigned char *md, int nid); | ||
138 | |||
139 | #if defined(_LP64) | ||
140 | #define STREEBOG_LONG64 unsigned long | ||
141 | #define U64(C) C##UL | ||
142 | #else | ||
143 | #define STREEBOG_LONG64 unsigned long long | ||
144 | #define U64(C) C##ULL | ||
145 | #endif | ||
146 | |||
147 | #define STREEBOG_LBLOCK 8 | ||
148 | #define STREEBOG_CBLOCK 64 | ||
149 | #define STREEBOG256_LENGTH 32 | ||
150 | #define STREEBOG512_LENGTH 64 | ||
151 | |||
152 | typedef struct STREEBOGstate_st { | ||
153 | STREEBOG_LONG64 data[STREEBOG_LBLOCK]; | ||
154 | unsigned int num; | ||
155 | unsigned int md_len; | ||
156 | STREEBOG_LONG64 h[STREEBOG_LBLOCK]; | ||
157 | STREEBOG_LONG64 N[STREEBOG_LBLOCK]; | ||
158 | STREEBOG_LONG64 Sigma[STREEBOG_LBLOCK]; | ||
159 | } STREEBOG_CTX; | ||
160 | |||
161 | int STREEBOG256_Init(STREEBOG_CTX *c); | ||
162 | int STREEBOG256_Update(STREEBOG_CTX *c, const void *data, size_t len); | ||
163 | int STREEBOG256_Final(unsigned char *md, STREEBOG_CTX *c); | ||
164 | void STREEBOG256_Transform(STREEBOG_CTX *c, const unsigned char *data); | ||
165 | unsigned char *STREEBOG256(const unsigned char *d, size_t n,unsigned char *md); | ||
166 | |||
167 | int STREEBOG512_Init(STREEBOG_CTX *c); | ||
168 | int STREEBOG512_Update(STREEBOG_CTX *c, const void *data, size_t len); | ||
169 | int STREEBOG512_Final(unsigned char *md, STREEBOG_CTX *c); | ||
170 | void STREEBOG512_Transform(STREEBOG_CTX *c, const unsigned char *data); | ||
171 | unsigned char *STREEBOG512(const unsigned char *d, size_t n,unsigned char *md); | ||
172 | |||
173 | typedef struct gost_key_st GOST_KEY; | ||
174 | GOST_KEY *GOST_KEY_new(void); | ||
175 | void GOST_KEY_free(GOST_KEY * r); | ||
176 | int GOST_KEY_check_key(const GOST_KEY * eckey); | ||
177 | int GOST_KEY_set_public_key_affine_coordinates(GOST_KEY * key, BIGNUM * x, BIGNUM * y); | ||
178 | const EC_GROUP * GOST_KEY_get0_group(const GOST_KEY * key); | ||
179 | int GOST_KEY_set_group(GOST_KEY * key, const EC_GROUP * group); | ||
180 | int GOST_KEY_get_digest(const GOST_KEY * key); | ||
181 | int GOST_KEY_set_digest(GOST_KEY * key, int digest_nid); | ||
182 | const BIGNUM * GOST_KEY_get0_private_key(const GOST_KEY * key); | ||
183 | int GOST_KEY_set_private_key(GOST_KEY * key, const BIGNUM * priv_key); | ||
184 | const EC_POINT * GOST_KEY_get0_public_key(const GOST_KEY * key); | ||
185 | int GOST_KEY_set_public_key(GOST_KEY * key, const EC_POINT * pub_key); | ||
186 | size_t GOST_KEY_get_size(const GOST_KEY * r); | ||
187 | |||
188 | /* Gost-specific pmeth control-function parameters */ | ||
189 | /* For GOST R34.10 parameters */ | ||
190 | #define EVP_PKEY_CTRL_GOST_PARAMSET (EVP_PKEY_ALG_CTRL+1) | ||
191 | #define EVP_PKEY_CTRL_GOST_SIG_FORMAT (EVP_PKEY_ALG_CTRL+2) | ||
192 | #define EVP_PKEY_CTRL_GOST_SET_DIGEST (EVP_PKEY_ALG_CTRL+3) | ||
193 | #define EVP_PKEY_CTRL_GOST_GET_DIGEST (EVP_PKEY_ALG_CTRL+4) | ||
194 | |||
195 | #define GOST_SIG_FORMAT_SR_BE 0 | ||
196 | #define GOST_SIG_FORMAT_RS_LE 1 | ||
197 | |||
198 | /* BEGIN ERROR CODES */ | ||
199 | /* The following lines are auto generated by the script mkerr.pl. Any changes | ||
200 | * made after this point may be overwritten when the script is next run. | ||
201 | */ | ||
202 | void ERR_load_GOST_strings(void); | ||
203 | |||
204 | /* Error codes for the GOST functions. */ | ||
205 | |||
206 | /* Function codes. */ | ||
207 | #define GOST_F_DECODE_GOST01_ALGOR_PARAMS 104 | ||
208 | #define GOST_F_ENCODE_GOST01_ALGOR_PARAMS 105 | ||
209 | #define GOST_F_GOST2001_COMPUTE_PUBLIC 106 | ||
210 | #define GOST_F_GOST2001_DO_SIGN 107 | ||
211 | #define GOST_F_GOST2001_DO_VERIFY 108 | ||
212 | #define GOST_F_GOST2001_KEYGEN 109 | ||
213 | #define GOST_F_GOST89_GET_ASN1_PARAMETERS 102 | ||
214 | #define GOST_F_GOST89_SET_ASN1_PARAMETERS 103 | ||
215 | #define GOST_F_GOST_KEY_CHECK_KEY 124 | ||
216 | #define GOST_F_GOST_KEY_NEW 125 | ||
217 | #define GOST_F_GOST_KEY_SET_PUBLIC_KEY_AFFINE_COORDINATES 126 | ||
218 | #define GOST_F_PARAM_COPY_GOST01 110 | ||
219 | #define GOST_F_PARAM_DECODE_GOST01 111 | ||
220 | #define GOST_F_PKEY_GOST01_CTRL 116 | ||
221 | #define GOST_F_PKEY_GOST01_DECRYPT 112 | ||
222 | #define GOST_F_PKEY_GOST01_DERIVE 113 | ||
223 | #define GOST_F_PKEY_GOST01_ENCRYPT 114 | ||
224 | #define GOST_F_PKEY_GOST01_PARAMGEN 115 | ||
225 | #define GOST_F_PKEY_GOST01_SIGN 123 | ||
226 | #define GOST_F_PKEY_GOST_MAC_CTRL 100 | ||
227 | #define GOST_F_PKEY_GOST_MAC_KEYGEN 101 | ||
228 | #define GOST_F_PRIV_DECODE_GOST01 117 | ||
229 | #define GOST_F_PUB_DECODE_GOST01 118 | ||
230 | #define GOST_F_PUB_ENCODE_GOST01 119 | ||
231 | #define GOST_F_PUB_PRINT_GOST01 120 | ||
232 | #define GOST_F_UNPACK_SIGNATURE_CP 121 | ||
233 | #define GOST_F_UNPACK_SIGNATURE_LE 122 | ||
234 | |||
235 | /* Reason codes. */ | ||
236 | #define GOST_R_BAD_KEY_PARAMETERS_FORMAT 104 | ||
237 | #define GOST_R_BAD_PKEY_PARAMETERS_FORMAT 105 | ||
238 | #define GOST_R_CANNOT_PACK_EPHEMERAL_KEY 106 | ||
239 | #define GOST_R_CTRL_CALL_FAILED 107 | ||
240 | #define GOST_R_ERROR_COMPUTING_SHARED_KEY 108 | ||
241 | #define GOST_R_ERROR_PARSING_KEY_TRANSPORT_INFO 109 | ||
242 | #define GOST_R_INCOMPATIBLE_ALGORITHMS 110 | ||
243 | #define GOST_R_INCOMPATIBLE_PEER_KEY 111 | ||
244 | #define GOST_R_INVALID_DIGEST_TYPE 100 | ||
245 | #define GOST_R_INVALID_IV_LENGTH 103 | ||
246 | #define GOST_R_INVALID_MAC_KEY_LENGTH 101 | ||
247 | #define GOST_R_KEY_IS_NOT_INITIALIZED 112 | ||
248 | #define GOST_R_KEY_PARAMETERS_MISSING 113 | ||
249 | #define GOST_R_MAC_KEY_NOT_SET 102 | ||
250 | #define GOST_R_NO_PARAMETERS_SET 115 | ||
251 | #define GOST_R_NO_PEER_KEY 116 | ||
252 | #define GOST_R_NO_PRIVATE_PART_OF_NON_EPHEMERAL_KEYPAIR 117 | ||
253 | #define GOST_R_PUBLIC_KEY_UNDEFINED 118 | ||
254 | #define GOST_R_RANDOM_GENERATOR_FAILURE 119 | ||
255 | #define GOST_R_RANDOM_NUMBER_GENERATOR_FAILED 120 | ||
256 | #define GOST_R_SIGNATURE_MISMATCH 121 | ||
257 | #define GOST_R_SIGNATURE_PARTS_GREATER_THAN_Q 122 | ||
258 | #define GOST_R_UKM_NOT_SET 123 | ||
259 | |||
260 | #ifdef __cplusplus | ||
261 | } | ||
262 | #endif | ||
263 | #endif | ||
diff --git a/src/lib/libssl/src/crypto/gost/gost2814789.c b/src/lib/libssl/src/crypto/gost/gost2814789.c new file mode 100644 index 0000000000..b80f692f10 --- /dev/null +++ b/src/lib/libssl/src/crypto/gost/gost2814789.c | |||
@@ -0,0 +1,453 @@ | |||
1 | /* $OpenBSD: gost2814789.c,v 1.1 2014/11/09 19:17:13 miod Exp $ */ | ||
2 | /* | ||
3 | * Copyright (c) 2014 Dmitry Eremin-Solenikov <dbaryshkov@gmail.com> | ||
4 | * Copyright (c) 2005-2006 Cryptocom LTD | ||
5 | * | ||
6 | * Redistribution and use in source and binary forms, with or without | ||
7 | * modification, are permitted provided that the following conditions | ||
8 | * are met: | ||
9 | * | ||
10 | * 1. Redistributions of source code must retain the above copyright | ||
11 | * notice, this list of conditions and the following disclaimer. | ||
12 | * | ||
13 | * 2. Redistributions in binary form must reproduce the above copyright | ||
14 | * notice, this list of conditions and the following disclaimer in | ||
15 | * the documentation and/or other materials provided with the | ||
16 | * distribution. | ||
17 | * | ||
18 | * 3. All advertising materials mentioning features or use of this | ||
19 | * software must display the following acknowledgment: | ||
20 | * "This product includes software developed by the OpenSSL Project | ||
21 | * for use in the OpenSSL Toolkit. (http://www.openssl.org/)" | ||
22 | * | ||
23 | * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to | ||
24 | * endorse or promote products derived from this software without | ||
25 | * prior written permission. For written permission, please contact | ||
26 | * openssl-core@openssl.org. | ||
27 | * | ||
28 | * 5. Products derived from this software may not be called "OpenSSL" | ||
29 | * nor may "OpenSSL" appear in their names without prior written | ||
30 | * permission of the OpenSSL Project. | ||
31 | * | ||
32 | * 6. Redistributions of any form whatsoever must retain the following | ||
33 | * acknowledgment: | ||
34 | * "This product includes software developed by the OpenSSL Project | ||
35 | * for use in the OpenSSL Toolkit (http://www.openssl.org/)" | ||
36 | * | ||
37 | * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY | ||
38 | * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | ||
39 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR | ||
40 | * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR | ||
41 | * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, | ||
42 | * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT | ||
43 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; | ||
44 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | ||
45 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, | ||
46 | * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) | ||
47 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED | ||
48 | * OF THE POSSIBILITY OF SUCH DAMAGE. | ||
49 | * ==================================================================== | ||
50 | */ | ||
51 | |||
52 | #include <string.h> | ||
53 | |||
54 | #include <openssl/opensslconf.h> | ||
55 | |||
56 | #ifndef OPENSSL_NO_GOST | ||
57 | #include <openssl/objects.h> | ||
58 | #include <openssl/gost.h> | ||
59 | |||
60 | #include "gost_locl.h" | ||
61 | |||
62 | static inline unsigned int f(const GOST2814789_KEY *c, unsigned int x) | ||
63 | { | ||
64 | return c->k87[(x>>24) & 255] | c->k65[(x>>16) & 255]| | ||
65 | c->k43[(x>> 8) & 255] | c->k21[(x ) & 255]; | ||
66 | } | ||
67 | |||
68 | void Gost2814789_encrypt(const unsigned char *in, unsigned char *out, | ||
69 | const GOST2814789_KEY *key) | ||
70 | { | ||
71 | unsigned int n1, n2; /* As named in the GOST */ | ||
72 | c2l(in, n1); | ||
73 | c2l(in, n2); | ||
74 | |||
75 | /* Instead of swapping halves, swap names each round */ | ||
76 | n2 ^= f(key, n1 + key->key[0]); n1 ^= f(key, n2 + key->key[1]); | ||
77 | n2 ^= f(key, n1 + key->key[2]); n1 ^= f(key, n2 + key->key[3]); | ||
78 | n2 ^= f(key, n1 + key->key[4]); n1 ^= f(key, n2 + key->key[5]); | ||
79 | n2 ^= f(key, n1 + key->key[6]); n1 ^= f(key, n2 + key->key[7]); | ||
80 | |||
81 | n2 ^= f(key, n1 + key->key[0]); n1 ^= f(key, n2 + key->key[1]); | ||
82 | n2 ^= f(key, n1 + key->key[2]); n1 ^= f(key, n2 + key->key[3]); | ||
83 | n2 ^= f(key, n1 + key->key[4]); n1 ^= f(key, n2 + key->key[5]); | ||
84 | n2 ^= f(key, n1 + key->key[6]); n1 ^= f(key, n2 + key->key[7]); | ||
85 | |||
86 | n2 ^= f(key, n1 + key->key[0]); n1 ^= f(key, n2 + key->key[1]); | ||
87 | n2 ^= f(key, n1 + key->key[2]); n1 ^= f(key, n2 + key->key[3]); | ||
88 | n2 ^= f(key, n1 + key->key[4]); n1 ^= f(key, n2 + key->key[5]); | ||
89 | n2 ^= f(key, n1 + key->key[6]); n1 ^= f(key, n2 + key->key[7]); | ||
90 | |||
91 | n2 ^= f(key, n1 + key->key[7]); n1 ^= f(key, n2 + key->key[6]); | ||
92 | n2 ^= f(key, n1 + key->key[5]); n1 ^= f(key, n2 + key->key[4]); | ||
93 | n2 ^= f(key, n1 + key->key[3]); n1 ^= f(key, n2 + key->key[2]); | ||
94 | n2 ^= f(key, n1 + key->key[1]); n1 ^= f(key, n2 + key->key[0]); | ||
95 | |||
96 | l2c(n2, out); | ||
97 | l2c(n1, out); | ||
98 | } | ||
99 | |||
100 | void Gost2814789_decrypt(const unsigned char *in, unsigned char *out, | ||
101 | const GOST2814789_KEY *key) | ||
102 | { | ||
103 | unsigned int n1, n2; /* As named in the GOST */ | ||
104 | c2l(in, n1); | ||
105 | c2l(in, n2); | ||
106 | |||
107 | /* Instead of swapping halves, swap names each round */ | ||
108 | n2 ^= f(key, n1 + key->key[0]); n1 ^= f(key, n2 + key->key[1]); | ||
109 | n2 ^= f(key, n1 + key->key[2]); n1 ^= f(key, n2 + key->key[3]); | ||
110 | n2 ^= f(key, n1 + key->key[4]); n1 ^= f(key, n2 + key->key[5]); | ||
111 | n2 ^= f(key, n1 + key->key[6]); n1 ^= f(key, n2 + key->key[7]); | ||
112 | |||
113 | n2 ^= f(key, n1 + key->key[7]); n1 ^= f(key, n2 + key->key[6]); | ||
114 | n2 ^= f(key, n1 + key->key[5]); n1 ^= f(key, n2 + key->key[4]); | ||
115 | n2 ^= f(key, n1 + key->key[3]); n1 ^= f(key, n2 + key->key[2]); | ||
116 | n2 ^= f(key, n1 + key->key[1]); n1 ^= f(key, n2 + key->key[0]); | ||
117 | |||
118 | n2 ^= f(key, n1 + key->key[7]); n1 ^= f(key, n2 + key->key[6]); | ||
119 | n2 ^= f(key, n1 + key->key[5]); n1 ^= f(key, n2 + key->key[4]); | ||
120 | n2 ^= f(key, n1 + key->key[3]); n1 ^= f(key, n2 + key->key[2]); | ||
121 | n2 ^= f(key, n1 + key->key[1]); n1 ^= f(key, n2 + key->key[0]); | ||
122 | |||
123 | n2 ^= f(key, n1 + key->key[7]); n1 ^= f(key, n2 + key->key[6]); | ||
124 | n2 ^= f(key, n1 + key->key[5]); n1 ^= f(key, n2 + key->key[4]); | ||
125 | n2 ^= f(key, n1 + key->key[3]); n1 ^= f(key, n2 + key->key[2]); | ||
126 | n2 ^= f(key, n1 + key->key[1]); n1 ^= f(key, n2 + key->key[0]); | ||
127 | |||
128 | l2c(n2, out); | ||
129 | l2c(n1, out); | ||
130 | } | ||
131 | |||
132 | static void Gost2814789_mac(const unsigned char *in, | ||
133 | unsigned char *mac, | ||
134 | GOST2814789_KEY *key) | ||
135 | { | ||
136 | unsigned int n1, n2; /* As named in the GOST */ | ||
137 | unsigned char *p; | ||
138 | int i; | ||
139 | |||
140 | for (i = 0; i < 8; i++) | ||
141 | mac[i] ^= in[i]; | ||
142 | |||
143 | p = mac; | ||
144 | c2l(p, n1); | ||
145 | c2l(p, n2); | ||
146 | |||
147 | /* Instead of swapping halves, swap names each round */ | ||
148 | n2 ^= f(key, n1 + key->key[0]); n1 ^= f(key, n2 + key->key[1]); | ||
149 | n2 ^= f(key, n1 + key->key[2]); n1 ^= f(key, n2 + key->key[3]); | ||
150 | n2 ^= f(key, n1 + key->key[4]); n1 ^= f(key, n2 + key->key[5]); | ||
151 | n2 ^= f(key, n1 + key->key[6]); n1 ^= f(key, n2 + key->key[7]); | ||
152 | |||
153 | n2 ^= f(key, n1 + key->key[0]); n1 ^= f(key, n2 + key->key[1]); | ||
154 | n2 ^= f(key, n1 + key->key[2]); n1 ^= f(key, n2 + key->key[3]); | ||
155 | n2 ^= f(key, n1 + key->key[4]); n1 ^= f(key, n2 + key->key[5]); | ||
156 | n2 ^= f(key, n1 + key->key[6]); n1 ^= f(key, n2 + key->key[7]); | ||
157 | |||
158 | p = mac; | ||
159 | l2c(n1, p); | ||
160 | l2c(n2, p); | ||
161 | } | ||
162 | |||
163 | |||
164 | void Gost2814789_ecb_encrypt(const unsigned char *in, unsigned char *out, | ||
165 | GOST2814789_KEY *key, const int enc) | ||
166 | { | ||
167 | if (key->key_meshing && key->count == 1024) { | ||
168 | Gost2814789_cryptopro_key_mesh(key); | ||
169 | key->count = 0; | ||
170 | } | ||
171 | |||
172 | if (enc) | ||
173 | Gost2814789_encrypt(in, out, key); | ||
174 | else | ||
175 | Gost2814789_decrypt(in, out, key); | ||
176 | } | ||
177 | |||
178 | static inline void Gost2814789_encrypt_mesh(unsigned char *iv, GOST2814789_KEY *key) | ||
179 | { | ||
180 | if (key->key_meshing && key->count == 1024) { | ||
181 | Gost2814789_cryptopro_key_mesh(key); | ||
182 | Gost2814789_encrypt(iv, iv, key); | ||
183 | key->count = 0; | ||
184 | } | ||
185 | Gost2814789_encrypt(iv, iv, key); | ||
186 | key->count += 8; | ||
187 | } | ||
188 | |||
189 | static inline void Gost2814789_mac_mesh(const unsigned char *data, | ||
190 | unsigned char *mac, | ||
191 | GOST2814789_KEY *key) | ||
192 | { | ||
193 | if (key->key_meshing && key->count == 1024) { | ||
194 | Gost2814789_cryptopro_key_mesh(key); | ||
195 | key->count = 0; | ||
196 | } | ||
197 | Gost2814789_mac(data, mac, key); | ||
198 | key->count += 8; | ||
199 | } | ||
200 | |||
201 | void Gost2814789_cfb64_encrypt(const unsigned char *in, unsigned char *out, | ||
202 | size_t len, GOST2814789_KEY *key, | ||
203 | unsigned char *ivec, int *num, const int enc) | ||
204 | { | ||
205 | unsigned int n; | ||
206 | size_t l = 0; | ||
207 | |||
208 | OPENSSL_assert(in && out && key && ivec && num); | ||
209 | |||
210 | n = *num; | ||
211 | |||
212 | if (enc) { | ||
213 | #if !defined(OPENSSL_SMALL_FOOTPRINT) | ||
214 | if (8%sizeof(size_t) == 0) do { /* always true actually */ | ||
215 | while (n && len) { | ||
216 | *(out++) = ivec[n] ^= *(in++); | ||
217 | --len; | ||
218 | n = (n+1) % 8; | ||
219 | } | ||
220 | #ifdef __STRICT_ALIGNMENT | ||
221 | if (((size_t)in|(size_t)out|(size_t)ivec)%sizeof(size_t) != 0) | ||
222 | break; | ||
223 | #endif | ||
224 | while (len>=8) { | ||
225 | Gost2814789_encrypt_mesh(ivec, key); | ||
226 | for (; n<8; n+=sizeof(size_t)) { | ||
227 | *(size_t*)(out+n) = | ||
228 | *(size_t*)(ivec+n) ^= *(size_t*)(in+n); | ||
229 | } | ||
230 | len -= 8; | ||
231 | out += 8; | ||
232 | in += 8; | ||
233 | n = 0; | ||
234 | } | ||
235 | if (len) { | ||
236 | Gost2814789_encrypt_mesh(ivec, key); | ||
237 | while (len--) { | ||
238 | out[n] = ivec[n] ^= in[n]; | ||
239 | ++n; | ||
240 | } | ||
241 | } | ||
242 | *num = n; | ||
243 | return; | ||
244 | } while (0); | ||
245 | /* the rest would be commonly eliminated by x86* compiler */ | ||
246 | #endif | ||
247 | while (l<len) { | ||
248 | if (n == 0) { | ||
249 | Gost2814789_encrypt_mesh(ivec, key); | ||
250 | } | ||
251 | out[l] = ivec[n] ^= in[l]; | ||
252 | ++l; | ||
253 | n = (n+1) % 8; | ||
254 | } | ||
255 | *num = n; | ||
256 | } else { | ||
257 | #if !defined(OPENSSL_SMALL_FOOTPRINT) | ||
258 | if (8%sizeof(size_t) == 0) do { /* always true actually */ | ||
259 | while (n && len) { | ||
260 | unsigned char c; | ||
261 | *(out++) = ivec[n] ^ (c = *(in++)); ivec[n] = c; | ||
262 | --len; | ||
263 | n = (n+1) % 8; | ||
264 | } | ||
265 | #ifdef __STRICT_ALIGNMENT | ||
266 | if (((size_t)in|(size_t)out|(size_t)ivec)%sizeof(size_t) != 0) | ||
267 | break; | ||
268 | #endif | ||
269 | while (len>=8) { | ||
270 | Gost2814789_encrypt_mesh(ivec, key); | ||
271 | for (; n<8; n+=sizeof(size_t)) { | ||
272 | size_t t = *(size_t*)(in+n); | ||
273 | *(size_t*)(out+n) = *(size_t*)(ivec+n) ^ t; | ||
274 | *(size_t*)(ivec+n) = t; | ||
275 | } | ||
276 | len -= 8; | ||
277 | out += 8; | ||
278 | in += 8; | ||
279 | n = 0; | ||
280 | } | ||
281 | if (len) { | ||
282 | Gost2814789_encrypt_mesh(ivec, key); | ||
283 | while (len--) { | ||
284 | unsigned char c; | ||
285 | out[n] = ivec[n] ^ (c = in[n]); ivec[n] = c; | ||
286 | ++n; | ||
287 | } | ||
288 | } | ||
289 | *num = n; | ||
290 | return; | ||
291 | } while (0); | ||
292 | /* the rest would be commonly eliminated by x86* compiler */ | ||
293 | #endif | ||
294 | while (l<len) { | ||
295 | unsigned char c; | ||
296 | if (n == 0) { | ||
297 | Gost2814789_encrypt_mesh(ivec, key); | ||
298 | } | ||
299 | out[l] = ivec[n] ^ (c = in[l]); ivec[n] = c; | ||
300 | ++l; | ||
301 | n = (n+1) % 8; | ||
302 | } | ||
303 | *num=n; | ||
304 | } | ||
305 | } | ||
306 | |||
307 | static inline void Gost2814789_cnt_next(unsigned char *ivec, | ||
308 | unsigned char *out, | ||
309 | GOST2814789_KEY *key) | ||
310 | { | ||
311 | unsigned char *p = ivec, *p2 = ivec; | ||
312 | unsigned int val, val2; | ||
313 | |||
314 | if (key->count == 0) | ||
315 | Gost2814789_encrypt(ivec, ivec, key); | ||
316 | |||
317 | if (key->key_meshing && key->count == 1024) { | ||
318 | Gost2814789_cryptopro_key_mesh(key); | ||
319 | Gost2814789_encrypt(ivec, ivec, key); | ||
320 | key->count = 0; | ||
321 | } | ||
322 | |||
323 | c2l(p, val); | ||
324 | val2 = val + 0x01010101; | ||
325 | l2c(val2, p2); | ||
326 | |||
327 | c2l(p, val); | ||
328 | val2 = val + 0x01010104; | ||
329 | if (val > val2) /* overflow */ | ||
330 | val2++; | ||
331 | l2c(val2, p2); | ||
332 | |||
333 | Gost2814789_encrypt(ivec, out, key); | ||
334 | key->count += 8; | ||
335 | } | ||
336 | |||
337 | void Gost2814789_cnt_encrypt(const unsigned char *in, unsigned char *out, | ||
338 | size_t len, GOST2814789_KEY *key, | ||
339 | unsigned char *ivec, unsigned char *cnt_buf, int *num) | ||
340 | { | ||
341 | unsigned int n; | ||
342 | size_t l=0; | ||
343 | |||
344 | OPENSSL_assert(in && out && key && cnt_buf && num); | ||
345 | |||
346 | n = *num; | ||
347 | |||
348 | #if !defined(OPENSSL_SMALL_FOOTPRINT) | ||
349 | if (8%sizeof(size_t) == 0) do { /* always true actually */ | ||
350 | while (n && len) { | ||
351 | *(out++) = *(in++) ^ cnt_buf[n]; | ||
352 | --len; | ||
353 | n = (n+1) % 8; | ||
354 | } | ||
355 | |||
356 | #ifdef __STRICT_ALIGNMENT | ||
357 | if (((size_t)in|(size_t)out|(size_t)ivec)%sizeof(size_t) != 0) | ||
358 | break; | ||
359 | #endif | ||
360 | while (len>=8) { | ||
361 | Gost2814789_cnt_next(ivec, cnt_buf, key); | ||
362 | for (; n<8; n+=sizeof(size_t)) | ||
363 | *(size_t *)(out+n) = | ||
364 | *(size_t *)(in+n) ^ *(size_t *)(cnt_buf+n); | ||
365 | len -= 8; | ||
366 | out += 8; | ||
367 | in += 8; | ||
368 | n = 0; | ||
369 | } | ||
370 | if (len) { | ||
371 | Gost2814789_cnt_next(ivec, cnt_buf, key); | ||
372 | while (len--) { | ||
373 | out[n] = in[n] ^ cnt_buf[n]; | ||
374 | ++n; | ||
375 | } | ||
376 | } | ||
377 | *num = n; | ||
378 | return; | ||
379 | } while(0); | ||
380 | /* the rest would be commonly eliminated by x86* compiler */ | ||
381 | #endif | ||
382 | while (l<len) { | ||
383 | if (n==0) | ||
384 | Gost2814789_cnt_next(ivec, cnt_buf, key); | ||
385 | out[l] = in[l] ^ cnt_buf[n]; | ||
386 | ++l; | ||
387 | n = (n+1) % 8; | ||
388 | } | ||
389 | |||
390 | *num=n; | ||
391 | } | ||
392 | |||
393 | int GOST2814789IMIT_Init(GOST2814789IMIT_CTX *c, int nid) | ||
394 | { | ||
395 | c->Nl = c->Nh = c->num = 0; | ||
396 | memset(c->mac, 0, 8); | ||
397 | return Gost2814789_set_sbox(&c->cipher, nid); | ||
398 | } | ||
399 | |||
400 | static void GOST2814789IMIT_block_data_order(GOST2814789IMIT_CTX *ctx, const void *p, size_t num) | ||
401 | { | ||
402 | int i; | ||
403 | for (i = 0; i < num; i++) { | ||
404 | Gost2814789_mac_mesh(p, ctx->mac, &ctx->cipher); | ||
405 | p += 8; | ||
406 | } | ||
407 | } | ||
408 | |||
409 | #define DATA_ORDER_IS_LITTLE_ENDIAN | ||
410 | |||
411 | #define HASH_CBLOCK GOST2814789IMIT_CBLOCK | ||
412 | #define HASH_LONG GOST2814789IMIT_LONG | ||
413 | #define HASH_CTX GOST2814789IMIT_CTX | ||
414 | #define HASH_UPDATE GOST2814789IMIT_Update | ||
415 | #define HASH_TRANSFORM GOST2814789IMIT_Transform | ||
416 | #define HASH_NO_FINAL 1 | ||
417 | #define HASH_BLOCK_DATA_ORDER GOST2814789IMIT_block_data_order | ||
418 | |||
419 | #include "md32_common.h" | ||
420 | |||
421 | int GOST2814789IMIT_Final(unsigned char *md, GOST2814789IMIT_CTX *c) | ||
422 | { | ||
423 | if (c->num) { | ||
424 | memset(c->data + c->num, 0, 8 - c->num); | ||
425 | Gost2814789_mac_mesh(c->data, c->mac, &c->cipher); | ||
426 | } | ||
427 | if (c->Nl <= 8 * 8 && c->Nl > 0 && c->Nh == 0) { | ||
428 | memset(c->data, 0, 8); | ||
429 | Gost2814789_mac_mesh(c->data, c->mac, &c->cipher); | ||
430 | } | ||
431 | memcpy(md, c->mac, 4); | ||
432 | return 1; | ||
433 | } | ||
434 | |||
435 | unsigned char *GOST2814789IMIT(const unsigned char *d, size_t n, | ||
436 | unsigned char *md, int nid, | ||
437 | const unsigned char *key, const unsigned char *iv) | ||
438 | { | ||
439 | GOST2814789IMIT_CTX c; | ||
440 | static unsigned char m[GOST2814789IMIT_LENGTH]; | ||
441 | |||
442 | if (md == NULL) | ||
443 | md = m; | ||
444 | GOST2814789IMIT_Init(&c, nid); | ||
445 | memcpy(c.mac, iv, 8); | ||
446 | Gost2814789_set_key(&c.cipher, key, 256); | ||
447 | GOST2814789IMIT_Update(&c, d, n); | ||
448 | GOST2814789IMIT_Final(md, &c); | ||
449 | OPENSSL_cleanse(&c, sizeof(c)); | ||
450 | return (md); | ||
451 | } | ||
452 | |||
453 | #endif | ||
diff --git a/src/lib/libssl/src/crypto/gost/gost89_keywrap.c b/src/lib/libssl/src/crypto/gost/gost89_keywrap.c new file mode 100644 index 0000000000..8f641b6cef --- /dev/null +++ b/src/lib/libssl/src/crypto/gost/gost89_keywrap.c | |||
@@ -0,0 +1,136 @@ | |||
1 | /* $OpenBSD: gost89_keywrap.c,v 1.1 2014/11/09 19:17:13 miod Exp $ */ | ||
2 | /* | ||
3 | * Copyright (c) 2014 Dmitry Eremin-Solenikov <dbaryshkov@gmail.com> | ||
4 | * Copyright (c) 2005-2006 Cryptocom LTD | ||
5 | * | ||
6 | * Redistribution and use in source and binary forms, with or without | ||
7 | * modification, are permitted provided that the following conditions | ||
8 | * are met: | ||
9 | * | ||
10 | * 1. Redistributions of source code must retain the above copyright | ||
11 | * notice, this list of conditions and the following disclaimer. | ||
12 | * | ||
13 | * 2. Redistributions in binary form must reproduce the above copyright | ||
14 | * notice, this list of conditions and the following disclaimer in | ||
15 | * the documentation and/or other materials provided with the | ||
16 | * distribution. | ||
17 | * | ||
18 | * 3. All advertising materials mentioning features or use of this | ||
19 | * software must display the following acknowledgment: | ||
20 | * "This product includes software developed by the OpenSSL Project | ||
21 | * for use in the OpenSSL Toolkit. (http://www.openssl.org/)" | ||
22 | * | ||
23 | * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to | ||
24 | * endorse or promote products derived from this software without | ||
25 | * prior written permission. For written permission, please contact | ||
26 | * openssl-core@openssl.org. | ||
27 | * | ||
28 | * 5. Products derived from this software may not be called "OpenSSL" | ||
29 | * nor may "OpenSSL" appear in their names without prior written | ||
30 | * permission of the OpenSSL Project. | ||
31 | * | ||
32 | * 6. Redistributions of any form whatsoever must retain the following | ||
33 | * acknowledgment: | ||
34 | * "This product includes software developed by the OpenSSL Project | ||
35 | * for use in the OpenSSL Toolkit (http://www.openssl.org/)" | ||
36 | * | ||
37 | * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY | ||
38 | * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | ||
39 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR | ||
40 | * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR | ||
41 | * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, | ||
42 | * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT | ||
43 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; | ||
44 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | ||
45 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, | ||
46 | * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) | ||
47 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED | ||
48 | * OF THE POSSIBILITY OF SUCH DAMAGE. | ||
49 | * ==================================================================== | ||
50 | */ | ||
51 | |||
52 | #include <string.h> | ||
53 | |||
54 | #include <openssl/opensslconf.h> | ||
55 | |||
56 | #ifndef OPENSSL_NO_GOST | ||
57 | |||
58 | #include <openssl/gost.h> | ||
59 | |||
60 | #include "gost_locl.h" | ||
61 | |||
62 | static void key_diversify_crypto_pro(GOST2814789_KEY * ctx, const unsigned char *inputKey, | ||
63 | const unsigned char *ukm, unsigned char *outputKey) | ||
64 | { | ||
65 | |||
66 | unsigned long k, s1, s2; | ||
67 | int i, mask; | ||
68 | unsigned char S[8]; | ||
69 | unsigned char *p; | ||
70 | memcpy(outputKey, inputKey, 32); | ||
71 | for (i = 0; i < 8; i++) { | ||
72 | /* Make array of integers from key */ | ||
73 | /* Compute IV S */ | ||
74 | s1 = 0, s2 = 0; | ||
75 | p = outputKey; | ||
76 | for (mask = 1; mask < 256; mask <<= 1) { | ||
77 | c2l(p, k); | ||
78 | if (mask & ukm[i]) { | ||
79 | s1 += k; | ||
80 | } else { | ||
81 | s2 += k; | ||
82 | } | ||
83 | } | ||
84 | p = S; | ||
85 | l2c (s1, p); | ||
86 | l2c (s2, p); | ||
87 | Gost2814789_set_key(ctx, outputKey, 256); | ||
88 | mask = 0; | ||
89 | Gost2814789_cfb64_encrypt(outputKey, outputKey, 32, ctx, S, &mask, 1); | ||
90 | } | ||
91 | } | ||
92 | |||
93 | int key_wrap_crypto_pro(int nid, const unsigned char *keyExchangeKey, | ||
94 | const unsigned char *ukm, const unsigned char *sessionKey, | ||
95 | unsigned char *wrappedKey) | ||
96 | { | ||
97 | GOST2814789_KEY ctx; | ||
98 | unsigned char kek_ukm[32]; | ||
99 | |||
100 | Gost2814789_set_sbox(&ctx, nid); | ||
101 | key_diversify_crypto_pro(&ctx, keyExchangeKey, ukm, kek_ukm); | ||
102 | Gost2814789_set_key(&ctx, kek_ukm, 256); | ||
103 | memcpy(wrappedKey, ukm, 8); | ||
104 | Gost2814789_encrypt(sessionKey + 0, wrappedKey + 8 + 0, &ctx); | ||
105 | Gost2814789_encrypt(sessionKey + 8, wrappedKey + 8 + 8, &ctx); | ||
106 | Gost2814789_encrypt(sessionKey + 16, wrappedKey + 8 + 16, &ctx); | ||
107 | Gost2814789_encrypt(sessionKey + 24, wrappedKey + 8 + 24, &ctx); | ||
108 | GOST2814789IMIT(sessionKey, 32, wrappedKey + 40, nid, kek_ukm, ukm); | ||
109 | return 1; | ||
110 | } | ||
111 | |||
112 | int key_unwrap_crypto_pro(int nid, const unsigned char *keyExchangeKey, | ||
113 | const unsigned char *wrappedKey, | ||
114 | unsigned char *sessionKey) | ||
115 | { | ||
116 | unsigned char kek_ukm[32], cek_mac[4]; | ||
117 | GOST2814789_KEY ctx; | ||
118 | |||
119 | Gost2814789_set_sbox(&ctx, nid); | ||
120 | /* First 8 bytes of wrapped Key is ukm */ | ||
121 | key_diversify_crypto_pro(&ctx, keyExchangeKey, wrappedKey, kek_ukm); | ||
122 | Gost2814789_set_key(&ctx, kek_ukm, 256); | ||
123 | Gost2814789_decrypt(wrappedKey + 8 + 0, sessionKey + 0, &ctx); | ||
124 | Gost2814789_decrypt(wrappedKey + 8 + 8, sessionKey + 8, &ctx); | ||
125 | Gost2814789_decrypt(wrappedKey + 8 + 16, sessionKey + 16, &ctx); | ||
126 | Gost2814789_decrypt(wrappedKey + 8 + 24, sessionKey + 24, &ctx); | ||
127 | |||
128 | GOST2814789IMIT(sessionKey, 32, cek_mac, nid, kek_ukm, wrappedKey); | ||
129 | if (memcmp(cek_mac, wrappedKey + 40, 4)) { | ||
130 | printf("IMIT Missmatch!\n"); | ||
131 | return 0; | ||
132 | } | ||
133 | return 1; | ||
134 | } | ||
135 | |||
136 | #endif | ||
diff --git a/src/lib/libssl/src/crypto/gost/gost89_params.c b/src/lib/libssl/src/crypto/gost/gost89_params.c new file mode 100644 index 0000000000..2b2607d24b --- /dev/null +++ b/src/lib/libssl/src/crypto/gost/gost89_params.c | |||
@@ -0,0 +1,241 @@ | |||
1 | /* $OpenBSD: gost89_params.c,v 1.1 2014/11/09 19:17:13 miod Exp $ */ | ||
2 | /* | ||
3 | * Copyright (c) 2014 Dmitry Eremin-Solenikov <dbaryshkov@gmail.com> | ||
4 | * Copyright (c) 2005-2006 Cryptocom LTD | ||
5 | * | ||
6 | * Redistribution and use in source and binary forms, with or without | ||
7 | * modification, are permitted provided that the following conditions | ||
8 | * are met: | ||
9 | * | ||
10 | * 1. Redistributions of source code must retain the above copyright | ||
11 | * notice, this list of conditions and the following disclaimer. | ||
12 | * | ||
13 | * 2. Redistributions in binary form must reproduce the above copyright | ||
14 | * notice, this list of conditions and the following disclaimer in | ||
15 | * the documentation and/or other materials provided with the | ||
16 | * distribution. | ||
17 | * | ||
18 | * 3. All advertising materials mentioning features or use of this | ||
19 | * software must display the following acknowledgment: | ||
20 | * "This product includes software developed by the OpenSSL Project | ||
21 | * for use in the OpenSSL Toolkit. (http://www.openssl.org/)" | ||
22 | * | ||
23 | * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to | ||
24 | * endorse or promote products derived from this software without | ||
25 | * prior written permission. For written permission, please contact | ||
26 | * openssl-core@openssl.org. | ||
27 | * | ||
28 | * 5. Products derived from this software may not be called "OpenSSL" | ||
29 | * nor may "OpenSSL" appear in their names without prior written | ||
30 | * permission of the OpenSSL Project. | ||
31 | * | ||
32 | * 6. Redistributions of any form whatsoever must retain the following | ||
33 | * acknowledgment: | ||
34 | * "This product includes software developed by the OpenSSL Project | ||
35 | * for use in the OpenSSL Toolkit (http://www.openssl.org/)" | ||
36 | * | ||
37 | * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY | ||
38 | * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | ||
39 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR | ||
40 | * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR | ||
41 | * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, | ||
42 | * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT | ||
43 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; | ||
44 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | ||
45 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, | ||
46 | * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) | ||
47 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED | ||
48 | * OF THE POSSIBILITY OF SUCH DAMAGE. | ||
49 | * ==================================================================== | ||
50 | */ | ||
51 | |||
52 | #include <stdlib.h> | ||
53 | |||
54 | #include <openssl/opensslconf.h> | ||
55 | |||
56 | #ifndef OPENSSL_NO_GOST | ||
57 | #include <openssl/objects.h> | ||
58 | #include <openssl/gost.h> | ||
59 | |||
60 | #include "gost_locl.h" | ||
61 | |||
62 | /* Substitution blocks from test examples for GOST R 34.11-94*/ | ||
63 | static const gost_subst_block GostR3411_94_TestParamSet = { | ||
64 | {0x1,0xF,0xD,0x0,0x5,0x7,0xA,0x4,0x9,0x2,0x3,0xE,0x6,0xB,0x8,0xC}, | ||
65 | {0xD,0xB,0x4,0x1,0x3,0xF,0x5,0x9,0x0,0xA,0xE,0x7,0x6,0x8,0x2,0xC}, | ||
66 | {0x4,0xB,0xA,0x0,0x7,0x2,0x1,0xD,0x3,0x6,0x8,0x5,0x9,0xC,0xF,0xE}, | ||
67 | {0x6,0xC,0x7,0x1,0x5,0xF,0xD,0x8,0x4,0xA,0x9,0xE,0x0,0x3,0xB,0x2}, | ||
68 | {0x7,0xD,0xA,0x1,0x0,0x8,0x9,0xF,0xE,0x4,0x6,0xC,0xB,0x2,0x5,0x3}, | ||
69 | {0x5,0x8,0x1,0xD,0xA,0x3,0x4,0x2,0xE,0xF,0xC,0x7,0x6,0x0,0x9,0xB}, | ||
70 | {0xE,0xB,0x4,0xC,0x6,0xD,0xF,0xA,0x2,0x3,0x8,0x1,0x0,0x7,0x5,0x9}, | ||
71 | {0x4,0xA,0x9,0x2,0xD,0x8,0x0,0xE,0x6,0xB,0x1,0xC,0x7,0xF,0x5,0x3} | ||
72 | }; | ||
73 | |||
74 | /* Substitution blocks for hash function 1.2.643.2.9.1.6.1 */ | ||
75 | static const gost_subst_block GostR3411_94_CryptoProParamSet = { | ||
76 | {0x1,0x3,0xA,0x9,0x5,0xB,0x4,0xF,0x8,0x6,0x7,0xE,0xD,0x0,0x2,0xC}, | ||
77 | {0xD,0xE,0x4,0x1,0x7,0x0,0x5,0xA,0x3,0xC,0x8,0xF,0x6,0x2,0x9,0xB}, | ||
78 | {0x7,0x6,0x2,0x4,0xD,0x9,0xF,0x0,0xA,0x1,0x5,0xB,0x8,0xE,0xC,0x3}, | ||
79 | {0x7,0x6,0x4,0xB,0x9,0xC,0x2,0xA,0x1,0x8,0x0,0xE,0xF,0xD,0x3,0x5}, | ||
80 | {0x4,0xA,0x7,0xC,0x0,0xF,0x2,0x8,0xE,0x1,0x6,0x5,0xD,0xB,0x9,0x3}, | ||
81 | {0x7,0xF,0xC,0xE,0x9,0x4,0x1,0x0,0x3,0xB,0x5,0x2,0x6,0xA,0x8,0xD}, | ||
82 | {0x5,0xF,0x4,0x0,0x2,0xD,0xB,0x9,0x1,0x7,0x6,0x3,0xC,0xE,0xA,0x8}, | ||
83 | {0xA,0x4,0x5,0x6,0x8,0x1,0x3,0x7,0xD,0xC,0xE,0x0,0x9,0x2,0xB,0xF} | ||
84 | }; | ||
85 | |||
86 | /* Test paramset from GOST 28147 */ | ||
87 | gost_subst_block Gost28147_TestParamSet = { | ||
88 | {0xC,0x6,0x5,0x2,0xB,0x0,0x9,0xD,0x3,0xE,0x7,0xA,0xF,0x4,0x1,0x8}, | ||
89 | {0x9,0xB,0xC,0x0,0x3,0x6,0x7,0x5,0x4,0x8,0xE,0xF,0x1,0xA,0x2,0xD}, | ||
90 | {0x8,0xF,0x6,0xB,0x1,0x9,0xC,0x5,0xD,0x3,0x7,0xA,0x0,0xE,0x2,0x4}, | ||
91 | {0x3,0xE,0x5,0x9,0x6,0x8,0x0,0xD,0xA,0xB,0x7,0xC,0x2,0x1,0xF,0x4}, | ||
92 | {0xE,0x9,0xB,0x2,0x5,0xF,0x7,0x1,0x0,0xD,0xC,0x6,0xA,0x4,0x3,0x8}, | ||
93 | {0xD,0x8,0xE,0xC,0x7,0x3,0x9,0xA,0x1,0x5,0x2,0x4,0x6,0xF,0x0,0xB}, | ||
94 | {0xC,0x9,0xF,0xE,0x8,0x1,0x3,0xA,0x2,0x7,0x4,0xD,0x6,0x0,0xB,0x5}, | ||
95 | {0x4,0x2,0xF,0x5,0x9,0x1,0x0,0x8,0xE,0x3,0xB,0xC,0xD,0x7,0xA,0x6} | ||
96 | }; | ||
97 | |||
98 | |||
99 | /* 1.2.643.2.2.31.1 */ | ||
100 | static const gost_subst_block Gost28147_CryptoProParamSetA = { | ||
101 | {0xB,0xA,0xF,0x5,0x0,0xC,0xE,0x8,0x6,0x2,0x3,0x9,0x1,0x7,0xD,0x4}, | ||
102 | {0x1,0xD,0x2,0x9,0x7,0xA,0x6,0x0,0x8,0xC,0x4,0x5,0xF,0x3,0xB,0xE}, | ||
103 | {0x3,0xA,0xD,0xC,0x1,0x2,0x0,0xB,0x7,0x5,0x9,0x4,0x8,0xF,0xE,0x6}, | ||
104 | {0xB,0x5,0x1,0x9,0x8,0xD,0xF,0x0,0xE,0x4,0x2,0x3,0xC,0x7,0xA,0x6}, | ||
105 | {0xE,0x7,0xA,0xC,0xD,0x1,0x3,0x9,0x0,0x2,0xB,0x4,0xF,0x8,0x5,0x6}, | ||
106 | {0xE,0x4,0x6,0x2,0xB,0x3,0xD,0x8,0xC,0xF,0x5,0xA,0x0,0x7,0x1,0x9}, | ||
107 | {0x3,0x7,0xE,0x9,0x8,0xA,0xF,0x0,0x5,0x2,0x6,0xC,0xB,0x4,0xD,0x1}, | ||
108 | {0x9,0x6,0x3,0x2,0x8,0xB,0x1,0x7,0xA,0x4,0xE,0xF,0xC,0x0,0xD,0x5} | ||
109 | }; | ||
110 | |||
111 | /* 1.2.643.2.2.31.2 */ | ||
112 | static const gost_subst_block Gost28147_CryptoProParamSetB = { | ||
113 | {0x0,0x4,0xB,0xE,0x8,0x3,0x7,0x1,0xA,0x2,0x9,0x6,0xF,0xD,0x5,0xC}, | ||
114 | {0x5,0x2,0xA,0xB,0x9,0x1,0xC,0x3,0x7,0x4,0xD,0x0,0x6,0xF,0x8,0xE}, | ||
115 | {0x8,0x3,0x2,0x6,0x4,0xD,0xE,0xB,0xC,0x1,0x7,0xF,0xA,0x0,0x9,0x5}, | ||
116 | {0x2,0x7,0xC,0xF,0x9,0x5,0xA,0xB,0x1,0x4,0x0,0xD,0x6,0x8,0xE,0x3}, | ||
117 | {0x7,0x5,0x0,0xD,0xB,0x6,0x1,0x2,0x3,0xA,0xC,0xF,0x4,0xE,0x9,0x8}, | ||
118 | {0xE,0xC,0x0,0xA,0x9,0x2,0xD,0xB,0x7,0x5,0x8,0xF,0x3,0x6,0x1,0x4}, | ||
119 | {0x0,0x1,0x2,0xA,0x4,0xD,0x5,0xC,0x9,0x7,0x3,0xF,0xB,0x8,0x6,0xE}, | ||
120 | {0x8,0x4,0xB,0x1,0x3,0x5,0x0,0x9,0x2,0xE,0xA,0xC,0xD,0x6,0x7,0xF} | ||
121 | }; | ||
122 | |||
123 | /* 1.2.643.2.2.31.3 */ | ||
124 | static const gost_subst_block Gost28147_CryptoProParamSetC = { | ||
125 | {0x7,0x4,0x0,0x5,0xA,0x2,0xF,0xE,0xC,0x6,0x1,0xB,0xD,0x9,0x3,0x8}, | ||
126 | {0xA,0x9,0x6,0x8,0xD,0xE,0x2,0x0,0xF,0x3,0x5,0xB,0x4,0x1,0xC,0x7}, | ||
127 | {0xC,0x9,0xB,0x1,0x8,0xE,0x2,0x4,0x7,0x3,0x6,0x5,0xA,0x0,0xF,0xD}, | ||
128 | {0x8,0xD,0xB,0x0,0x4,0x5,0x1,0x2,0x9,0x3,0xC,0xE,0x6,0xF,0xA,0x7}, | ||
129 | {0x3,0x6,0x0,0x1,0x5,0xD,0xA,0x8,0xB,0x2,0x9,0x7,0xE,0xF,0xC,0x4}, | ||
130 | {0x8,0x2,0x5,0x0,0x4,0x9,0xF,0xA,0x3,0x7,0xC,0xD,0x6,0xE,0x1,0xB}, | ||
131 | {0x0,0x1,0x7,0xD,0xB,0x4,0x5,0x2,0x8,0xE,0xF,0xC,0x9,0xA,0x6,0x3}, | ||
132 | {0x1,0xB,0xC,0x2,0x9,0xD,0x0,0xF,0x4,0x5,0x8,0xE,0xA,0x7,0x6,0x3} | ||
133 | }; | ||
134 | |||
135 | /* 1.2.643.2.2.31.4 */ | ||
136 | static const gost_subst_block Gost28147_CryptoProParamSetD = { | ||
137 | {0x1,0xA,0x6,0x8,0xF,0xB,0x0,0x4,0xC,0x3,0x5,0x9,0x7,0xD,0x2,0xE}, | ||
138 | {0x3,0x0,0x6,0xF,0x1,0xE,0x9,0x2,0xD,0x8,0xC,0x4,0xB,0xA,0x5,0x7}, | ||
139 | {0x8,0x0,0xF,0x3,0x2,0x5,0xE,0xB,0x1,0xA,0x4,0x7,0xC,0x9,0xD,0x6}, | ||
140 | {0x0,0xC,0x8,0x9,0xD,0x2,0xA,0xB,0x7,0x3,0x6,0x5,0x4,0xE,0xF,0x1}, | ||
141 | {0x1,0x5,0xE,0xC,0xA,0x7,0x0,0xD,0x6,0x2,0xB,0x4,0x9,0x3,0xF,0x8}, | ||
142 | {0x1,0xC,0xB,0x0,0xF,0xE,0x6,0x5,0xA,0xD,0x4,0x8,0x9,0x3,0x7,0x2}, | ||
143 | {0xB,0x6,0x3,0x4,0xC,0xF,0xE,0x2,0x7,0xD,0x8,0x0,0x5,0xA,0x9,0x1}, | ||
144 | {0xF,0xC,0x2,0xA,0x6,0x4,0x5,0x0,0x7,0x9,0xE,0xD,0x1,0xB,0x8,0x3} | ||
145 | }; | ||
146 | |||
147 | static const gost_subst_block Gost28147_TC26ParamSetZ = { | ||
148 | {0x1,0x7,0xe,0xd,0x0,0x5,0x8,0x3,0x4,0xf,0xa,0x6,0x9,0xc,0xb,0x2}, | ||
149 | {0x8,0xe,0x2,0x5,0x6,0x9,0x1,0xc,0xf,0x4,0xb,0x0,0xd,0xa,0x3,0x7}, | ||
150 | {0x5,0xd,0xf,0x6,0x9,0x2,0xc,0xa,0xb,0x7,0x8,0x1,0x4,0x3,0xe,0x0}, | ||
151 | {0x7,0xf,0x5,0xa,0x8,0x1,0x6,0xd,0x0,0x9,0x3,0xe,0xb,0x4,0x2,0xc}, | ||
152 | {0xc,0x8,0x2,0x1,0xd,0x4,0xf,0x6,0x7,0x0,0xa,0x5,0x3,0xe,0x9,0xb}, | ||
153 | {0xb,0x3,0x5,0x8,0x2,0xf,0xa,0xd,0xe,0x1,0x7,0x4,0xc,0x9,0x6,0x0}, | ||
154 | {0x6,0x8,0x2,0x3,0x9,0xa,0x5,0xc,0x1,0xe,0x4,0x7,0xb,0xd,0x0,0xf}, | ||
155 | {0xc,0x4,0x6,0x2,0xa,0x5,0xb,0x9,0xe,0x8,0xd,0x7,0x0,0x3,0xf,0x1} | ||
156 | }; | ||
157 | |||
158 | static const unsigned char CryptoProKeyMeshingKey[] = { | ||
159 | 0x69, 0x00, 0x72, 0x22, 0x64, 0xC9, 0x04, 0x23, | ||
160 | 0x8D, 0x3A, 0xDB, 0x96, 0x46, 0xE9, 0x2A, 0xC4, | ||
161 | 0x18, 0xFE, 0xAC, 0x94, 0x00, 0xED, 0x07, 0x12, | ||
162 | 0xC0, 0x86, 0xDC, 0xC2, 0xEF, 0x4C, 0xA9, 0x2B | ||
163 | }; | ||
164 | |||
165 | static const struct gost89_parameters_info { | ||
166 | int nid; | ||
167 | const gost_subst_block *sblock; | ||
168 | int key_meshing; | ||
169 | } gost_cipher_list[] = | ||
170 | { | ||
171 | {NID_id_Gost28147_89_CryptoPro_A_ParamSet,&Gost28147_CryptoProParamSetA,1}, | ||
172 | {NID_id_Gost28147_89_CryptoPro_B_ParamSet,&Gost28147_CryptoProParamSetB,1}, | ||
173 | {NID_id_Gost28147_89_CryptoPro_C_ParamSet,&Gost28147_CryptoProParamSetC,1}, | ||
174 | {NID_id_Gost28147_89_CryptoPro_D_ParamSet,&Gost28147_CryptoProParamSetD,1}, | ||
175 | {NID_id_tc26_gost_28147_param_Z,&Gost28147_TC26ParamSetZ,1}, | ||
176 | {NID_id_Gost28147_89_TestParamSet,&Gost28147_TestParamSet,0}, | ||
177 | {NID_id_GostR3411_94_TestParamSet,&GostR3411_94_TestParamSet,0}, | ||
178 | {NID_id_GostR3411_94_CryptoProParamSet,&GostR3411_94_CryptoProParamSet,0}, | ||
179 | {NID_undef,NULL,0} | ||
180 | }; | ||
181 | |||
182 | int Gost2814789_set_sbox(GOST2814789_KEY *key, int nid) | ||
183 | { | ||
184 | int i; | ||
185 | const gost_subst_block *b = NULL; | ||
186 | unsigned int t; | ||
187 | |||
188 | for (i = 0; gost_cipher_list[i].nid != NID_undef; i++) { | ||
189 | if (gost_cipher_list[i].nid != nid) | ||
190 | continue; | ||
191 | |||
192 | b = gost_cipher_list[i].sblock; | ||
193 | key->key_meshing = gost_cipher_list[i].key_meshing; | ||
194 | break; | ||
195 | } | ||
196 | |||
197 | if (!b) | ||
198 | return 0; | ||
199 | |||
200 | for (i = 0; i < 256; i++) { | ||
201 | t = (unsigned int)(b->k8[i >> 4] <<4 | b->k7 [i & 15]) << 24; | ||
202 | key->k87[i] = (t << 11) | (t >> 21); | ||
203 | t = (unsigned int)(b->k6[i >> 4] <<4 | b->k5 [i & 15]) << 16; | ||
204 | key->k65[i] = (t << 11) | (t >> 21); | ||
205 | t = (unsigned int)(b->k4[i >> 4] <<4 | b->k3 [i & 15]) << 8; | ||
206 | key->k43[i] = (t << 11) | (t >> 21); | ||
207 | t = (unsigned int)(b->k2[i >> 4] <<4 | b->k1 [i & 15]) << 0; | ||
208 | key->k21[i] = (t << 11) | (t >> 21); | ||
209 | } | ||
210 | |||
211 | return 1; | ||
212 | } | ||
213 | |||
214 | int Gost2814789_set_key(GOST2814789_KEY *key, | ||
215 | const unsigned char *userKey, const int bits) | ||
216 | { | ||
217 | int i; | ||
218 | |||
219 | if (bits != 256) | ||
220 | return 0; | ||
221 | |||
222 | for (i = 0; i < 8; i++) | ||
223 | c2l(userKey, key->key[i]); | ||
224 | |||
225 | key->count = 0; | ||
226 | |||
227 | return 1; | ||
228 | } | ||
229 | |||
230 | void Gost2814789_cryptopro_key_mesh(GOST2814789_KEY *key) | ||
231 | { | ||
232 | unsigned char newkey[32]; | ||
233 | |||
234 | Gost2814789_decrypt(CryptoProKeyMeshingKey + 0, newkey + 0, key); | ||
235 | Gost2814789_decrypt(CryptoProKeyMeshingKey + 8, newkey + 8, key); | ||
236 | Gost2814789_decrypt(CryptoProKeyMeshingKey + 16, newkey + 16, key); | ||
237 | Gost2814789_decrypt(CryptoProKeyMeshingKey + 24, newkey + 24, key); | ||
238 | |||
239 | Gost2814789_set_key(key, newkey, 256); | ||
240 | } | ||
241 | #endif | ||
diff --git a/src/lib/libssl/src/crypto/gost/gost89imit_ameth.c b/src/lib/libssl/src/crypto/gost/gost89imit_ameth.c new file mode 100644 index 0000000000..879c2b0ca0 --- /dev/null +++ b/src/lib/libssl/src/crypto/gost/gost89imit_ameth.c | |||
@@ -0,0 +1,88 @@ | |||
1 | /* $OpenBSD: gost89imit_ameth.c,v 1.1 2014/11/09 19:17:13 miod Exp $ */ | ||
2 | /* | ||
3 | * Copyright (c) 2014 Dmitry Eremin-Solenikov <dbaryshkov@gmail.com> | ||
4 | * Copyright (c) 2005-2006 Cryptocom LTD | ||
5 | * | ||
6 | * Redistribution and use in source and binary forms, with or without | ||
7 | * modification, are permitted provided that the following conditions | ||
8 | * are met: | ||
9 | * | ||
10 | * 1. Redistributions of source code must retain the above copyright | ||
11 | * notice, this list of conditions and the following disclaimer. | ||
12 | * | ||
13 | * 2. Redistributions in binary form must reproduce the above copyright | ||
14 | * notice, this list of conditions and the following disclaimer in | ||
15 | * the documentation and/or other materials provided with the | ||
16 | * distribution. | ||
17 | * | ||
18 | * 3. All advertising materials mentioning features or use of this | ||
19 | * software must display the following acknowledgment: | ||
20 | * "This product includes software developed by the OpenSSL Project | ||
21 | * for use in the OpenSSL Toolkit. (http://www.openssl.org/)" | ||
22 | * | ||
23 | * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to | ||
24 | * endorse or promote products derived from this software without | ||
25 | * prior written permission. For written permission, please contact | ||
26 | * openssl-core@openssl.org. | ||
27 | * | ||
28 | * 5. Products derived from this software may not be called "OpenSSL" | ||
29 | * nor may "OpenSSL" appear in their names without prior written | ||
30 | * permission of the OpenSSL Project. | ||
31 | * | ||
32 | * 6. Redistributions of any form whatsoever must retain the following | ||
33 | * acknowledgment: | ||
34 | * "This product includes software developed by the OpenSSL Project | ||
35 | * for use in the OpenSSL Toolkit (http://www.openssl.org/)" | ||
36 | * | ||
37 | * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY | ||
38 | * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | ||
39 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR | ||
40 | * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR | ||
41 | * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, | ||
42 | * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT | ||
43 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; | ||
44 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | ||
45 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, | ||
46 | * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) | ||
47 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED | ||
48 | * OF THE POSSIBILITY OF SUCH DAMAGE. | ||
49 | * ==================================================================== | ||
50 | */ | ||
51 | |||
52 | #include <openssl/opensslconf.h> | ||
53 | |||
54 | #ifndef OPENSSL_NO_GOST | ||
55 | #include <openssl/evp.h> | ||
56 | |||
57 | #include "asn1_locl.h" | ||
58 | |||
59 | static void mackey_free_gost(EVP_PKEY *pk) | ||
60 | { | ||
61 | if (pk->pkey.ptr) { | ||
62 | free(pk->pkey.ptr); | ||
63 | } | ||
64 | } | ||
65 | |||
66 | static int mac_ctrl_gost(EVP_PKEY *pkey, int op, long arg1, void *arg2) | ||
67 | { | ||
68 | switch (op) { | ||
69 | case ASN1_PKEY_CTRL_DEFAULT_MD_NID: | ||
70 | *(int *)arg2 = NID_id_Gost28147_89_MAC; | ||
71 | return 2; | ||
72 | } | ||
73 | return -2; | ||
74 | } | ||
75 | |||
76 | const EVP_PKEY_ASN1_METHOD gostimit_asn1_meth = { | ||
77 | .pkey_id = EVP_PKEY_GOSTIMIT, | ||
78 | .pkey_base_id = EVP_PKEY_GOSTIMIT, | ||
79 | .pkey_flags = ASN1_PKEY_SIGPARAM_NULL, | ||
80 | |||
81 | .pem_str = "GOST-MAC", | ||
82 | .info = "GOST 28147-89 MAC", | ||
83 | |||
84 | .pkey_free = mackey_free_gost, | ||
85 | .pkey_ctrl = mac_ctrl_gost, | ||
86 | }; | ||
87 | |||
88 | #endif | ||
diff --git a/src/lib/libssl/src/crypto/gost/gost89imit_pmeth.c b/src/lib/libssl/src/crypto/gost/gost89imit_pmeth.c new file mode 100644 index 0000000000..ec9c72372c --- /dev/null +++ b/src/lib/libssl/src/crypto/gost/gost89imit_pmeth.c | |||
@@ -0,0 +1,230 @@ | |||
1 | /* $OpenBSD: gost89imit_pmeth.c,v 1.1 2014/11/09 19:17:13 miod Exp $ */ | ||
2 | /* | ||
3 | * Copyright (c) 2014 Dmitry Eremin-Solenikov <dbaryshkov@gmail.com> | ||
4 | * Copyright (c) 2005-2006 Cryptocom LTD | ||
5 | * | ||
6 | * Redistribution and use in source and binary forms, with or without | ||
7 | * modification, are permitted provided that the following conditions | ||
8 | * are met: | ||
9 | * | ||
10 | * 1. Redistributions of source code must retain the above copyright | ||
11 | * notice, this list of conditions and the following disclaimer. | ||
12 | * | ||
13 | * 2. Redistributions in binary form must reproduce the above copyright | ||
14 | * notice, this list of conditions and the following disclaimer in | ||
15 | * the documentation and/or other materials provided with the | ||
16 | * distribution. | ||
17 | * | ||
18 | * 3. All advertising materials mentioning features or use of this | ||
19 | * software must display the following acknowledgment: | ||
20 | * "This product includes software developed by the OpenSSL Project | ||
21 | * for use in the OpenSSL Toolkit. (http://www.openssl.org/)" | ||
22 | * | ||
23 | * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to | ||
24 | * endorse or promote products derived from this software without | ||
25 | * prior written permission. For written permission, please contact | ||
26 | * openssl-core@openssl.org. | ||
27 | * | ||
28 | * 5. Products derived from this software may not be called "OpenSSL" | ||
29 | * nor may "OpenSSL" appear in their names without prior written | ||
30 | * permission of the OpenSSL Project. | ||
31 | * | ||
32 | * 6. Redistributions of any form whatsoever must retain the following | ||
33 | * acknowledgment: | ||
34 | * "This product includes software developed by the OpenSSL Project | ||
35 | * for use in the OpenSSL Toolkit (http://www.openssl.org/)" | ||
36 | * | ||
37 | * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY | ||
38 | * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | ||
39 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR | ||
40 | * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR | ||
41 | * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, | ||
42 | * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT | ||
43 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; | ||
44 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | ||
45 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, | ||
46 | * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) | ||
47 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED | ||
48 | * OF THE POSSIBILITY OF SUCH DAMAGE. | ||
49 | * ==================================================================== | ||
50 | */ | ||
51 | |||
52 | #include <string.h> | ||
53 | |||
54 | #include <openssl/opensslconf.h> | ||
55 | |||
56 | #ifndef OPENSSL_NO_GOST | ||
57 | #include <openssl/evp.h> | ||
58 | #include <openssl/err.h> | ||
59 | #include <openssl/gost.h> | ||
60 | #include <openssl/x509v3.h> /*For string_to_hex */ | ||
61 | |||
62 | #include "evp_locl.h" | ||
63 | #include "gost_locl.h" | ||
64 | |||
65 | struct gost_mac_pmeth_data { | ||
66 | EVP_MD *md; | ||
67 | unsigned char key[32]; | ||
68 | unsigned key_set : 1; | ||
69 | }; | ||
70 | |||
71 | static int pkey_gost_mac_init(EVP_PKEY_CTX *ctx) | ||
72 | { | ||
73 | struct gost_mac_pmeth_data *data; | ||
74 | |||
75 | data = calloc(1, sizeof(struct gost_mac_pmeth_data)); | ||
76 | if (!data) | ||
77 | return 0; | ||
78 | EVP_PKEY_CTX_set_data(ctx,data); | ||
79 | return 1; | ||
80 | } | ||
81 | |||
82 | static void pkey_gost_mac_cleanup (EVP_PKEY_CTX *ctx) | ||
83 | { | ||
84 | struct gost_mac_pmeth_data *data = EVP_PKEY_CTX_get_data(ctx); | ||
85 | free(data); | ||
86 | } | ||
87 | |||
88 | static int pkey_gost_mac_copy(EVP_PKEY_CTX *dst, EVP_PKEY_CTX *src) | ||
89 | { | ||
90 | struct gost_mac_pmeth_data *dst_data, *src_data; | ||
91 | |||
92 | if (!pkey_gost_mac_init(dst)) | ||
93 | return 0; | ||
94 | |||
95 | src_data = EVP_PKEY_CTX_get_data(src); | ||
96 | dst_data = EVP_PKEY_CTX_get_data(dst); | ||
97 | |||
98 | *dst_data = *src_data; | ||
99 | |||
100 | return 1; | ||
101 | } | ||
102 | |||
103 | static int pkey_gost_mac_keygen(EVP_PKEY_CTX *ctx, EVP_PKEY *pkey) | ||
104 | { | ||
105 | struct gost_mac_pmeth_data *data = EVP_PKEY_CTX_get_data(ctx); | ||
106 | unsigned char *keydata; | ||
107 | |||
108 | if (!data->key_set) { | ||
109 | GOSTerr(GOST_F_PKEY_GOST_MAC_KEYGEN, GOST_R_MAC_KEY_NOT_SET); | ||
110 | return 0; | ||
111 | } | ||
112 | |||
113 | keydata = malloc(32); | ||
114 | memcpy(keydata, data->key, 32); | ||
115 | EVP_PKEY_assign(pkey, NID_id_Gost28147_89_MAC, keydata); | ||
116 | |||
117 | return 1; | ||
118 | } | ||
119 | |||
120 | static int pkey_gost_mac_ctrl(EVP_PKEY_CTX *ctx, int type, int p1, void *p2) | ||
121 | { | ||
122 | struct gost_mac_pmeth_data *data = EVP_PKEY_CTX_get_data(ctx); | ||
123 | |||
124 | switch (type) { | ||
125 | case EVP_PKEY_CTRL_MD: | ||
126 | if (EVP_MD_type(p2) != NID_id_Gost28147_89_MAC) { | ||
127 | GOSTerr(GOST_F_PKEY_GOST_MAC_CTRL, GOST_R_INVALID_DIGEST_TYPE); | ||
128 | return 0; | ||
129 | } | ||
130 | data->md = p2; | ||
131 | return 1; | ||
132 | |||
133 | case EVP_PKEY_CTRL_SET_MAC_KEY: | ||
134 | if (p1 != 32) { | ||
135 | GOSTerr(GOST_F_PKEY_GOST_MAC_CTRL, GOST_R_INVALID_MAC_KEY_LENGTH); | ||
136 | return 0; | ||
137 | } | ||
138 | |||
139 | memcpy(data->key, p2, 32); | ||
140 | data->key_set = 1; | ||
141 | return 1; | ||
142 | |||
143 | case EVP_PKEY_CTRL_DIGESTINIT: | ||
144 | { | ||
145 | EVP_MD_CTX *mctx = p2; | ||
146 | void *key; | ||
147 | if (!data->key_set) { | ||
148 | EVP_PKEY *pkey = EVP_PKEY_CTX_get0_pkey(ctx); | ||
149 | if (!pkey) { | ||
150 | GOSTerr(GOST_F_PKEY_GOST_MAC_CTRL, GOST_R_MAC_KEY_NOT_SET); | ||
151 | return 0; | ||
152 | } | ||
153 | key = EVP_PKEY_get0(pkey); | ||
154 | if (!key) { | ||
155 | GOSTerr(GOST_F_PKEY_GOST_MAC_CTRL, GOST_R_MAC_KEY_NOT_SET); | ||
156 | return 0; | ||
157 | } | ||
158 | } else { | ||
159 | key = &(data->key); | ||
160 | } | ||
161 | if (!mctx->digest->md_ctrl) | ||
162 | return 0; | ||
163 | return mctx->digest->md_ctrl(mctx, EVP_MD_CTRL_SET_KEY, 32 * 8, key); | ||
164 | } | ||
165 | |||
166 | } | ||
167 | |||
168 | return -2; | ||
169 | } | ||
170 | static int pkey_gost_mac_ctrl_str(EVP_PKEY_CTX *ctx, | ||
171 | const char *type, const char *value) | ||
172 | { | ||
173 | if (!value) | ||
174 | return 0; | ||
175 | if (!strcmp(type, "key")) { | ||
176 | void *p = (void *)value; | ||
177 | return pkey_gost_mac_ctrl(ctx, EVP_PKEY_CTRL_SET_MAC_KEY, strlen(value), p); | ||
178 | } | ||
179 | if (!strcmp(type, "hexkey")) { | ||
180 | unsigned char *key; | ||
181 | int r; | ||
182 | long keylen; | ||
183 | key = string_to_hex(value, &keylen); | ||
184 | if (!key) | ||
185 | return 0; | ||
186 | r = pkey_gost_mac_ctrl(ctx, EVP_PKEY_CTRL_SET_MAC_KEY, keylen, key); | ||
187 | free(key); | ||
188 | return r; | ||
189 | } | ||
190 | return -2; | ||
191 | } | ||
192 | |||
193 | static int pkey_gost_mac_signctx_init(EVP_PKEY_CTX *ctx, EVP_MD_CTX *mctx) | ||
194 | { | ||
195 | return 1; | ||
196 | } | ||
197 | |||
198 | static int pkey_gost_mac_signctx(EVP_PKEY_CTX *ctx, unsigned char *sig, size_t *siglen, EVP_MD_CTX *mctx) | ||
199 | { | ||
200 | unsigned int tmpsiglen=*siglen; /* for platforms where sizeof(int)!=sizeof(size_t)*/ | ||
201 | int ret; | ||
202 | |||
203 | |||
204 | if (!sig) { | ||
205 | *siglen = 4; | ||
206 | return 1; | ||
207 | } | ||
208 | |||
209 | ret = EVP_DigestFinal_ex(mctx, sig, &tmpsiglen); | ||
210 | *siglen = tmpsiglen; | ||
211 | return ret; | ||
212 | } | ||
213 | |||
214 | const EVP_PKEY_METHOD gostimit_pkey_meth = { | ||
215 | .pkey_id = EVP_PKEY_GOSTIMIT, | ||
216 | |||
217 | .init = pkey_gost_mac_init, | ||
218 | .cleanup = pkey_gost_mac_cleanup, | ||
219 | .copy = pkey_gost_mac_copy, | ||
220 | |||
221 | .keygen = pkey_gost_mac_keygen, | ||
222 | |||
223 | .signctx_init = pkey_gost_mac_signctx_init, | ||
224 | .signctx = pkey_gost_mac_signctx, | ||
225 | |||
226 | .ctrl = pkey_gost_mac_ctrl, | ||
227 | .ctrl_str = pkey_gost_mac_ctrl_str, | ||
228 | }; | ||
229 | |||
230 | #endif | ||
diff --git a/src/lib/libssl/src/crypto/gost/gost_asn1.c b/src/lib/libssl/src/crypto/gost/gost_asn1.c new file mode 100644 index 0000000000..b8ed244e49 --- /dev/null +++ b/src/lib/libssl/src/crypto/gost/gost_asn1.c | |||
@@ -0,0 +1,53 @@ | |||
1 | /********************************************************************** | ||
2 | * gost_keytrans.c * | ||
3 | * Copyright (c) 2005-2006 Cryptocom LTD * | ||
4 | * This file is distributed under the same license as OpenSSL * | ||
5 | * * | ||
6 | * ASN1 structure definition for GOST key transport * | ||
7 | * Requires OpenSSL 0.9.9 for compilation * | ||
8 | **********************************************************************/ | ||
9 | |||
10 | #include <openssl/opensslconf.h> | ||
11 | |||
12 | #ifndef OPENSSL_NO_GOST | ||
13 | #include <openssl/asn1t.h> | ||
14 | #include <openssl/x509.h> | ||
15 | #include <openssl/gost.h> | ||
16 | |||
17 | #include "gost_locl.h" | ||
18 | #include "gost_asn1.h" | ||
19 | |||
20 | ASN1_NDEF_SEQUENCE(GOST_KEY_TRANSPORT) = { | ||
21 | ASN1_SIMPLE(GOST_KEY_TRANSPORT, key_info, GOST_KEY_INFO), | ||
22 | ASN1_IMP(GOST_KEY_TRANSPORT, key_agreement_info, GOST_KEY_AGREEMENT_INFO, 0) | ||
23 | } ASN1_NDEF_SEQUENCE_END(GOST_KEY_TRANSPORT) | ||
24 | IMPLEMENT_ASN1_FUNCTIONS(GOST_KEY_TRANSPORT) | ||
25 | |||
26 | ASN1_NDEF_SEQUENCE(GOST_KEY_INFO) = { | ||
27 | ASN1_SIMPLE(GOST_KEY_INFO, encrypted_key, ASN1_OCTET_STRING), | ||
28 | ASN1_SIMPLE(GOST_KEY_INFO, imit, ASN1_OCTET_STRING) | ||
29 | } ASN1_NDEF_SEQUENCE_END(GOST_KEY_INFO) | ||
30 | IMPLEMENT_ASN1_FUNCTIONS(GOST_KEY_INFO) | ||
31 | |||
32 | ASN1_NDEF_SEQUENCE(GOST_KEY_AGREEMENT_INFO) = { | ||
33 | ASN1_SIMPLE(GOST_KEY_AGREEMENT_INFO, cipher, ASN1_OBJECT), | ||
34 | ASN1_IMP_OPT(GOST_KEY_AGREEMENT_INFO, ephem_key, X509_PUBKEY, 0), | ||
35 | ASN1_SIMPLE(GOST_KEY_AGREEMENT_INFO, eph_iv, ASN1_OCTET_STRING) | ||
36 | } ASN1_NDEF_SEQUENCE_END(GOST_KEY_AGREEMENT_INFO) | ||
37 | IMPLEMENT_ASN1_FUNCTIONS(GOST_KEY_AGREEMENT_INFO) | ||
38 | |||
39 | |||
40 | ASN1_NDEF_SEQUENCE(GOST_KEY_PARAMS) = { | ||
41 | ASN1_SIMPLE(GOST_KEY_PARAMS, key_params, ASN1_OBJECT), | ||
42 | ASN1_SIMPLE(GOST_KEY_PARAMS, hash_params, ASN1_OBJECT), | ||
43 | ASN1_OPT(GOST_KEY_PARAMS, cipher_params, ASN1_OBJECT), | ||
44 | } ASN1_NDEF_SEQUENCE_END(GOST_KEY_PARAMS) | ||
45 | IMPLEMENT_ASN1_FUNCTIONS(GOST_KEY_PARAMS) | ||
46 | |||
47 | ASN1_NDEF_SEQUENCE(GOST_CIPHER_PARAMS) = { | ||
48 | ASN1_SIMPLE(GOST_CIPHER_PARAMS, iv, ASN1_OCTET_STRING), | ||
49 | ASN1_SIMPLE(GOST_CIPHER_PARAMS, enc_param_set, ASN1_OBJECT), | ||
50 | } ASN1_NDEF_SEQUENCE_END(GOST_CIPHER_PARAMS) | ||
51 | IMPLEMENT_ASN1_FUNCTIONS(GOST_CIPHER_PARAMS) | ||
52 | |||
53 | #endif | ||
diff --git a/src/lib/libssl/src/crypto/gost/gost_asn1.h b/src/lib/libssl/src/crypto/gost/gost_asn1.h new file mode 100644 index 0000000000..62719c70cd --- /dev/null +++ b/src/lib/libssl/src/crypto/gost/gost_asn1.h | |||
@@ -0,0 +1,87 @@ | |||
1 | /* $OpenBSD: gost_asn1.h,v 1.1 2014/11/09 19:17:13 miod Exp $ */ | ||
2 | /* | ||
3 | * Copyright (c) 2014 Dmitry Eremin-Solenikov <dbaryshkov@gmail.com> | ||
4 | * Copyright (c) 2005-2006 Cryptocom LTD | ||
5 | * | ||
6 | * Redistribution and use in source and binary forms, with or without | ||
7 | * modification, are permitted provided that the following conditions | ||
8 | * are met: | ||
9 | * | ||
10 | * 1. Redistributions of source code must retain the above copyright | ||
11 | * notice, this list of conditions and the following disclaimer. | ||
12 | * | ||
13 | * 2. Redistributions in binary form must reproduce the above copyright | ||
14 | * notice, this list of conditions and the following disclaimer in | ||
15 | * the documentation and/or other materials provided with the | ||
16 | * distribution. | ||
17 | * | ||
18 | * 3. All advertising materials mentioning features or use of this | ||
19 | * software must display the following acknowledgment: | ||
20 | * "This product includes software developed by the OpenSSL Project | ||
21 | * for use in the OpenSSL Toolkit. (http://www.openssl.org/)" | ||
22 | * | ||
23 | * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to | ||
24 | * endorse or promote products derived from this software without | ||
25 | * prior written permission. For written permission, please contact | ||
26 | * openssl-core@openssl.org. | ||
27 | * | ||
28 | * 5. Products derived from this software may not be called "OpenSSL" | ||
29 | * nor may "OpenSSL" appear in their names without prior written | ||
30 | * permission of the OpenSSL Project. | ||
31 | * | ||
32 | * 6. Redistributions of any form whatsoever must retain the following | ||
33 | * acknowledgment: | ||
34 | * "This product includes software developed by the OpenSSL Project | ||
35 | * for use in the OpenSSL Toolkit (http://www.openssl.org/)" | ||
36 | * | ||
37 | * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY | ||
38 | * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | ||
39 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR | ||
40 | * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR | ||
41 | * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, | ||
42 | * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT | ||
43 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; | ||
44 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | ||
45 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, | ||
46 | * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) | ||
47 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED | ||
48 | * OF THE POSSIBILITY OF SUCH DAMAGE. | ||
49 | * ==================================================================== | ||
50 | */ | ||
51 | |||
52 | #ifndef HEADER_GOST_ASN1_H | ||
53 | #define HEADER_GOST_ASN1_H | ||
54 | |||
55 | #include <openssl/asn1.h> | ||
56 | |||
57 | typedef struct { | ||
58 | ASN1_OCTET_STRING *encrypted_key; | ||
59 | ASN1_OCTET_STRING *imit; | ||
60 | } GOST_KEY_INFO; | ||
61 | |||
62 | DECLARE_ASN1_FUNCTIONS(GOST_KEY_INFO) | ||
63 | |||
64 | typedef struct { | ||
65 | ASN1_OBJECT *cipher; | ||
66 | X509_PUBKEY *ephem_key; | ||
67 | ASN1_OCTET_STRING *eph_iv; | ||
68 | } GOST_KEY_AGREEMENT_INFO; | ||
69 | |||
70 | DECLARE_ASN1_FUNCTIONS(GOST_KEY_AGREEMENT_INFO) | ||
71 | |||
72 | typedef struct { | ||
73 | GOST_KEY_INFO *key_info; | ||
74 | GOST_KEY_AGREEMENT_INFO *key_agreement_info; | ||
75 | } GOST_KEY_TRANSPORT; | ||
76 | |||
77 | DECLARE_ASN1_FUNCTIONS(GOST_KEY_TRANSPORT) | ||
78 | |||
79 | typedef struct { | ||
80 | ASN1_OBJECT *key_params; | ||
81 | ASN1_OBJECT *hash_params; | ||
82 | ASN1_OBJECT *cipher_params; | ||
83 | } GOST_KEY_PARAMS; | ||
84 | |||
85 | DECLARE_ASN1_FUNCTIONS(GOST_KEY_PARAMS) | ||
86 | |||
87 | #endif | ||
diff --git a/src/lib/libssl/src/crypto/gost/gost_err.c b/src/lib/libssl/src/crypto/gost/gost_err.c new file mode 100644 index 0000000000..a52fe4cd5a --- /dev/null +++ b/src/lib/libssl/src/crypto/gost/gost_err.c | |||
@@ -0,0 +1,143 @@ | |||
1 | /* crypto/gost/gost_err.c */ | ||
2 | /* ==================================================================== | ||
3 | * Copyright (c) 1999-2014 The OpenSSL Project. All rights reserved. | ||
4 | * | ||
5 | * Redistribution and use in source and binary forms, with or without | ||
6 | * modification, are permitted provided that the following conditions | ||
7 | * are met: | ||
8 | * | ||
9 | * 1. Redistributions of source code must retain the above copyright | ||
10 | * notice, this list of conditions and the following disclaimer. | ||
11 | * | ||
12 | * 2. Redistributions in binary form must reproduce the above copyright | ||
13 | * notice, this list of conditions and the following disclaimer in | ||
14 | * the documentation and/or other materials provided with the | ||
15 | * distribution. | ||
16 | * | ||
17 | * 3. All advertising materials mentioning features or use of this | ||
18 | * software must display the following acknowledgment: | ||
19 | * "This product includes software developed by the OpenSSL Project | ||
20 | * for use in the OpenSSL Toolkit. (http://www.OpenSSL.org/)" | ||
21 | * | ||
22 | * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to | ||
23 | * endorse or promote products derived from this software without | ||
24 | * prior written permission. For written permission, please contact | ||
25 | * openssl-core@OpenSSL.org. | ||
26 | * | ||
27 | * 5. Products derived from this software may not be called "OpenSSL" | ||
28 | * nor may "OpenSSL" appear in their names without prior written | ||
29 | * permission of the OpenSSL Project. | ||
30 | * | ||
31 | * 6. Redistributions of any form whatsoever must retain the following | ||
32 | * acknowledgment: | ||
33 | * "This product includes software developed by the OpenSSL Project | ||
34 | * for use in the OpenSSL Toolkit (http://www.OpenSSL.org/)" | ||
35 | * | ||
36 | * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY | ||
37 | * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | ||
38 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR | ||
39 | * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR | ||
40 | * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, | ||
41 | * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT | ||
42 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; | ||
43 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | ||
44 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, | ||
45 | * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) | ||
46 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED | ||
47 | * OF THE POSSIBILITY OF SUCH DAMAGE. | ||
48 | * ==================================================================== | ||
49 | * | ||
50 | * This product includes cryptographic software written by Eric Young | ||
51 | * (eay@cryptsoft.com). This product includes software written by Tim | ||
52 | * Hudson (tjh@cryptsoft.com). | ||
53 | * | ||
54 | */ | ||
55 | |||
56 | /* NOTE: this file was auto generated by the mkerr.pl script: any changes | ||
57 | * made to it will be overwritten when the script next updates this file, | ||
58 | * only reason strings will be preserved. | ||
59 | */ | ||
60 | |||
61 | #include <stdio.h> | ||
62 | #include <openssl/err.h> | ||
63 | #include <openssl/gost.h> | ||
64 | |||
65 | /* BEGIN ERROR CODES */ | ||
66 | #ifndef OPENSSL_NO_ERR | ||
67 | |||
68 | #define ERR_FUNC(func) ERR_PACK(ERR_LIB_GOST,func,0) | ||
69 | #define ERR_REASON(reason) ERR_PACK(ERR_LIB_GOST,0,reason) | ||
70 | |||
71 | static ERR_STRING_DATA GOST_str_functs[]= | ||
72 | { | ||
73 | {ERR_FUNC(GOST_F_DECODE_GOST01_ALGOR_PARAMS), "DECODE_GOST01_ALGOR_PARAMS"}, | ||
74 | {ERR_FUNC(GOST_F_ENCODE_GOST01_ALGOR_PARAMS), "ENCODE_GOST01_ALGOR_PARAMS"}, | ||
75 | {ERR_FUNC(GOST_F_GOST2001_COMPUTE_PUBLIC), "GOST2001_COMPUTE_PUBLIC"}, | ||
76 | {ERR_FUNC(GOST_F_GOST2001_DO_SIGN), "GOST2001_DO_SIGN"}, | ||
77 | {ERR_FUNC(GOST_F_GOST2001_DO_VERIFY), "GOST2001_DO_VERIFY"}, | ||
78 | {ERR_FUNC(GOST_F_GOST2001_KEYGEN), "GOST2001_KEYGEN"}, | ||
79 | {ERR_FUNC(GOST_F_GOST89_GET_ASN1_PARAMETERS), "GOST89_GET_ASN1_PARAMETERS"}, | ||
80 | {ERR_FUNC(GOST_F_GOST89_SET_ASN1_PARAMETERS), "GOST89_SET_ASN1_PARAMETERS"}, | ||
81 | {ERR_FUNC(GOST_F_GOST_KEY_CHECK_KEY), "GOST_KEY_check_key"}, | ||
82 | {ERR_FUNC(GOST_F_GOST_KEY_NEW), "GOST_KEY_new"}, | ||
83 | {ERR_FUNC(GOST_F_GOST_KEY_SET_PUBLIC_KEY_AFFINE_COORDINATES), "GOST_KEY_set_public_key_affine_coordinates"}, | ||
84 | {ERR_FUNC(GOST_F_PARAM_COPY_GOST01), "PARAM_COPY_GOST01"}, | ||
85 | {ERR_FUNC(GOST_F_PARAM_DECODE_GOST01), "PARAM_DECODE_GOST01"}, | ||
86 | {ERR_FUNC(GOST_F_PKEY_GOST01_CTRL), "PKEY_GOST01_CTRL"}, | ||
87 | {ERR_FUNC(GOST_F_PKEY_GOST01_DECRYPT), "PKEY_GOST01_DECRYPT"}, | ||
88 | {ERR_FUNC(GOST_F_PKEY_GOST01_DERIVE), "PKEY_GOST01_DERIVE"}, | ||
89 | {ERR_FUNC(GOST_F_PKEY_GOST01_ENCRYPT), "PKEY_GOST01_ENCRYPT"}, | ||
90 | {ERR_FUNC(GOST_F_PKEY_GOST01_PARAMGEN), "PKEY_GOST01_PARAMGEN"}, | ||
91 | {ERR_FUNC(GOST_F_PKEY_GOST01_SIGN), "PKEY_GOST01_SIGN"}, | ||
92 | {ERR_FUNC(GOST_F_PKEY_GOST_MAC_CTRL), "PKEY_GOST_MAC_CTRL"}, | ||
93 | {ERR_FUNC(GOST_F_PKEY_GOST_MAC_KEYGEN), "PKEY_GOST_MAC_KEYGEN"}, | ||
94 | {ERR_FUNC(GOST_F_PRIV_DECODE_GOST01), "PRIV_DECODE_GOST01"}, | ||
95 | {ERR_FUNC(GOST_F_PUB_DECODE_GOST01), "PUB_DECODE_GOST01"}, | ||
96 | {ERR_FUNC(GOST_F_PUB_ENCODE_GOST01), "PUB_ENCODE_GOST01"}, | ||
97 | {ERR_FUNC(GOST_F_PUB_PRINT_GOST01), "PUB_PRINT_GOST01"}, | ||
98 | {ERR_FUNC(GOST_F_UNPACK_SIGNATURE_CP), "UNPACK_SIGNATURE_CP"}, | ||
99 | {ERR_FUNC(GOST_F_UNPACK_SIGNATURE_LE), "UNPACK_SIGNATURE_LE"}, | ||
100 | {0,NULL} | ||
101 | }; | ||
102 | |||
103 | static ERR_STRING_DATA GOST_str_reasons[]= | ||
104 | { | ||
105 | {ERR_REASON(GOST_R_BAD_KEY_PARAMETERS_FORMAT),"bad key parameters format"}, | ||
106 | {ERR_REASON(GOST_R_BAD_PKEY_PARAMETERS_FORMAT),"bad pkey parameters format"}, | ||
107 | {ERR_REASON(GOST_R_CANNOT_PACK_EPHEMERAL_KEY),"cannot pack ephemeral key"}, | ||
108 | {ERR_REASON(GOST_R_CTRL_CALL_FAILED) ,"ctrl call failed"}, | ||
109 | {ERR_REASON(GOST_R_ERROR_COMPUTING_SHARED_KEY),"error computing shared key"}, | ||
110 | {ERR_REASON(GOST_R_ERROR_PARSING_KEY_TRANSPORT_INFO),"error parsing key transport info"}, | ||
111 | {ERR_REASON(GOST_R_INCOMPATIBLE_ALGORITHMS),"incompatible algorithms"}, | ||
112 | {ERR_REASON(GOST_R_INCOMPATIBLE_PEER_KEY),"incompatible peer key"}, | ||
113 | {ERR_REASON(GOST_R_INVALID_DIGEST_TYPE) ,"invalid digest type"}, | ||
114 | {ERR_REASON(GOST_R_INVALID_IV_LENGTH) ,"invalid iv length"}, | ||
115 | {ERR_REASON(GOST_R_INVALID_MAC_KEY_LENGTH),"invalid mac key length"}, | ||
116 | {ERR_REASON(GOST_R_KEY_IS_NOT_INITIALIZED),"key is not initialized"}, | ||
117 | {ERR_REASON(GOST_R_KEY_PARAMETERS_MISSING),"key parameters missing"}, | ||
118 | {ERR_REASON(GOST_R_MAC_KEY_NOT_SET) ,"mac key not set"}, | ||
119 | {ERR_REASON(GOST_R_NO_PARAMETERS_SET) ,"no parameters set"}, | ||
120 | {ERR_REASON(GOST_R_NO_PEER_KEY) ,"no peer key"}, | ||
121 | {ERR_REASON(GOST_R_NO_PRIVATE_PART_OF_NON_EPHEMERAL_KEYPAIR),"no private part of non ephemeral keypair"}, | ||
122 | {ERR_REASON(GOST_R_PUBLIC_KEY_UNDEFINED) ,"public key undefined"}, | ||
123 | {ERR_REASON(GOST_R_RANDOM_GENERATOR_FAILURE),"random generator failure"}, | ||
124 | {ERR_REASON(GOST_R_RANDOM_NUMBER_GENERATOR_FAILED),"random number generator failed"}, | ||
125 | {ERR_REASON(GOST_R_SIGNATURE_MISMATCH) ,"signature mismatch"}, | ||
126 | {ERR_REASON(GOST_R_SIGNATURE_PARTS_GREATER_THAN_Q),"signature parts greater than q"}, | ||
127 | {ERR_REASON(GOST_R_UKM_NOT_SET) ,"ukm not set"}, | ||
128 | {0,NULL} | ||
129 | }; | ||
130 | |||
131 | #endif | ||
132 | |||
133 | void ERR_load_GOST_strings(void) | ||
134 | { | ||
135 | #ifndef OPENSSL_NO_ERR | ||
136 | |||
137 | if (ERR_func_error_string(GOST_str_functs[0].error) == NULL) | ||
138 | { | ||
139 | ERR_load_strings(0,GOST_str_functs); | ||
140 | ERR_load_strings(0,GOST_str_reasons); | ||
141 | } | ||
142 | #endif | ||
143 | } | ||
diff --git a/src/lib/libssl/src/crypto/gost/gost_locl.h b/src/lib/libssl/src/crypto/gost/gost_locl.h new file mode 100644 index 0000000000..b616005dc5 --- /dev/null +++ b/src/lib/libssl/src/crypto/gost/gost_locl.h | |||
@@ -0,0 +1,114 @@ | |||
1 | /* $OpenBSD: gost_locl.h,v 1.1 2014/11/09 19:17:13 miod Exp $ */ | ||
2 | /* | ||
3 | * Copyright (c) 2014 Dmitry Eremin-Solenikov <dbaryshkov@gmail.com> | ||
4 | * Copyright (c) 2005-2006 Cryptocom LTD | ||
5 | * | ||
6 | * Redistribution and use in source and binary forms, with or without | ||
7 | * modification, are permitted provided that the following conditions | ||
8 | * are met: | ||
9 | * | ||
10 | * 1. Redistributions of source code must retain the above copyright | ||
11 | * notice, this list of conditions and the following disclaimer. | ||
12 | * | ||
13 | * 2. Redistributions in binary form must reproduce the above copyright | ||
14 | * notice, this list of conditions and the following disclaimer in | ||
15 | * the documentation and/or other materials provided with the | ||
16 | * distribution. | ||
17 | * | ||
18 | * 3. All advertising materials mentioning features or use of this | ||
19 | * software must display the following acknowledgment: | ||
20 | * "This product includes software developed by the OpenSSL Project | ||
21 | * for use in the OpenSSL Toolkit. (http://www.openssl.org/)" | ||
22 | * | ||
23 | * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to | ||
24 | * endorse or promote products derived from this software without | ||
25 | * prior written permission. For written permission, please contact | ||
26 | * openssl-core@openssl.org. | ||
27 | * | ||
28 | * 5. Products derived from this software may not be called "OpenSSL" | ||
29 | * nor may "OpenSSL" appear in their names without prior written | ||
30 | * permission of the OpenSSL Project. | ||
31 | * | ||
32 | * 6. Redistributions of any form whatsoever must retain the following | ||
33 | * acknowledgment: | ||
34 | * "This product includes software developed by the OpenSSL Project | ||
35 | * for use in the OpenSSL Toolkit (http://www.openssl.org/)" | ||
36 | * | ||
37 | * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY | ||
38 | * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | ||
39 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR | ||
40 | * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR | ||
41 | * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, | ||
42 | * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT | ||
43 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; | ||
44 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | ||
45 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, | ||
46 | * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) | ||
47 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED | ||
48 | * OF THE POSSIBILITY OF SUCH DAMAGE. | ||
49 | * ==================================================================== | ||
50 | */ | ||
51 | |||
52 | #ifndef HEADER_GOST_LOCL_H | ||
53 | #define HEADER_GOST_LOCL_H | ||
54 | |||
55 | #include <openssl/ec.h> | ||
56 | #include <openssl/ecdsa.h> | ||
57 | |||
58 | /* Internal representation of GOST substitution blocks */ | ||
59 | typedef struct { | ||
60 | unsigned char k8[16]; | ||
61 | unsigned char k7[16]; | ||
62 | unsigned char k6[16]; | ||
63 | unsigned char k5[16]; | ||
64 | unsigned char k4[16]; | ||
65 | unsigned char k3[16]; | ||
66 | unsigned char k2[16]; | ||
67 | unsigned char k1[16]; | ||
68 | } gost_subst_block; | ||
69 | |||
70 | #if defined(__i386) || defined(__i386__) || defined(__x86_64) || defined(__x86_64__) | ||
71 | # define c2l(c,l) ((l)=*((const unsigned int *)(c)), (c)+=4) | ||
72 | # define l2c(l,c) (*((unsigned int *)(c))=(l), (c)+=4) | ||
73 | #else | ||
74 | #define c2l(c,l) (l =(((unsigned long)(*((c)++))) ), \ | ||
75 | l|=(((unsigned long)(*((c)++)))<< 8), \ | ||
76 | l|=(((unsigned long)(*((c)++)))<<16), \ | ||
77 | l|=(((unsigned long)(*((c)++)))<<24)) | ||
78 | #define l2c(l,c) (*((c)++)=(unsigned char)(((l) )&0xff), \ | ||
79 | *((c)++)=(unsigned char)(((l)>> 8)&0xff), \ | ||
80 | *((c)++)=(unsigned char)(((l)>>16)&0xff), \ | ||
81 | *((c)++)=(unsigned char)(((l)>>24)&0xff)) | ||
82 | #endif | ||
83 | |||
84 | extern void Gost2814789_encrypt(const unsigned char *in, unsigned char *out, | ||
85 | const GOST2814789_KEY *key); | ||
86 | extern void Gost2814789_decrypt(const unsigned char *in, unsigned char *out, | ||
87 | const GOST2814789_KEY *key); | ||
88 | extern void Gost2814789_cryptopro_key_mesh(GOST2814789_KEY *key); | ||
89 | |||
90 | /* GOST 28147-89 key wrapping */ | ||
91 | extern int key_unwrap_crypto_pro(int nid, const unsigned char *keyExchangeKey, | ||
92 | const unsigned char *wrappedKey, | ||
93 | unsigned char *sessionKey); | ||
94 | extern int key_wrap_crypto_pro(int nid, const unsigned char *keyExchangeKey, | ||
95 | const unsigned char *ukm, const unsigned char *sessionKey, | ||
96 | unsigned char *wrappedKey); | ||
97 | /* Pkey part */ | ||
98 | extern int gost2001_compute_public(GOST_KEY * ec); | ||
99 | extern ECDSA_SIG *gost2001_do_sign(BIGNUM * md, GOST_KEY * eckey); | ||
100 | extern int gost2001_do_verify(BIGNUM * md, ECDSA_SIG * sig, GOST_KEY * ec); | ||
101 | extern int gost2001_keygen(GOST_KEY * ec); | ||
102 | extern void VKO_compute_key(BIGNUM * X, BIGNUM * Y, | ||
103 | const GOST_KEY * pkey, GOST_KEY * priv_key, | ||
104 | const BIGNUM * ukm); | ||
105 | extern BIGNUM *GOST_le2bn(const unsigned char * buf, size_t len, BIGNUM * bn); | ||
106 | extern int GOST_bn2le(BIGNUM * bn, unsigned char * buf, int len); | ||
107 | |||
108 | /* GOST R 34.10 parameters */ | ||
109 | extern int GostR3410_get_md_digest(int nid); | ||
110 | extern int GostR3410_get_pk_digest(int nid); | ||
111 | extern int GostR3410_256_param_id(const char *value); | ||
112 | extern int GostR3410_512_param_id(const char *value); | ||
113 | |||
114 | #endif | ||
diff --git a/src/lib/libssl/src/crypto/gost/gostr341001.c b/src/lib/libssl/src/crypto/gost/gostr341001.c new file mode 100644 index 0000000000..3c314765f7 --- /dev/null +++ b/src/lib/libssl/src/crypto/gost/gostr341001.c | |||
@@ -0,0 +1,321 @@ | |||
1 | /* $OpenBSD: gostr341001.c,v 1.1 2014/11/09 19:17:13 miod Exp $ */ | ||
2 | /* | ||
3 | * Copyright (c) 2014 Dmitry Eremin-Solenikov <dbaryshkov@gmail.com> | ||
4 | * Copyright (c) 2005-2006 Cryptocom LTD | ||
5 | * | ||
6 | * Redistribution and use in source and binary forms, with or without | ||
7 | * modification, are permitted provided that the following conditions | ||
8 | * are met: | ||
9 | * | ||
10 | * 1. Redistributions of source code must retain the above copyright | ||
11 | * notice, this list of conditions and the following disclaimer. | ||
12 | * | ||
13 | * 2. Redistributions in binary form must reproduce the above copyright | ||
14 | * notice, this list of conditions and the following disclaimer in | ||
15 | * the documentation and/or other materials provided with the | ||
16 | * distribution. | ||
17 | * | ||
18 | * 3. All advertising materials mentioning features or use of this | ||
19 | * software must display the following acknowledgment: | ||
20 | * "This product includes software developed by the OpenSSL Project | ||
21 | * for use in the OpenSSL Toolkit. (http://www.openssl.org/)" | ||
22 | * | ||
23 | * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to | ||
24 | * endorse or promote products derived from this software without | ||
25 | * prior written permission. For written permission, please contact | ||
26 | * openssl-core@openssl.org. | ||
27 | * | ||
28 | * 5. Products derived from this software may not be called "OpenSSL" | ||
29 | * nor may "OpenSSL" appear in their names without prior written | ||
30 | * permission of the OpenSSL Project. | ||
31 | * | ||
32 | * 6. Redistributions of any form whatsoever must retain the following | ||
33 | * acknowledgment: | ||
34 | * "This product includes software developed by the OpenSSL Project | ||
35 | * for use in the OpenSSL Toolkit (http://www.openssl.org/)" | ||
36 | * | ||
37 | * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY | ||
38 | * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | ||
39 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR | ||
40 | * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR | ||
41 | * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, | ||
42 | * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT | ||
43 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; | ||
44 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | ||
45 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, | ||
46 | * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) | ||
47 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED | ||
48 | * OF THE POSSIBILITY OF SUCH DAMAGE. | ||
49 | * ==================================================================== | ||
50 | */ | ||
51 | |||
52 | #include <string.h> | ||
53 | |||
54 | #include <openssl/opensslconf.h> | ||
55 | |||
56 | #ifndef OPENSSL_NO_GOST | ||
57 | #include <openssl/err.h> | ||
58 | #include <openssl/gost.h> | ||
59 | #include "gost_locl.h" | ||
60 | |||
61 | /* Convert little-endian byte array into bignum */ | ||
62 | BIGNUM *GOST_le2bn(const unsigned char * buf, size_t len, BIGNUM * bn) | ||
63 | { | ||
64 | unsigned char temp[64]; | ||
65 | int i; | ||
66 | if (len > 64) | ||
67 | return NULL; | ||
68 | |||
69 | for (i = 0; i < len; i++) { | ||
70 | temp[len - 1 - i] = buf[i]; | ||
71 | } | ||
72 | |||
73 | return BN_bin2bn(temp, len, bn); | ||
74 | } | ||
75 | |||
76 | int GOST_bn2le(BIGNUM * bn, unsigned char * buf, int len) | ||
77 | { | ||
78 | unsigned char temp[64]; | ||
79 | int i, bytes; | ||
80 | |||
81 | bytes = BN_num_bytes(bn); | ||
82 | if (len > 64 || bytes > len) | ||
83 | return 0; | ||
84 | |||
85 | BN_bn2bin(bn, temp); | ||
86 | |||
87 | for (i = 0; i < bytes; i++) { | ||
88 | buf[bytes - 1 - i] = temp[i]; | ||
89 | } | ||
90 | |||
91 | memset(buf + bytes, 0, len - bytes); | ||
92 | |||
93 | return 1; | ||
94 | } | ||
95 | |||
96 | |||
97 | int gost2001_compute_public(GOST_KEY * ec) | ||
98 | { | ||
99 | const EC_GROUP *group = GOST_KEY_get0_group(ec); | ||
100 | EC_POINT *pub_key = NULL; | ||
101 | const BIGNUM *priv_key = NULL; | ||
102 | BN_CTX *ctx = NULL; | ||
103 | int ok = 0; | ||
104 | |||
105 | if (!group) { | ||
106 | GOSTerr(GOST_F_GOST2001_COMPUTE_PUBLIC, | ||
107 | GOST_R_KEY_IS_NOT_INITIALIZED); | ||
108 | return 0; | ||
109 | } | ||
110 | ctx = BN_CTX_new(); | ||
111 | BN_CTX_start(ctx); | ||
112 | if (!(priv_key = GOST_KEY_get0_private_key(ec))) { | ||
113 | GOSTerr(GOST_F_GOST2001_COMPUTE_PUBLIC, ERR_R_EC_LIB); | ||
114 | goto err; | ||
115 | } | ||
116 | |||
117 | pub_key = EC_POINT_new(group); | ||
118 | if (!EC_POINT_mul(group, pub_key, priv_key, NULL, NULL, ctx)) { | ||
119 | GOSTerr(GOST_F_GOST2001_COMPUTE_PUBLIC, ERR_R_EC_LIB); | ||
120 | goto err; | ||
121 | } | ||
122 | if (!GOST_KEY_set_public_key(ec, pub_key)) { | ||
123 | GOSTerr(GOST_F_GOST2001_COMPUTE_PUBLIC, ERR_R_EC_LIB); | ||
124 | goto err; | ||
125 | } | ||
126 | ok = 256; | ||
127 | err: | ||
128 | BN_CTX_end(ctx); | ||
129 | EC_POINT_free(pub_key); | ||
130 | BN_CTX_free(ctx); | ||
131 | return ok; | ||
132 | } | ||
133 | |||
134 | ECDSA_SIG *gost2001_do_sign(BIGNUM * md, GOST_KEY * eckey) | ||
135 | { | ||
136 | ECDSA_SIG *newsig = NULL; | ||
137 | BIGNUM *order = NULL; | ||
138 | const EC_GROUP *group; | ||
139 | const BIGNUM *priv_key; | ||
140 | BIGNUM *r = NULL, *s = NULL, *X = NULL, *tmp = NULL, *tmp2 = NULL, *k = | ||
141 | NULL, *e = NULL; | ||
142 | EC_POINT *C = NULL; | ||
143 | BN_CTX *ctx = BN_CTX_new(); | ||
144 | BN_CTX_start(ctx); | ||
145 | newsig = ECDSA_SIG_new(); | ||
146 | if (!newsig) { | ||
147 | GOSTerr(GOST_F_GOST2001_DO_SIGN, ERR_R_MALLOC_FAILURE); | ||
148 | goto err; | ||
149 | } | ||
150 | s = newsig->s; | ||
151 | r = newsig->r; | ||
152 | group = GOST_KEY_get0_group(eckey); | ||
153 | order = BN_CTX_get(ctx); | ||
154 | EC_GROUP_get_order(group, order, ctx); | ||
155 | priv_key = GOST_KEY_get0_private_key(eckey); | ||
156 | e = BN_CTX_get(ctx); | ||
157 | BN_mod(e, md, order, ctx); | ||
158 | if (BN_is_zero(e)) { | ||
159 | BN_one(e); | ||
160 | } | ||
161 | k = BN_CTX_get(ctx); | ||
162 | X = BN_CTX_get(ctx); | ||
163 | C = EC_POINT_new(group); | ||
164 | do { | ||
165 | do { | ||
166 | if (!BN_rand_range(k, order)) { | ||
167 | GOSTerr(GOST_F_GOST2001_DO_SIGN, | ||
168 | GOST_R_RANDOM_NUMBER_GENERATOR_FAILED); | ||
169 | ECDSA_SIG_free(newsig); | ||
170 | newsig = NULL; | ||
171 | goto err; | ||
172 | } | ||
173 | /* We do not want timing information to leak the length of k, | ||
174 | * so we compute G*k using an equivalent scalar of fixed | ||
175 | * bit-length. */ | ||
176 | if (!BN_add(k, k, order)) | ||
177 | goto err; | ||
178 | if (BN_num_bits(k) <= BN_num_bits(order)) | ||
179 | if (!BN_add(k, k, order)) | ||
180 | goto err; | ||
181 | |||
182 | if (!EC_POINT_mul(group, C, k, NULL, NULL, ctx)) { | ||
183 | GOSTerr(GOST_F_GOST2001_DO_SIGN, ERR_R_EC_LIB); | ||
184 | ECDSA_SIG_free(newsig); | ||
185 | newsig = NULL; | ||
186 | goto err; | ||
187 | } | ||
188 | if (!EC_POINT_get_affine_coordinates_GFp | ||
189 | (group, C, X, NULL, ctx)) { | ||
190 | GOSTerr(GOST_F_GOST2001_DO_SIGN, ERR_R_EC_LIB); | ||
191 | ECDSA_SIG_free(newsig); | ||
192 | newsig = NULL; | ||
193 | goto err; | ||
194 | } | ||
195 | BN_nnmod(r, X, order, ctx); | ||
196 | } | ||
197 | while (BN_is_zero(r)); | ||
198 | /* s = (r*priv_key+k*e) mod order */ | ||
199 | if (!tmp) | ||
200 | tmp = BN_CTX_get(ctx); | ||
201 | BN_mod_mul(tmp, priv_key, r, order, ctx); | ||
202 | if (!tmp2) | ||
203 | tmp2 = BN_CTX_get(ctx); | ||
204 | BN_mod_mul(tmp2, k, e, order, ctx); | ||
205 | BN_mod_add(s, tmp, tmp2, order, ctx); | ||
206 | } | ||
207 | while (BN_is_zero(s)); | ||
208 | |||
209 | err: | ||
210 | BN_CTX_end(ctx); | ||
211 | BN_CTX_free(ctx); | ||
212 | EC_POINT_free(C); | ||
213 | BN_free(md); | ||
214 | return newsig; | ||
215 | } | ||
216 | |||
217 | int gost2001_do_verify(BIGNUM * md, ECDSA_SIG * sig, GOST_KEY * ec) | ||
218 | { | ||
219 | BN_CTX *ctx = BN_CTX_new(); | ||
220 | const EC_GROUP *group = GOST_KEY_get0_group(ec); | ||
221 | BIGNUM *order; | ||
222 | BIGNUM *e = NULL, *R = NULL, *v = NULL, *z1 = NULL, *z2 = NULL; | ||
223 | BIGNUM *X = NULL, *tmp = NULL; | ||
224 | EC_POINT *C = NULL; | ||
225 | const EC_POINT *pub_key = NULL; | ||
226 | int ok = 0; | ||
227 | |||
228 | BN_CTX_start(ctx); | ||
229 | order = BN_CTX_get(ctx); | ||
230 | e = BN_CTX_get(ctx); | ||
231 | z1 = BN_CTX_get(ctx); | ||
232 | z2 = BN_CTX_get(ctx); | ||
233 | tmp = BN_CTX_get(ctx); | ||
234 | X = BN_CTX_get(ctx); | ||
235 | R = BN_CTX_get(ctx); | ||
236 | v = BN_CTX_get(ctx); | ||
237 | |||
238 | EC_GROUP_get_order(group, order, ctx); | ||
239 | pub_key = GOST_KEY_get0_public_key(ec); | ||
240 | if (BN_is_zero(sig->s) || BN_is_zero(sig->r) || | ||
241 | (BN_cmp(sig->s, order) >= 1) || (BN_cmp(sig->r, order) >= 1)) { | ||
242 | GOSTerr(GOST_F_GOST2001_DO_VERIFY, GOST_R_SIGNATURE_PARTS_GREATER_THAN_Q); | ||
243 | goto err; | ||
244 | |||
245 | } | ||
246 | |||
247 | BN_mod(e, md, order, ctx); | ||
248 | if (BN_is_zero(e)) | ||
249 | BN_one(e); | ||
250 | v = BN_mod_inverse(v, e, order, ctx); | ||
251 | BN_mod_mul(z1, sig->s, v, order, ctx); | ||
252 | BN_sub(tmp, order, sig->r); | ||
253 | BN_mod_mul(z2, tmp, v, order, ctx); | ||
254 | C = EC_POINT_new(group); | ||
255 | if (!EC_POINT_mul(group, C, z1, pub_key, z2, ctx)) { | ||
256 | GOSTerr(GOST_F_GOST2001_DO_VERIFY, ERR_R_EC_LIB); | ||
257 | goto err; | ||
258 | } | ||
259 | if (!EC_POINT_get_affine_coordinates_GFp(group, C, X, NULL, ctx)) { | ||
260 | GOSTerr(GOST_F_GOST2001_DO_VERIFY, ERR_R_EC_LIB); | ||
261 | goto err; | ||
262 | } | ||
263 | BN_mod(R, X, order, ctx); | ||
264 | if (BN_cmp(R, sig->r) != 0) { | ||
265 | GOSTerr(GOST_F_GOST2001_DO_VERIFY, GOST_R_SIGNATURE_MISMATCH); | ||
266 | } else { | ||
267 | ok = 1; | ||
268 | } | ||
269 | err: | ||
270 | EC_POINT_free(C); | ||
271 | BN_CTX_end(ctx); | ||
272 | BN_CTX_free(ctx); | ||
273 | return ok; | ||
274 | } | ||
275 | |||
276 | |||
277 | /* Implementation of CryptoPro VKO 34.10-2001 algorithm */ | ||
278 | void VKO_compute_key(BIGNUM * X, BIGNUM * Y, | ||
279 | const GOST_KEY * pkey, GOST_KEY * priv_key, | ||
280 | const BIGNUM * ukm) | ||
281 | { | ||
282 | BIGNUM *p = NULL, *order = NULL; | ||
283 | const BIGNUM *key = GOST_KEY_get0_private_key(priv_key); | ||
284 | const EC_POINT *pub_key = GOST_KEY_get0_public_key(pkey); | ||
285 | EC_POINT *pnt = EC_POINT_new(GOST_KEY_get0_group(priv_key)); | ||
286 | BN_CTX *ctx = BN_CTX_new(); | ||
287 | |||
288 | BN_CTX_start(ctx); | ||
289 | p = BN_CTX_get(ctx); | ||
290 | order = BN_CTX_get(ctx); | ||
291 | EC_GROUP_get_order(GOST_KEY_get0_group(priv_key), order, ctx); | ||
292 | BN_mod_mul(p, key, ukm, order, ctx); | ||
293 | EC_POINT_mul(GOST_KEY_get0_group(priv_key), pnt, NULL, pub_key, p, ctx); | ||
294 | EC_POINT_get_affine_coordinates_GFp(GOST_KEY_get0_group(priv_key), | ||
295 | pnt, X, Y, ctx); | ||
296 | BN_CTX_end(ctx); | ||
297 | BN_CTX_free(ctx); | ||
298 | EC_POINT_free(pnt); | ||
299 | } | ||
300 | |||
301 | int gost2001_keygen(GOST_KEY * ec) | ||
302 | { | ||
303 | BIGNUM *order = BN_new(), *d = BN_new(); | ||
304 | const EC_GROUP *group = GOST_KEY_get0_group(ec); | ||
305 | EC_GROUP_get_order(group, order, NULL); | ||
306 | |||
307 | do { | ||
308 | if (!BN_rand_range(d, order)) { | ||
309 | GOSTerr(GOST_F_GOST2001_KEYGEN, | ||
310 | GOST_R_RANDOM_NUMBER_GENERATOR_FAILED); | ||
311 | BN_free(d); | ||
312 | BN_free(order); | ||
313 | return 0; | ||
314 | } | ||
315 | } while (BN_is_zero(d)); | ||
316 | GOST_KEY_set_private_key(ec, d); | ||
317 | BN_free(d); | ||
318 | BN_free(order); | ||
319 | return gost2001_compute_public(ec); | ||
320 | } | ||
321 | #endif | ||
diff --git a/src/lib/libssl/src/crypto/gost/gostr341001_ameth.c b/src/lib/libssl/src/crypto/gost/gostr341001_ameth.c new file mode 100644 index 0000000000..09b851cef4 --- /dev/null +++ b/src/lib/libssl/src/crypto/gost/gostr341001_ameth.c | |||
@@ -0,0 +1,656 @@ | |||
1 | /* $OpenBSD: gostr341001_ameth.c,v 1.1 2014/11/09 19:17:13 miod Exp $ */ | ||
2 | /* | ||
3 | * Copyright (c) 2014 Dmitry Eremin-Solenikov <dbaryshkov@gmail.com> | ||
4 | * Copyright (c) 2005-2006 Cryptocom LTD | ||
5 | * | ||
6 | * Redistribution and use in source and binary forms, with or without | ||
7 | * modification, are permitted provided that the following conditions | ||
8 | * are met: | ||
9 | * | ||
10 | * 1. Redistributions of source code must retain the above copyright | ||
11 | * notice, this list of conditions and the following disclaimer. | ||
12 | * | ||
13 | * 2. Redistributions in binary form must reproduce the above copyright | ||
14 | * notice, this list of conditions and the following disclaimer in | ||
15 | * the documentation and/or other materials provided with the | ||
16 | * distribution. | ||
17 | * | ||
18 | * 3. All advertising materials mentioning features or use of this | ||
19 | * software must display the following acknowledgment: | ||
20 | * "This product includes software developed by the OpenSSL Project | ||
21 | * for use in the OpenSSL Toolkit. (http://www.openssl.org/)" | ||
22 | * | ||
23 | * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to | ||
24 | * endorse or promote products derived from this software without | ||
25 | * prior written permission. For written permission, please contact | ||
26 | * openssl-core@openssl.org. | ||
27 | * | ||
28 | * 5. Products derived from this software may not be called "OpenSSL" | ||
29 | * nor may "OpenSSL" appear in their names without prior written | ||
30 | * permission of the OpenSSL Project. | ||
31 | * | ||
32 | * 6. Redistributions of any form whatsoever must retain the following | ||
33 | * acknowledgment: | ||
34 | * "This product includes software developed by the OpenSSL Project | ||
35 | * for use in the OpenSSL Toolkit (http://www.openssl.org/)" | ||
36 | * | ||
37 | * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY | ||
38 | * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | ||
39 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR | ||
40 | * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR | ||
41 | * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, | ||
42 | * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT | ||
43 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; | ||
44 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | ||
45 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, | ||
46 | * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) | ||
47 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED | ||
48 | * OF THE POSSIBILITY OF SUCH DAMAGE. | ||
49 | * ==================================================================== | ||
50 | */ | ||
51 | |||
52 | #include <string.h> | ||
53 | |||
54 | #include <openssl/opensslconf.h> | ||
55 | |||
56 | #ifndef OPENSSL_NO_GOST | ||
57 | #include <openssl/evp.h> | ||
58 | #include <openssl/ec.h> | ||
59 | #include <openssl/err.h> | ||
60 | #include <openssl/x509.h> | ||
61 | #include <openssl/gost.h> | ||
62 | |||
63 | #ifndef OPENSSL_NO_CMS | ||
64 | #include <openssl/cms.h> | ||
65 | #endif | ||
66 | |||
67 | #include "asn1_locl.h" | ||
68 | #include "gost_locl.h" | ||
69 | #include "gost_asn1.h" | ||
70 | |||
71 | static void pkey_free_gost01(EVP_PKEY *key) | ||
72 | { | ||
73 | GOST_KEY_free(key->pkey.gost); | ||
74 | } | ||
75 | |||
76 | /* Parses GOST algorithm parameters from X509_ALGOR and | ||
77 | * modifies pkey setting NID and parameters | ||
78 | */ | ||
79 | static int decode_gost01_algor_params(EVP_PKEY * pkey, const unsigned char **p, int len) | ||
80 | { | ||
81 | int param_nid = NID_undef, digest_nid = NID_undef; | ||
82 | GOST_KEY_PARAMS *gkp = NULL; | ||
83 | EC_GROUP *group; | ||
84 | GOST_KEY *ec; | ||
85 | |||
86 | gkp = d2i_GOST_KEY_PARAMS(NULL, p, len); | ||
87 | if (!gkp) { | ||
88 | GOSTerr(GOST_F_DECODE_GOST01_ALGOR_PARAMS, | ||
89 | GOST_R_BAD_PKEY_PARAMETERS_FORMAT); | ||
90 | return 0; | ||
91 | } | ||
92 | param_nid = OBJ_obj2nid(gkp->key_params); | ||
93 | digest_nid = OBJ_obj2nid(gkp->hash_params); | ||
94 | GOST_KEY_PARAMS_free(gkp); | ||
95 | ec = pkey->pkey.gost; | ||
96 | if (!ec) { | ||
97 | ec = GOST_KEY_new(); | ||
98 | if (!EVP_PKEY_assign_GOST(pkey, ec)) | ||
99 | return 0; | ||
100 | } | ||
101 | |||
102 | group = EC_GROUP_new_by_curve_name(param_nid); | ||
103 | if (group == NULL) | ||
104 | return 0; | ||
105 | EC_GROUP_set_asn1_flag(group, OPENSSL_EC_NAMED_CURVE); | ||
106 | if (GOST_KEY_set_group(ec, group) == 0) { | ||
107 | EC_GROUP_free(group); | ||
108 | return 0; | ||
109 | } | ||
110 | EC_GROUP_free(group); | ||
111 | if (GOST_KEY_set_digest(ec, digest_nid) == 0) | ||
112 | return 0; | ||
113 | return 1; | ||
114 | } | ||
115 | |||
116 | static ASN1_STRING *encode_gost01_algor_params(const EVP_PKEY * key) | ||
117 | { | ||
118 | ASN1_STRING *params = ASN1_STRING_new(); | ||
119 | GOST_KEY_PARAMS *gkp = GOST_KEY_PARAMS_new(); | ||
120 | int pkey_param_nid = NID_undef; | ||
121 | |||
122 | if (!params || !gkp) { | ||
123 | GOSTerr(GOST_F_ENCODE_GOST01_ALGOR_PARAMS, ERR_R_MALLOC_FAILURE); | ||
124 | ASN1_STRING_free(params); | ||
125 | params = NULL; | ||
126 | goto err; | ||
127 | } | ||
128 | |||
129 | pkey_param_nid = EC_GROUP_get_curve_name(GOST_KEY_get0_group(key->pkey.gost)); | ||
130 | gkp->key_params = OBJ_nid2obj(pkey_param_nid); | ||
131 | gkp->hash_params = OBJ_nid2obj(GOST_KEY_get_digest(key->pkey.gost)); | ||
132 | /*gkp->cipher_params = OBJ_nid2obj(cipher_param_nid); */ | ||
133 | params->length = i2d_GOST_KEY_PARAMS(gkp, ¶ms->data); | ||
134 | if (params->length <= 0) { | ||
135 | GOSTerr(GOST_F_ENCODE_GOST01_ALGOR_PARAMS, ERR_R_MALLOC_FAILURE); | ||
136 | ASN1_STRING_free(params); | ||
137 | params = NULL; | ||
138 | goto err; | ||
139 | } | ||
140 | params->type = V_ASN1_SEQUENCE; | ||
141 | err: | ||
142 | GOST_KEY_PARAMS_free(gkp); | ||
143 | return params; | ||
144 | } | ||
145 | |||
146 | static int pub_cmp_gost01(const EVP_PKEY * a, const EVP_PKEY * b) | ||
147 | { | ||
148 | const GOST_KEY *ea = a->pkey.gost; | ||
149 | const GOST_KEY *eb = b->pkey.gost; | ||
150 | const EC_POINT *ka, *kb; | ||
151 | int ret = 0; | ||
152 | if (!ea || !eb) | ||
153 | return 0; | ||
154 | ka = GOST_KEY_get0_public_key(ea); | ||
155 | kb = GOST_KEY_get0_public_key(eb); | ||
156 | if (!ka || !kb) | ||
157 | return 0; | ||
158 | ret = (0 == EC_POINT_cmp(GOST_KEY_get0_group(ea), ka, kb, NULL)); | ||
159 | return ret; | ||
160 | } | ||
161 | |||
162 | static int pkey_size_gost01(const EVP_PKEY * pk) | ||
163 | { | ||
164 | if (GOST_KEY_get_digest(pk->pkey.gost) == NID_id_tc26_gost3411_2012_512) | ||
165 | return 128; | ||
166 | return 64; | ||
167 | } | ||
168 | |||
169 | static int pkey_bits_gost01(const EVP_PKEY * pk) | ||
170 | { | ||
171 | if (GOST_KEY_get_digest(pk->pkey.gost) == NID_id_tc26_gost3411_2012_512) | ||
172 | return 512; | ||
173 | return 256; | ||
174 | } | ||
175 | |||
176 | static int pub_decode_gost01(EVP_PKEY *pk, X509_PUBKEY *pub) | ||
177 | { | ||
178 | X509_ALGOR *palg = NULL; | ||
179 | const unsigned char *pubkey_buf = NULL; | ||
180 | const unsigned char *p; | ||
181 | ASN1_OBJECT *palgobj = NULL; | ||
182 | int pub_len; | ||
183 | BIGNUM *X, *Y; | ||
184 | ASN1_OCTET_STRING *octet = NULL; | ||
185 | int len; | ||
186 | int ret; | ||
187 | int ptype = V_ASN1_UNDEF; | ||
188 | ASN1_STRING *pval = NULL; | ||
189 | |||
190 | if (!X509_PUBKEY_get0_param(&palgobj, &pubkey_buf, &pub_len, | ||
191 | &palg, pub)) | ||
192 | return 0; | ||
193 | EVP_PKEY_assign_GOST(pk, NULL); | ||
194 | X509_ALGOR_get0(NULL, &ptype, (void **)&pval, palg); | ||
195 | if (ptype != V_ASN1_SEQUENCE) { | ||
196 | GOSTerr(GOST_F_PUB_DECODE_GOST01, | ||
197 | GOST_R_BAD_KEY_PARAMETERS_FORMAT); | ||
198 | return 0; | ||
199 | } | ||
200 | p = pval->data; | ||
201 | if (!decode_gost01_algor_params(pk, &p, pval->length)) | ||
202 | return 0; | ||
203 | octet = d2i_ASN1_OCTET_STRING(NULL, &pubkey_buf, pub_len); | ||
204 | if (!octet) { | ||
205 | GOSTerr(GOST_F_PUB_DECODE_GOST01, ERR_R_MALLOC_FAILURE); | ||
206 | return 0; | ||
207 | } | ||
208 | len = octet->length / 2; | ||
209 | |||
210 | X = GOST_le2bn(octet->data, len, NULL); | ||
211 | Y = GOST_le2bn(octet->data + len, len, NULL); | ||
212 | |||
213 | ASN1_OCTET_STRING_free(octet); | ||
214 | |||
215 | ret = GOST_KEY_set_public_key_affine_coordinates(pk->pkey.gost, X, Y); | ||
216 | if (!ret) | ||
217 | GOSTerr(GOST_F_PUB_DECODE_GOST01, ERR_R_EC_LIB); | ||
218 | |||
219 | BN_free(X); | ||
220 | BN_free(Y); | ||
221 | |||
222 | return ret; | ||
223 | |||
224 | } | ||
225 | |||
226 | static int pub_encode_gost01(X509_PUBKEY * pub, const EVP_PKEY * pk) | ||
227 | { | ||
228 | ASN1_OBJECT *algobj = NULL; | ||
229 | ASN1_OCTET_STRING *octet = NULL; | ||
230 | void *pval = NULL; | ||
231 | unsigned char *buf = NULL, *sptr; | ||
232 | int key_size, ret = 0; | ||
233 | const EC_POINT *pub_key; | ||
234 | BIGNUM *X, *Y; | ||
235 | const GOST_KEY *ec = pk->pkey.gost; | ||
236 | int ptype = V_ASN1_UNDEF; | ||
237 | |||
238 | algobj = OBJ_nid2obj(GostR3410_get_pk_digest(GOST_KEY_get_digest(ec))); | ||
239 | if (pk->save_parameters) { | ||
240 | ASN1_STRING *params = encode_gost01_algor_params(pk); | ||
241 | pval = params; | ||
242 | ptype = V_ASN1_SEQUENCE; | ||
243 | } | ||
244 | |||
245 | key_size = GOST_KEY_get_size(ec); | ||
246 | |||
247 | pub_key = GOST_KEY_get0_public_key(ec); | ||
248 | if (!pub_key) { | ||
249 | GOSTerr(GOST_F_PUB_ENCODE_GOST01, GOST_R_PUBLIC_KEY_UNDEFINED); | ||
250 | return 0; | ||
251 | } | ||
252 | |||
253 | octet = ASN1_OCTET_STRING_new(); | ||
254 | if (!octet) { | ||
255 | GOSTerr(GOST_F_PUB_ENCODE_GOST01, ERR_R_MALLOC_FAILURE); | ||
256 | return 0; | ||
257 | } | ||
258 | |||
259 | ret = ASN1_STRING_set(octet, NULL, 2 * key_size); | ||
260 | if (!ret) { | ||
261 | GOSTerr(GOST_F_PUB_ENCODE_GOST01, ERR_R_INTERNAL_ERROR); | ||
262 | ASN1_BIT_STRING_free(octet); | ||
263 | return 0; | ||
264 | } | ||
265 | |||
266 | sptr = ASN1_STRING_data(octet); | ||
267 | |||
268 | X = BN_new(); | ||
269 | Y = BN_new(); | ||
270 | if (!X || !Y) { | ||
271 | GOSTerr(GOST_F_PUB_ENCODE_GOST01, ERR_R_MALLOC_FAILURE); | ||
272 | ASN1_BIT_STRING_free(octet); | ||
273 | BN_free(X); | ||
274 | BN_free(Y); | ||
275 | return 0; | ||
276 | } | ||
277 | |||
278 | EC_POINT_get_affine_coordinates_GFp(GOST_KEY_get0_group(ec), | ||
279 | pub_key, X, Y, NULL); | ||
280 | |||
281 | GOST_bn2le(X, sptr, key_size); | ||
282 | GOST_bn2le(Y, sptr + key_size, key_size); | ||
283 | |||
284 | BN_free(X); | ||
285 | BN_free(Y); | ||
286 | |||
287 | ret = i2d_ASN1_OCTET_STRING(octet, &buf); | ||
288 | ASN1_BIT_STRING_free(octet); | ||
289 | if (ret < 0) | ||
290 | return 0; | ||
291 | |||
292 | return X509_PUBKEY_set0_param(pub, algobj, ptype, pval, buf, ret); | ||
293 | } | ||
294 | |||
295 | static int param_print_gost01(BIO * out, const EVP_PKEY * pkey, int indent, | ||
296 | ASN1_PCTX * pctx) | ||
297 | { | ||
298 | int param_nid = EC_GROUP_get_curve_name(GOST_KEY_get0_group(pkey->pkey.gost)); | ||
299 | if (!BIO_indent(out, indent, 128)) | ||
300 | return 0; | ||
301 | BIO_printf(out, "Parameter set: %s\n", OBJ_nid2ln(param_nid)); | ||
302 | if (!BIO_indent(out, indent, 128)) | ||
303 | return 0; | ||
304 | BIO_printf(out, "Digest Algorithm: %s\n", OBJ_nid2ln(GOST_KEY_get_digest(pkey->pkey.gost))); | ||
305 | return 1; | ||
306 | } | ||
307 | |||
308 | static int pub_print_gost01(BIO * out, const EVP_PKEY * pkey, int indent, | ||
309 | ASN1_PCTX * pctx) | ||
310 | { | ||
311 | BN_CTX *ctx = BN_CTX_new(); | ||
312 | BIGNUM *X, *Y; | ||
313 | const EC_POINT *pubkey; | ||
314 | const EC_GROUP *group; | ||
315 | |||
316 | if (!ctx) { | ||
317 | GOSTerr(GOST_F_PUB_PRINT_GOST01, ERR_R_MALLOC_FAILURE); | ||
318 | return 0; | ||
319 | } | ||
320 | BN_CTX_start(ctx); | ||
321 | X = BN_CTX_get(ctx); | ||
322 | Y = BN_CTX_get(ctx); | ||
323 | pubkey = GOST_KEY_get0_public_key(pkey->pkey.gost); | ||
324 | group = GOST_KEY_get0_group(pkey->pkey.gost); | ||
325 | if (!EC_POINT_get_affine_coordinates_GFp(group, pubkey, X, Y, ctx)) { | ||
326 | GOSTerr(GOST_F_PUB_PRINT_GOST01, ERR_R_EC_LIB); | ||
327 | BN_CTX_free(ctx); | ||
328 | return 0; | ||
329 | } | ||
330 | if (!BIO_indent(out, indent, 128)) | ||
331 | return 0; | ||
332 | BIO_printf(out, "Public key:\n"); | ||
333 | if (!BIO_indent(out, indent + 3, 128)) | ||
334 | return 0; | ||
335 | BIO_printf(out, "X:"); | ||
336 | BN_print(out, X); | ||
337 | BIO_printf(out, "\n"); | ||
338 | BIO_indent(out, indent + 3, 128); | ||
339 | BIO_printf(out, "Y:"); | ||
340 | BN_print(out, Y); | ||
341 | BIO_printf(out, "\n"); | ||
342 | BN_CTX_end(ctx); | ||
343 | BN_CTX_free(ctx); | ||
344 | |||
345 | return param_print_gost01(out, pkey, indent, pctx); | ||
346 | } | ||
347 | |||
348 | static int priv_print_gost01(BIO * out, const EVP_PKEY * pkey, int indent, | ||
349 | ASN1_PCTX * pctx) | ||
350 | { | ||
351 | const BIGNUM *key; | ||
352 | |||
353 | if (!BIO_indent(out, indent, 128)) | ||
354 | return 0; | ||
355 | BIO_printf(out, "Private key: "); | ||
356 | key = GOST_KEY_get0_private_key(pkey->pkey.gost); | ||
357 | if (!key) | ||
358 | BIO_printf(out, "<undefined)"); | ||
359 | else | ||
360 | BN_print(out, key); | ||
361 | BIO_printf(out, "\n"); | ||
362 | |||
363 | return pub_print_gost01(out, pkey, indent, pctx); | ||
364 | } | ||
365 | |||
366 | static int priv_decode_gost01(EVP_PKEY * pk, PKCS8_PRIV_KEY_INFO * p8inf) | ||
367 | { | ||
368 | const unsigned char *pkey_buf = NULL, *p = NULL; | ||
369 | int priv_len = 0; | ||
370 | BIGNUM *pk_num = NULL; | ||
371 | int ret = 0; | ||
372 | X509_ALGOR *palg = NULL; | ||
373 | ASN1_OBJECT *palg_obj = NULL; | ||
374 | ASN1_INTEGER *priv_key = NULL; | ||
375 | GOST_KEY *ec; | ||
376 | int ptype = V_ASN1_UNDEF; | ||
377 | ASN1_STRING *pval = NULL; | ||
378 | |||
379 | if (!PKCS8_pkey_get0(&palg_obj, &pkey_buf, &priv_len, &palg, p8inf)) | ||
380 | return 0; | ||
381 | EVP_PKEY_assign_GOST(pk, NULL); | ||
382 | X509_ALGOR_get0(NULL, &ptype, (void **)&pval, palg); | ||
383 | if (ptype != V_ASN1_SEQUENCE) { | ||
384 | GOSTerr(GOST_F_PUB_DECODE_GOST01, | ||
385 | GOST_R_BAD_KEY_PARAMETERS_FORMAT); | ||
386 | return 0; | ||
387 | } | ||
388 | p = pval->data; | ||
389 | if (!decode_gost01_algor_params(pk, &p, pval->length)) | ||
390 | return 0; | ||
391 | p = pkey_buf; | ||
392 | if (V_ASN1_OCTET_STRING == *p) { | ||
393 | /* New format - Little endian octet string */ | ||
394 | unsigned char rev_buf[32]; | ||
395 | int i; | ||
396 | ASN1_OCTET_STRING *s = d2i_ASN1_OCTET_STRING(NULL, &p, priv_len); | ||
397 | if (!s || s->length != 32) { | ||
398 | GOSTerr(GOST_F_PRIV_DECODE_GOST01, EVP_R_DECODE_ERROR); | ||
399 | return 0; | ||
400 | } | ||
401 | for (i = 0; i < 32; i++) { | ||
402 | rev_buf[31 - i] = s->data[i]; | ||
403 | } | ||
404 | ASN1_STRING_free(s); | ||
405 | pk_num = BN_bin2bn(rev_buf, 32, NULL); | ||
406 | } else { | ||
407 | priv_key = d2i_ASN1_INTEGER(NULL, &p, priv_len); | ||
408 | if (!priv_key) | ||
409 | return 0; | ||
410 | ret = ((pk_num = ASN1_INTEGER_to_BN(priv_key, NULL)) != NULL); | ||
411 | ASN1_INTEGER_free(priv_key); | ||
412 | if (!ret) { | ||
413 | GOSTerr(GOST_F_PRIV_DECODE_GOST01, EVP_R_DECODE_ERROR); | ||
414 | return 0; | ||
415 | } | ||
416 | } | ||
417 | |||
418 | ec = pk->pkey.gost; | ||
419 | if (!ec) { | ||
420 | ec = GOST_KEY_new(); | ||
421 | EVP_PKEY_assign_GOST(pk, ec); | ||
422 | } | ||
423 | if (!GOST_KEY_set_private_key(ec, pk_num)) { | ||
424 | BN_free(pk_num); | ||
425 | return 0; | ||
426 | } | ||
427 | if (!EVP_PKEY_missing_parameters(pk)) | ||
428 | gost2001_compute_public(ec); | ||
429 | BN_free(pk_num); | ||
430 | |||
431 | return 1; | ||
432 | } | ||
433 | |||
434 | static int priv_encode_gost01(PKCS8_PRIV_KEY_INFO * p8, const EVP_PKEY * pk) | ||
435 | { | ||
436 | ASN1_OBJECT *algobj = OBJ_nid2obj(GostR3410_get_pk_digest(GOST_KEY_get_digest(pk->pkey.gost))); | ||
437 | ASN1_STRING *params = encode_gost01_algor_params(pk); | ||
438 | unsigned char *priv_buf = NULL; | ||
439 | int priv_len; | ||
440 | |||
441 | ASN1_INTEGER *asn1key = NULL; | ||
442 | if (!params) { | ||
443 | return 0; | ||
444 | } | ||
445 | asn1key = BN_to_ASN1_INTEGER(GOST_KEY_get0_private_key(pk->pkey.gost), NULL); | ||
446 | priv_len = i2d_ASN1_INTEGER(asn1key, &priv_buf); | ||
447 | ASN1_INTEGER_free(asn1key); | ||
448 | return PKCS8_pkey_set0(p8, algobj, 0, V_ASN1_SEQUENCE, params, | ||
449 | priv_buf, priv_len); | ||
450 | } | ||
451 | |||
452 | static int param_encode_gost01(const EVP_PKEY * pkey, unsigned char **pder) | ||
453 | { | ||
454 | ASN1_STRING *params = encode_gost01_algor_params(pkey); | ||
455 | int len; | ||
456 | if (!params) | ||
457 | return 0; | ||
458 | len = params->length; | ||
459 | if (pder) | ||
460 | memcpy(*pder, params->data, params->length); | ||
461 | ASN1_STRING_free(params); | ||
462 | return len; | ||
463 | } | ||
464 | |||
465 | static int param_decode_gost01(EVP_PKEY * pkey, const unsigned char **pder, | ||
466 | int derlen) | ||
467 | { | ||
468 | ASN1_OBJECT *obj = NULL; | ||
469 | int nid; | ||
470 | GOST_KEY *ec; | ||
471 | EC_GROUP *group; | ||
472 | |||
473 | /* New format */ | ||
474 | if ((V_ASN1_SEQUENCE | V_ASN1_CONSTRUCTED) == **pder) | ||
475 | return decode_gost01_algor_params(pkey, pder, derlen); | ||
476 | |||
477 | /* Compatibility */ | ||
478 | if (d2i_ASN1_OBJECT(&obj, pder, derlen) == NULL) { | ||
479 | GOSTerr(GOST_F_PARAM_DECODE_GOST01, ERR_R_MALLOC_FAILURE); | ||
480 | return 0; | ||
481 | } | ||
482 | nid = OBJ_obj2nid(obj); | ||
483 | ASN1_OBJECT_free(obj); | ||
484 | |||
485 | ec = GOST_KEY_new(); | ||
486 | if (!ec) { | ||
487 | GOSTerr(GOST_F_PARAM_DECODE_GOST01, ERR_R_MALLOC_FAILURE); | ||
488 | return 0; | ||
489 | } | ||
490 | group = EC_GROUP_new_by_curve_name(nid); | ||
491 | if (group == NULL) { | ||
492 | GOSTerr(GOST_F_PARAM_DECODE_GOST01, EC_R_EC_GROUP_NEW_BY_NAME_FAILURE); | ||
493 | GOST_KEY_free(ec); | ||
494 | return 0; | ||
495 | } | ||
496 | |||
497 | EC_GROUP_set_asn1_flag(group, OPENSSL_EC_NAMED_CURVE); | ||
498 | if (GOST_KEY_set_group(ec, group) == 0) { | ||
499 | GOSTerr(GOST_F_PARAM_DECODE_GOST01, ERR_R_EC_LIB); | ||
500 | EC_GROUP_free(group); | ||
501 | GOST_KEY_free(ec); | ||
502 | return 0; | ||
503 | } | ||
504 | EC_GROUP_free(group); | ||
505 | if (GOST_KEY_set_digest(ec, NID_id_GostR3411_94_CryptoProParamSet) == 0) { | ||
506 | GOSTerr(GOST_F_PARAM_DECODE_GOST01, GOST_R_INVALID_DIGEST_TYPE); | ||
507 | GOST_KEY_free(ec); | ||
508 | return 0; | ||
509 | } | ||
510 | EVP_PKEY_assign_GOST(pkey, ec); | ||
511 | return 1; | ||
512 | } | ||
513 | |||
514 | static int param_missing_gost01(const EVP_PKEY * pk) | ||
515 | { | ||
516 | const GOST_KEY *ec = pk->pkey.gost; | ||
517 | if (!ec) | ||
518 | return 1; | ||
519 | if (!GOST_KEY_get0_group(ec)) | ||
520 | return 1; | ||
521 | if (GOST_KEY_get_digest(ec) == NID_undef) | ||
522 | return 1; | ||
523 | return 0; | ||
524 | } | ||
525 | |||
526 | static int param_copy_gost01(EVP_PKEY * to, const EVP_PKEY * from) | ||
527 | { | ||
528 | GOST_KEY *eto = to->pkey.gost; | ||
529 | const GOST_KEY *efrom = from->pkey.gost; | ||
530 | if (EVP_PKEY_base_id(from) != EVP_PKEY_base_id(to)) { | ||
531 | GOSTerr(GOST_F_PARAM_COPY_GOST01, | ||
532 | GOST_R_INCOMPATIBLE_ALGORITHMS); | ||
533 | return 0; | ||
534 | } | ||
535 | if (!efrom) { | ||
536 | GOSTerr(GOST_F_PARAM_COPY_GOST01, | ||
537 | GOST_R_KEY_PARAMETERS_MISSING); | ||
538 | return 0; | ||
539 | } | ||
540 | if (!eto) { | ||
541 | eto = GOST_KEY_new(); | ||
542 | EVP_PKEY_assign(to, EVP_PKEY_base_id(from), eto); | ||
543 | } | ||
544 | GOST_KEY_set_group(eto, GOST_KEY_get0_group(efrom)); | ||
545 | GOST_KEY_set_digest(eto, GOST_KEY_get_digest(efrom)); | ||
546 | if (GOST_KEY_get0_private_key(eto)) { | ||
547 | gost2001_compute_public(eto); | ||
548 | } | ||
549 | return 1; | ||
550 | } | ||
551 | |||
552 | static int param_cmp_gost01(const EVP_PKEY * a, const EVP_PKEY * b) | ||
553 | { | ||
554 | if (EC_GROUP_get_curve_name(GOST_KEY_get0_group(a->pkey.gost)) != | ||
555 | EC_GROUP_get_curve_name(GOST_KEY_get0_group(b->pkey.gost))) { | ||
556 | return 0; | ||
557 | } | ||
558 | if (GOST_KEY_get_digest(a->pkey.gost) != | ||
559 | GOST_KEY_get_digest(b->pkey.gost)) | ||
560 | return 0; | ||
561 | return 1; | ||
562 | |||
563 | } | ||
564 | |||
565 | static int pkey_ctrl_gost01(EVP_PKEY * pkey, int op, long arg1, void *arg2) | ||
566 | { | ||
567 | X509_ALGOR *alg1 = NULL, *alg2 = NULL, *alg3 = NULL; | ||
568 | int digest = GOST_KEY_get_digest(pkey->pkey.gost); | ||
569 | |||
570 | switch (op) { | ||
571 | case ASN1_PKEY_CTRL_PKCS7_SIGN: | ||
572 | if (arg1 == 0) | ||
573 | PKCS7_SIGNER_INFO_get0_algs(arg2, NULL, &alg1, &alg2); | ||
574 | break; | ||
575 | |||
576 | case ASN1_PKEY_CTRL_PKCS7_ENCRYPT: | ||
577 | if (arg1 == 0) | ||
578 | PKCS7_RECIP_INFO_get0_alg(arg2, &alg3); | ||
579 | break; | ||
580 | #ifndef OPENSSL_NO_CMS | ||
581 | case ASN1_PKEY_CTRL_CMS_SIGN: | ||
582 | if (arg1 == 0) | ||
583 | CMS_SignerInfo_get0_algs(arg2, NULL, NULL, &alg1, &alg2); | ||
584 | break; | ||
585 | |||
586 | case ASN1_PKEY_CTRL_CMS_ENVELOPE: | ||
587 | if (arg1 == 0) | ||
588 | CMS_RecipientInfo_ktri_get0_algs(arg2, NULL, NULL, &alg3); | ||
589 | break; | ||
590 | #endif | ||
591 | case ASN1_PKEY_CTRL_DEFAULT_MD_NID: | ||
592 | *(int *)arg2 = GostR3410_get_md_digest(digest); | ||
593 | return 2; | ||
594 | |||
595 | default: | ||
596 | return -2; | ||
597 | } | ||
598 | |||
599 | if (alg1) | ||
600 | X509_ALGOR_set0(alg1, OBJ_nid2obj(GostR3410_get_md_digest(digest)), V_ASN1_NULL, 0); | ||
601 | if (alg2) | ||
602 | X509_ALGOR_set0(alg2, OBJ_nid2obj(GostR3410_get_pk_digest(digest)), V_ASN1_NULL, 0); | ||
603 | if (alg3) { | ||
604 | ASN1_STRING *params = encode_gost01_algor_params(pkey); | ||
605 | if (!params) { | ||
606 | return -1; | ||
607 | } | ||
608 | X509_ALGOR_set0(alg3, OBJ_nid2obj(GostR3410_get_pk_digest(digest)), V_ASN1_SEQUENCE, params); | ||
609 | } | ||
610 | |||
611 | return 1; | ||
612 | } | ||
613 | |||
614 | const EVP_PKEY_ASN1_METHOD gostr01_asn1_meths[] = { | ||
615 | { | ||
616 | .pkey_id = EVP_PKEY_GOSTR01, | ||
617 | .pkey_base_id = EVP_PKEY_GOSTR01, | ||
618 | .pkey_flags = ASN1_PKEY_SIGPARAM_NULL, | ||
619 | |||
620 | .pem_str = "GOST2001", | ||
621 | .info = "GOST R 34.10-2001", | ||
622 | |||
623 | .pkey_free = pkey_free_gost01, | ||
624 | .pkey_ctrl = pkey_ctrl_gost01, | ||
625 | |||
626 | .priv_decode = priv_decode_gost01, | ||
627 | .priv_encode = priv_encode_gost01, | ||
628 | .priv_print = priv_print_gost01, | ||
629 | |||
630 | .param_decode = param_decode_gost01, | ||
631 | .param_encode = param_encode_gost01, | ||
632 | .param_missing = param_missing_gost01, | ||
633 | .param_copy = param_copy_gost01, | ||
634 | .param_cmp = param_cmp_gost01, | ||
635 | .param_print = param_print_gost01, | ||
636 | |||
637 | .pub_decode = pub_decode_gost01, | ||
638 | .pub_encode = pub_encode_gost01, | ||
639 | .pub_cmp = pub_cmp_gost01, | ||
640 | .pub_print = pub_print_gost01, | ||
641 | .pkey_size = pkey_size_gost01, | ||
642 | .pkey_bits = pkey_bits_gost01, | ||
643 | }, | ||
644 | { | ||
645 | .pkey_id = EVP_PKEY_GOSTR12_256, | ||
646 | .pkey_base_id = EVP_PKEY_GOSTR01, | ||
647 | .pkey_flags = ASN1_PKEY_ALIAS | ||
648 | }, | ||
649 | { | ||
650 | .pkey_id = EVP_PKEY_GOSTR12_512, | ||
651 | .pkey_base_id = EVP_PKEY_GOSTR01, | ||
652 | .pkey_flags = ASN1_PKEY_ALIAS | ||
653 | }, | ||
654 | }; | ||
655 | |||
656 | #endif | ||
diff --git a/src/lib/libssl/src/crypto/gost/gostr341001_key.c b/src/lib/libssl/src/crypto/gost/gostr341001_key.c new file mode 100644 index 0000000000..9c7f52b769 --- /dev/null +++ b/src/lib/libssl/src/crypto/gost/gostr341001_key.c | |||
@@ -0,0 +1,306 @@ | |||
1 | /* $OpenBSD: gostr341001_key.c,v 1.1 2014/11/09 19:17:13 miod Exp $ */ | ||
2 | /* | ||
3 | * Copyright (c) 2014 Dmitry Eremin-Solenikov <dbaryshkov@gmail.com> | ||
4 | * Copyright (c) 2005-2006 Cryptocom LTD | ||
5 | * | ||
6 | * Redistribution and use in source and binary forms, with or without | ||
7 | * modification, are permitted provided that the following conditions | ||
8 | * are met: | ||
9 | * | ||
10 | * 1. Redistributions of source code must retain the above copyright | ||
11 | * notice, this list of conditions and the following disclaimer. | ||
12 | * | ||
13 | * 2. Redistributions in binary form must reproduce the above copyright | ||
14 | * notice, this list of conditions and the following disclaimer in | ||
15 | * the documentation and/or other materials provided with the | ||
16 | * distribution. | ||
17 | * | ||
18 | * 3. All advertising materials mentioning features or use of this | ||
19 | * software must display the following acknowledgment: | ||
20 | * "This product includes software developed by the OpenSSL Project | ||
21 | * for use in the OpenSSL Toolkit. (http://www.openssl.org/)" | ||
22 | * | ||
23 | * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to | ||
24 | * endorse or promote products derived from this software without | ||
25 | * prior written permission. For written permission, please contact | ||
26 | * openssl-core@openssl.org. | ||
27 | * | ||
28 | * 5. Products derived from this software may not be called "OpenSSL" | ||
29 | * nor may "OpenSSL" appear in their names without prior written | ||
30 | * permission of the OpenSSL Project. | ||
31 | * | ||
32 | * 6. Redistributions of any form whatsoever must retain the following | ||
33 | * acknowledgment: | ||
34 | * "This product includes software developed by the OpenSSL Project | ||
35 | * for use in the OpenSSL Toolkit (http://www.openssl.org/)" | ||
36 | * | ||
37 | * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY | ||
38 | * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | ||
39 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR | ||
40 | * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR | ||
41 | * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, | ||
42 | * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT | ||
43 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; | ||
44 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | ||
45 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, | ||
46 | * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) | ||
47 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED | ||
48 | * OF THE POSSIBILITY OF SUCH DAMAGE. | ||
49 | * ==================================================================== | ||
50 | */ | ||
51 | |||
52 | #include <openssl/opensslconf.h> | ||
53 | |||
54 | #ifndef OPENSSL_NO_GOST | ||
55 | #include <openssl/err.h> | ||
56 | #include <openssl/gost.h> | ||
57 | #include <openssl/objects.h> | ||
58 | #include "gost_locl.h" | ||
59 | |||
60 | struct gost_key_st { | ||
61 | EC_GROUP *group; | ||
62 | |||
63 | EC_POINT *pub_key; | ||
64 | BIGNUM *priv_key; | ||
65 | |||
66 | int references; | ||
67 | |||
68 | int digest_nid; | ||
69 | }; | ||
70 | |||
71 | GOST_KEY * GOST_KEY_new(void) | ||
72 | { | ||
73 | GOST_KEY *ret; | ||
74 | |||
75 | ret = malloc(sizeof(GOST_KEY)); | ||
76 | if (ret == NULL) { | ||
77 | GOSTerr(GOST_F_GOST_KEY_NEW, ERR_R_MALLOC_FAILURE); | ||
78 | return (NULL); | ||
79 | } | ||
80 | ret->group = NULL; | ||
81 | ret->pub_key = NULL; | ||
82 | ret->priv_key = NULL; | ||
83 | ret->references = 1; | ||
84 | ret->digest_nid = NID_undef; | ||
85 | return (ret); | ||
86 | } | ||
87 | |||
88 | void GOST_KEY_free(GOST_KEY * r) | ||
89 | { | ||
90 | int i; | ||
91 | |||
92 | if (r == NULL) | ||
93 | return; | ||
94 | |||
95 | i = CRYPTO_add(&r->references, -1, CRYPTO_LOCK_EC); | ||
96 | if (i > 0) | ||
97 | return; | ||
98 | |||
99 | EC_GROUP_free(r->group); | ||
100 | EC_POINT_free(r->pub_key); | ||
101 | BN_clear_free(r->priv_key); | ||
102 | |||
103 | OPENSSL_cleanse((void *) r, sizeof(GOST_KEY)); | ||
104 | |||
105 | free(r); | ||
106 | } | ||
107 | |||
108 | int GOST_KEY_check_key(const GOST_KEY * key) | ||
109 | { | ||
110 | int ok = 0; | ||
111 | BN_CTX *ctx = NULL; | ||
112 | BIGNUM *order = NULL; | ||
113 | EC_POINT *point = NULL; | ||
114 | |||
115 | if (!key || !key->group || !key->pub_key) { | ||
116 | GOSTerr(GOST_F_GOST_KEY_CHECK_KEY, ERR_R_PASSED_NULL_PARAMETER); | ||
117 | return 0; | ||
118 | } | ||
119 | if (EC_POINT_is_at_infinity(key->group, key->pub_key)) { | ||
120 | GOSTerr(GOST_F_GOST_KEY_CHECK_KEY, EC_R_POINT_AT_INFINITY); | ||
121 | goto err; | ||
122 | } | ||
123 | if ((ctx = BN_CTX_new()) == NULL) | ||
124 | goto err; | ||
125 | if ((point = EC_POINT_new(key->group)) == NULL) | ||
126 | goto err; | ||
127 | |||
128 | /* testing whether the pub_key is on the elliptic curve */ | ||
129 | if (!EC_POINT_is_on_curve(key->group, key->pub_key, ctx)) { | ||
130 | GOSTerr(GOST_F_GOST_KEY_CHECK_KEY, EC_R_POINT_IS_NOT_ON_CURVE); | ||
131 | goto err; | ||
132 | } | ||
133 | /* testing whether pub_key * order is the point at infinity */ | ||
134 | if ((order = BN_new()) == NULL) | ||
135 | goto err; | ||
136 | if (!EC_GROUP_get_order(key->group, order, ctx)) { | ||
137 | GOSTerr(GOST_F_GOST_KEY_CHECK_KEY, EC_R_INVALID_GROUP_ORDER); | ||
138 | goto err; | ||
139 | } | ||
140 | if (!EC_POINT_mul(key->group, point, NULL, key->pub_key, order, ctx)) { | ||
141 | GOSTerr(GOST_F_GOST_KEY_CHECK_KEY, ERR_R_EC_LIB); | ||
142 | goto err; | ||
143 | } | ||
144 | if (!EC_POINT_is_at_infinity(key->group, point)) { | ||
145 | GOSTerr(GOST_F_GOST_KEY_CHECK_KEY, EC_R_WRONG_ORDER); | ||
146 | goto err; | ||
147 | } | ||
148 | /* | ||
149 | * in case the priv_key is present : check if generator * priv_key == | ||
150 | * pub_key | ||
151 | */ | ||
152 | if (key->priv_key) { | ||
153 | if (BN_cmp(key->priv_key, order) >= 0) { | ||
154 | GOSTerr(GOST_F_GOST_KEY_CHECK_KEY, EC_R_WRONG_ORDER); | ||
155 | goto err; | ||
156 | } | ||
157 | if (!EC_POINT_mul(key->group, point, key->priv_key, | ||
158 | NULL, NULL, ctx)) { | ||
159 | GOSTerr(GOST_F_GOST_KEY_CHECK_KEY, ERR_R_EC_LIB); | ||
160 | goto err; | ||
161 | } | ||
162 | if (EC_POINT_cmp(key->group, point, key->pub_key, | ||
163 | ctx) != 0) { | ||
164 | GOSTerr(GOST_F_GOST_KEY_CHECK_KEY, EC_R_INVALID_PRIVATE_KEY); | ||
165 | goto err; | ||
166 | } | ||
167 | } | ||
168 | ok = 1; | ||
169 | err: | ||
170 | BN_free(order); | ||
171 | BN_CTX_free(ctx); | ||
172 | EC_POINT_free(point); | ||
173 | return (ok); | ||
174 | } | ||
175 | |||
176 | int GOST_KEY_set_public_key_affine_coordinates(GOST_KEY * key, BIGNUM * x, BIGNUM * y) | ||
177 | { | ||
178 | BN_CTX *ctx = NULL; | ||
179 | BIGNUM *tx, *ty; | ||
180 | EC_POINT *point = NULL; | ||
181 | int ok = 0; | ||
182 | |||
183 | if (!key || !key->group || !x || !y) { | ||
184 | GOSTerr(GOST_F_GOST_KEY_SET_PUBLIC_KEY_AFFINE_COORDINATES, | ||
185 | ERR_R_PASSED_NULL_PARAMETER); | ||
186 | return 0; | ||
187 | } | ||
188 | ctx = BN_CTX_new(); | ||
189 | if (!ctx) | ||
190 | goto err; | ||
191 | |||
192 | point = EC_POINT_new(key->group); | ||
193 | |||
194 | if (!point) | ||
195 | goto err; | ||
196 | |||
197 | tx = BN_CTX_get(ctx); | ||
198 | ty = BN_CTX_get(ctx); | ||
199 | if (!EC_POINT_set_affine_coordinates_GFp(key->group, point, | ||
200 | x, y, ctx)) | ||
201 | goto err; | ||
202 | if (!EC_POINT_get_affine_coordinates_GFp(key->group, point, | ||
203 | tx, ty, ctx)) | ||
204 | goto err; | ||
205 | /* | ||
206 | * Check if retrieved coordinates match originals: if not values are | ||
207 | * out of range. | ||
208 | */ | ||
209 | if (BN_cmp(x, tx) || BN_cmp(y, ty)) { | ||
210 | GOSTerr(GOST_F_GOST_KEY_SET_PUBLIC_KEY_AFFINE_COORDINATES, | ||
211 | EC_R_COORDINATES_OUT_OF_RANGE); | ||
212 | goto err; | ||
213 | } | ||
214 | if (!GOST_KEY_set_public_key(key, point)) | ||
215 | goto err; | ||
216 | |||
217 | if (GOST_KEY_check_key(key) == 0) | ||
218 | goto err; | ||
219 | |||
220 | ok = 1; | ||
221 | |||
222 | err: | ||
223 | BN_CTX_free(ctx); | ||
224 | EC_POINT_free(point); | ||
225 | return ok; | ||
226 | |||
227 | } | ||
228 | |||
229 | const EC_GROUP * GOST_KEY_get0_group(const GOST_KEY * key) | ||
230 | { | ||
231 | return key->group; | ||
232 | } | ||
233 | |||
234 | int GOST_KEY_set_group(GOST_KEY * key, const EC_GROUP * group) | ||
235 | { | ||
236 | EC_GROUP_free(key->group); | ||
237 | key->group = EC_GROUP_dup(group); | ||
238 | return (key->group == NULL) ? 0 : 1; | ||
239 | } | ||
240 | |||
241 | const BIGNUM * GOST_KEY_get0_private_key(const GOST_KEY * key) | ||
242 | { | ||
243 | return key->priv_key; | ||
244 | } | ||
245 | |||
246 | int GOST_KEY_set_private_key(GOST_KEY * key, const BIGNUM * priv_key) | ||
247 | { | ||
248 | BN_clear_free(key->priv_key); | ||
249 | key->priv_key = BN_dup(priv_key); | ||
250 | return (key->priv_key == NULL) ? 0 : 1; | ||
251 | } | ||
252 | |||
253 | const EC_POINT * | ||
254 | GOST_KEY_get0_public_key(const GOST_KEY * key) | ||
255 | { | ||
256 | return key->pub_key; | ||
257 | } | ||
258 | |||
259 | int GOST_KEY_set_public_key(GOST_KEY * key, const EC_POINT * pub_key) | ||
260 | { | ||
261 | EC_POINT_free(key->pub_key); | ||
262 | key->pub_key = EC_POINT_dup(pub_key, key->group); | ||
263 | return (key->pub_key == NULL) ? 0 : 1; | ||
264 | } | ||
265 | |||
266 | int GOST_KEY_get_digest(const GOST_KEY * key) | ||
267 | { | ||
268 | return key->digest_nid; | ||
269 | } | ||
270 | int GOST_KEY_set_digest(GOST_KEY * key, int digest_nid) | ||
271 | { | ||
272 | if (digest_nid == NID_id_GostR3411_94_CryptoProParamSet || | ||
273 | digest_nid == NID_id_tc26_gost3411_2012_256 || | ||
274 | digest_nid == NID_id_tc26_gost3411_2012_512) { | ||
275 | key->digest_nid = digest_nid; | ||
276 | return 1; | ||
277 | } | ||
278 | |||
279 | return 0; | ||
280 | } | ||
281 | |||
282 | size_t GOST_KEY_get_size(const GOST_KEY * r) | ||
283 | { | ||
284 | int i; | ||
285 | BIGNUM *order = NULL; | ||
286 | const EC_GROUP *group; | ||
287 | |||
288 | if (r == NULL) | ||
289 | return 0; | ||
290 | group = GOST_KEY_get0_group(r); | ||
291 | if (group == NULL) | ||
292 | return 0; | ||
293 | |||
294 | if ((order = BN_new()) == NULL) | ||
295 | return 0; | ||
296 | |||
297 | if (!EC_GROUP_get_order(group,order,NULL)) { | ||
298 | BN_clear_free(order); | ||
299 | return 0; | ||
300 | } | ||
301 | |||
302 | i = BN_num_bytes(order); | ||
303 | BN_clear_free(order); | ||
304 | return (i); | ||
305 | } | ||
306 | #endif | ||
diff --git a/src/lib/libssl/src/crypto/gost/gostr341001_params.c b/src/lib/libssl/src/crypto/gost/gostr341001_params.c new file mode 100644 index 0000000000..1c8276e7b0 --- /dev/null +++ b/src/lib/libssl/src/crypto/gost/gostr341001_params.c | |||
@@ -0,0 +1,126 @@ | |||
1 | /* $OpenBSD: gostr341001_params.c,v 1.1 2014/11/09 19:17:13 miod Exp $ */ | ||
2 | /* | ||
3 | * Copyright (c) 2014 Dmitry Eremin-Solenikov <dbaryshkov@gmail.com> | ||
4 | * Copyright (c) 2005-2006 Cryptocom LTD | ||
5 | * | ||
6 | * Redistribution and use in source and binary forms, with or without | ||
7 | * modification, are permitted provided that the following conditions | ||
8 | * are met: | ||
9 | * | ||
10 | * 1. Redistributions of source code must retain the above copyright | ||
11 | * notice, this list of conditions and the following disclaimer. | ||
12 | * | ||
13 | * 2. Redistributions in binary form must reproduce the above copyright | ||
14 | * notice, this list of conditions and the following disclaimer in | ||
15 | * the documentation and/or other materials provided with the | ||
16 | * distribution. | ||
17 | * | ||
18 | * 3. All advertising materials mentioning features or use of this | ||
19 | * software must display the following acknowledgment: | ||
20 | * "This product includes software developed by the OpenSSL Project | ||
21 | * for use in the OpenSSL Toolkit. (http://www.openssl.org/)" | ||
22 | * | ||
23 | * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to | ||
24 | * endorse or promote products derived from this software without | ||
25 | * prior written permission. For written permission, please contact | ||
26 | * openssl-core@openssl.org. | ||
27 | * | ||
28 | * 5. Products derived from this software may not be called "OpenSSL" | ||
29 | * nor may "OpenSSL" appear in their names without prior written | ||
30 | * permission of the OpenSSL Project. | ||
31 | * | ||
32 | * 6. Redistributions of any form whatsoever must retain the following | ||
33 | * acknowledgment: | ||
34 | * "This product includes software developed by the OpenSSL Project | ||
35 | * for use in the OpenSSL Toolkit (http://www.openssl.org/)" | ||
36 | * | ||
37 | * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY | ||
38 | * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | ||
39 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR | ||
40 | * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR | ||
41 | * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, | ||
42 | * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT | ||
43 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; | ||
44 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | ||
45 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, | ||
46 | * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) | ||
47 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED | ||
48 | * OF THE POSSIBILITY OF SUCH DAMAGE. | ||
49 | * ==================================================================== | ||
50 | */ | ||
51 | |||
52 | #include <strings.h> | ||
53 | |||
54 | #include <openssl/opensslconf.h> | ||
55 | |||
56 | #ifndef OPENSSL_NO_GOST | ||
57 | #include <openssl/objects.h> | ||
58 | #include <openssl/gost.h> | ||
59 | |||
60 | #include "gost_locl.h" | ||
61 | |||
62 | int GostR3410_get_md_digest(int nid) | ||
63 | { | ||
64 | if (nid == NID_id_GostR3411_94_CryptoProParamSet) | ||
65 | return NID_id_GostR3411_94; | ||
66 | return nid; | ||
67 | } | ||
68 | |||
69 | int GostR3410_get_pk_digest(int nid) | ||
70 | { | ||
71 | switch (nid) { | ||
72 | case NID_id_GostR3411_94_CryptoProParamSet: | ||
73 | return NID_id_GostR3410_2001; | ||
74 | case NID_id_tc26_gost3411_2012_256: | ||
75 | return NID_id_tc26_gost3410_2012_256; | ||
76 | case NID_id_tc26_gost3411_2012_512: | ||
77 | return NID_id_tc26_gost3410_2012_512; | ||
78 | default: | ||
79 | return NID_undef; | ||
80 | } | ||
81 | } | ||
82 | |||
83 | typedef struct GostR3410_params { | ||
84 | const char *name; | ||
85 | int nid; | ||
86 | } GostR3410_params; | ||
87 | |||
88 | static const GostR3410_params GostR3410_256_params[] = { | ||
89 | { "A", NID_id_GostR3410_2001_CryptoPro_A_ParamSet }, | ||
90 | { "B", NID_id_GostR3410_2001_CryptoPro_B_ParamSet }, | ||
91 | { "C", NID_id_GostR3410_2001_CryptoPro_C_ParamSet }, | ||
92 | { "0", NID_id_GostR3410_2001_TestParamSet }, | ||
93 | { "XA", NID_id_GostR3410_2001_CryptoPro_XchA_ParamSet }, | ||
94 | { "XB", NID_id_GostR3410_2001_CryptoPro_XchB_ParamSet }, | ||
95 | { NULL, NID_undef }, | ||
96 | }; | ||
97 | |||
98 | static const GostR3410_params GostR3410_512_params[] = { | ||
99 | { "A", NID_id_tc26_gost_3410_2012_512_paramSetA }, | ||
100 | { "B", NID_id_tc26_gost_3410_2012_512_paramSetB }, | ||
101 | { NULL, NID_undef }, | ||
102 | }; | ||
103 | |||
104 | int GostR3410_256_param_id(const char *value) | ||
105 | { | ||
106 | int i; | ||
107 | for (i = 0; GostR3410_256_params[i].nid != NID_undef; i++) { | ||
108 | if (!strcasecmp(GostR3410_256_params[i].name, value)) | ||
109 | return GostR3410_256_params[i].nid; | ||
110 | } | ||
111 | |||
112 | return NID_undef; | ||
113 | } | ||
114 | |||
115 | int GostR3410_512_param_id(const char *value) | ||
116 | { | ||
117 | int i; | ||
118 | for (i = 0; GostR3410_512_params[i].nid != NID_undef; i++) { | ||
119 | if (!strcasecmp(GostR3410_512_params[i].name, value)) | ||
120 | return GostR3410_512_params[i].nid; | ||
121 | } | ||
122 | |||
123 | return NID_undef; | ||
124 | } | ||
125 | |||
126 | #endif | ||
diff --git a/src/lib/libssl/src/crypto/gost/gostr341001_pmeth.c b/src/lib/libssl/src/crypto/gost/gostr341001_pmeth.c new file mode 100644 index 0000000000..0f82e88a9d --- /dev/null +++ b/src/lib/libssl/src/crypto/gost/gostr341001_pmeth.c | |||
@@ -0,0 +1,657 @@ | |||
1 | /* $OpenBSD: gostr341001_pmeth.c,v 1.1 2014/11/09 19:17:13 miod Exp $ */ | ||
2 | /* | ||
3 | * Copyright (c) 2014 Dmitry Eremin-Solenikov <dbaryshkov@gmail.com> | ||
4 | * Copyright (c) 2005-2006 Cryptocom LTD | ||
5 | * | ||
6 | * Redistribution and use in source and binary forms, with or without | ||
7 | * modification, are permitted provided that the following conditions | ||
8 | * are met: | ||
9 | * | ||
10 | * 1. Redistributions of source code must retain the above copyright | ||
11 | * notice, this list of conditions and the following disclaimer. | ||
12 | * | ||
13 | * 2. Redistributions in binary form must reproduce the above copyright | ||
14 | * notice, this list of conditions and the following disclaimer in | ||
15 | * the documentation and/or other materials provided with the | ||
16 | * distribution. | ||
17 | * | ||
18 | * 3. All advertising materials mentioning features or use of this | ||
19 | * software must display the following acknowledgment: | ||
20 | * "This product includes software developed by the OpenSSL Project | ||
21 | * for use in the OpenSSL Toolkit. (http://www.openssl.org/)" | ||
22 | * | ||
23 | * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to | ||
24 | * endorse or promote products derived from this software without | ||
25 | * prior written permission. For written permission, please contact | ||
26 | * openssl-core@openssl.org. | ||
27 | * | ||
28 | * 5. Products derived from this software may not be called "OpenSSL" | ||
29 | * nor may "OpenSSL" appear in their names without prior written | ||
30 | * permission of the OpenSSL Project. | ||
31 | * | ||
32 | * 6. Redistributions of any form whatsoever must retain the following | ||
33 | * acknowledgment: | ||
34 | * "This product includes software developed by the OpenSSL Project | ||
35 | * for use in the OpenSSL Toolkit (http://www.openssl.org/)" | ||
36 | * | ||
37 | * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY | ||
38 | * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | ||
39 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR | ||
40 | * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR | ||
41 | * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, | ||
42 | * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT | ||
43 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; | ||
44 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | ||
45 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, | ||
46 | * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) | ||
47 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED | ||
48 | * OF THE POSSIBILITY OF SUCH DAMAGE. | ||
49 | * ==================================================================== | ||
50 | */ | ||
51 | |||
52 | #include <string.h> | ||
53 | |||
54 | #include <openssl/opensslconf.h> | ||
55 | |||
56 | #ifndef OPENSSL_NO_GOST | ||
57 | #include <openssl/evp.h> | ||
58 | #include <openssl/err.h> | ||
59 | #include <openssl/gost.h> | ||
60 | #include <openssl/ec.h> | ||
61 | #include <openssl/ecdsa.h> | ||
62 | #include <openssl/x509.h> | ||
63 | #include <openssl/rand.h> /* for RAND_bytes */ | ||
64 | |||
65 | #include "evp_locl.h" | ||
66 | #include "gost_locl.h" | ||
67 | #include "gost_asn1.h" | ||
68 | |||
69 | static ECDSA_SIG *unpack_signature_cp(const unsigned char *sig, size_t siglen) | ||
70 | { | ||
71 | ECDSA_SIG *s; | ||
72 | |||
73 | s = ECDSA_SIG_new(); | ||
74 | if (s == NULL) { | ||
75 | GOSTerr(GOST_F_UNPACK_SIGNATURE_CP, ERR_R_MALLOC_FAILURE); | ||
76 | return NULL; | ||
77 | } | ||
78 | BN_bin2bn(sig, siglen / 2, s->s); | ||
79 | BN_bin2bn(sig + siglen / 2, siglen / 2, s->r); | ||
80 | return s; | ||
81 | } | ||
82 | |||
83 | static int pack_signature_cp(ECDSA_SIG * s, int order, unsigned char *sig, size_t * siglen) | ||
84 | { | ||
85 | int r_len = BN_num_bytes(s->r); | ||
86 | int s_len = BN_num_bytes(s->s); | ||
87 | |||
88 | if ((r_len > order) || (s_len > order)) | ||
89 | return 0; | ||
90 | |||
91 | *siglen = 2 * order; | ||
92 | |||
93 | memset(sig, 0, *siglen); | ||
94 | BN_bn2bin(s->s, sig + order - s_len); | ||
95 | BN_bn2bin(s->r, sig + 2 * order - r_len); | ||
96 | ECDSA_SIG_free(s); | ||
97 | return 1; | ||
98 | } | ||
99 | |||
100 | static ECDSA_SIG *unpack_signature_le(const unsigned char *sig, size_t siglen) | ||
101 | { | ||
102 | ECDSA_SIG *s; | ||
103 | |||
104 | s = ECDSA_SIG_new(); | ||
105 | if (s == NULL) { | ||
106 | GOSTerr(GOST_F_UNPACK_SIGNATURE_LE, ERR_R_MALLOC_FAILURE); | ||
107 | return NULL; | ||
108 | } | ||
109 | GOST_le2bn(sig, siglen / 2, s->r); | ||
110 | GOST_le2bn(sig + siglen / 2, siglen / 2, s->s); | ||
111 | return s; | ||
112 | } | ||
113 | |||
114 | static int pack_signature_le(ECDSA_SIG * s, int order, unsigned char *sig, size_t * siglen) | ||
115 | { | ||
116 | *siglen = 2 * order; | ||
117 | memset(sig, 0, *siglen); | ||
118 | GOST_bn2le(s->r, sig, order); | ||
119 | GOST_bn2le(s->s, sig + order, order); | ||
120 | ECDSA_SIG_free(s); | ||
121 | return 1; | ||
122 | } | ||
123 | |||
124 | struct gost_pmeth_data { | ||
125 | int sign_param_nid; /* Should be set whenever parameters are filled */ | ||
126 | int digest_nid; | ||
127 | EVP_MD *md; | ||
128 | unsigned char *shared_ukm; | ||
129 | int peer_key_used; | ||
130 | int sig_format; | ||
131 | }; | ||
132 | |||
133 | static int pkey_gost01_init(EVP_PKEY_CTX * ctx) | ||
134 | { | ||
135 | struct gost_pmeth_data *data; | ||
136 | EVP_PKEY *pkey = EVP_PKEY_CTX_get0_pkey(ctx); | ||
137 | data = malloc(sizeof(struct gost_pmeth_data)); | ||
138 | if (!data) | ||
139 | return 0; | ||
140 | |||
141 | memset(data, 0, sizeof(struct gost_pmeth_data)); | ||
142 | if (pkey && pkey->pkey.gost) { | ||
143 | data->sign_param_nid = EC_GROUP_get_curve_name(GOST_KEY_get0_group(pkey->pkey.gost)); | ||
144 | data->digest_nid = GOST_KEY_get_digest(pkey->pkey.gost); | ||
145 | } | ||
146 | EVP_PKEY_CTX_set_data(ctx, data); | ||
147 | return 1; | ||
148 | } | ||
149 | |||
150 | /* Copies contents of gost_pmeth_data structure */ | ||
151 | static int pkey_gost01_copy(EVP_PKEY_CTX * dst, EVP_PKEY_CTX * src) | ||
152 | { | ||
153 | struct gost_pmeth_data *dst_data, *src_data; | ||
154 | if (!pkey_gost01_init(dst)) { | ||
155 | return 0; | ||
156 | } | ||
157 | src_data = EVP_PKEY_CTX_get_data(src); | ||
158 | dst_data = EVP_PKEY_CTX_get_data(dst); | ||
159 | *dst_data = *src_data; | ||
160 | if (src_data->shared_ukm) { | ||
161 | dst_data->shared_ukm = NULL; | ||
162 | } | ||
163 | return 1; | ||
164 | } | ||
165 | |||
166 | /* Frees up gost_pmeth_data structure */ | ||
167 | static void pkey_gost01_cleanup(EVP_PKEY_CTX * ctx) | ||
168 | { | ||
169 | struct gost_pmeth_data *data = EVP_PKEY_CTX_get_data(ctx); | ||
170 | free(data->shared_ukm); | ||
171 | free(data); | ||
172 | } | ||
173 | |||
174 | static int pkey_gost01_paramgen(EVP_PKEY_CTX * ctx, EVP_PKEY * pkey) | ||
175 | { | ||
176 | struct gost_pmeth_data *data = EVP_PKEY_CTX_get_data(ctx); | ||
177 | EC_GROUP *group; | ||
178 | GOST_KEY *gost; | ||
179 | int ret; | ||
180 | |||
181 | if (data->sign_param_nid == NID_undef || data->digest_nid == NID_undef) { | ||
182 | GOSTerr(GOST_F_PKEY_GOST01_PARAMGEN, GOST_R_NO_PARAMETERS_SET); | ||
183 | return 0; | ||
184 | } | ||
185 | |||
186 | group = EC_GROUP_new_by_curve_name(data->sign_param_nid); | ||
187 | if (!group) | ||
188 | return 0; | ||
189 | |||
190 | EC_GROUP_set_asn1_flag(group, OPENSSL_EC_NAMED_CURVE); | ||
191 | |||
192 | gost = GOST_KEY_new(); | ||
193 | if (!gost) | ||
194 | return 0; | ||
195 | |||
196 | if (!GOST_KEY_set_digest(gost, data->digest_nid)) | ||
197 | return 0; | ||
198 | |||
199 | ret = GOST_KEY_set_group(gost, group); | ||
200 | if (ret) | ||
201 | EVP_PKEY_assign_GOST(pkey, gost); | ||
202 | else | ||
203 | GOST_KEY_free(gost); | ||
204 | |||
205 | EC_GROUP_free(group); | ||
206 | return ret; | ||
207 | } | ||
208 | |||
209 | static int pkey_gost01_keygen(EVP_PKEY_CTX * ctx, EVP_PKEY * pkey) | ||
210 | { | ||
211 | if (!pkey_gost01_paramgen(ctx, pkey)) | ||
212 | return 0; | ||
213 | gost2001_keygen(pkey->pkey.gost); | ||
214 | return 1; | ||
215 | } | ||
216 | |||
217 | static int pkey_gost01_sign(EVP_PKEY_CTX * ctx, unsigned char *sig, | ||
218 | size_t * siglen, const unsigned char *tbs, | ||
219 | size_t tbs_len) | ||
220 | { | ||
221 | ECDSA_SIG *unpacked_sig = NULL; | ||
222 | EVP_PKEY *pkey = EVP_PKEY_CTX_get0_pkey(ctx); | ||
223 | struct gost_pmeth_data *pctx = EVP_PKEY_CTX_get_data(ctx); | ||
224 | BIGNUM *md; | ||
225 | size_t size = GOST_KEY_get_size(pkey->pkey.gost); | ||
226 | |||
227 | if (!siglen) | ||
228 | return 0; | ||
229 | if (!sig) { | ||
230 | *siglen = 2 * size; | ||
231 | return 1; | ||
232 | } else if (*siglen < 2 * size) { | ||
233 | GOSTerr(GOST_F_PKEY_GOST01_SIGN, EC_R_BUFFER_TOO_SMALL); | ||
234 | return 0; | ||
235 | } | ||
236 | OPENSSL_assert(tbs_len == 32 || tbs_len == 64); | ||
237 | md = GOST_le2bn(tbs, tbs_len, NULL); | ||
238 | unpacked_sig = gost2001_do_sign(md, pkey->pkey.gost); | ||
239 | #ifdef DEBUG_SIGN | ||
240 | fprintf(stderr, "S.R="); | ||
241 | BN_print_fp(stderr, unpacked_sig->r); | ||
242 | fprintf(stderr, "\nS.S="); | ||
243 | BN_print_fp(stderr, unpacked_sig->s); | ||
244 | fprintf(stderr, "\n"); | ||
245 | #endif | ||
246 | if (!unpacked_sig) { | ||
247 | return 0; | ||
248 | } | ||
249 | switch (pctx->sig_format) { | ||
250 | case GOST_SIG_FORMAT_SR_BE: | ||
251 | return pack_signature_cp(unpacked_sig, size, sig, siglen); | ||
252 | case GOST_SIG_FORMAT_RS_LE: | ||
253 | return pack_signature_le(unpacked_sig, size, sig, siglen); | ||
254 | default: | ||
255 | ECDSA_SIG_free(unpacked_sig); | ||
256 | return -1; | ||
257 | } | ||
258 | } | ||
259 | |||
260 | static int pkey_gost01_verify(EVP_PKEY_CTX * ctx, const unsigned char *sig, | ||
261 | size_t siglen, const unsigned char *tbs, | ||
262 | size_t tbs_len) | ||
263 | { | ||
264 | int ok = 0; | ||
265 | EVP_PKEY *pub_key = EVP_PKEY_CTX_get0_pkey(ctx); | ||
266 | struct gost_pmeth_data *pctx = EVP_PKEY_CTX_get_data(ctx); | ||
267 | ECDSA_SIG *s = NULL; | ||
268 | BIGNUM *md; | ||
269 | |||
270 | if (!pub_key) | ||
271 | return 0; | ||
272 | switch (pctx->sig_format) { | ||
273 | case GOST_SIG_FORMAT_SR_BE: | ||
274 | s = unpack_signature_cp(sig, siglen); | ||
275 | break; | ||
276 | case GOST_SIG_FORMAT_RS_LE: | ||
277 | s = unpack_signature_le(sig, siglen); | ||
278 | break; | ||
279 | } | ||
280 | if (!s) | ||
281 | return 0; | ||
282 | md = GOST_le2bn(tbs, tbs_len, NULL); | ||
283 | if (!md) | ||
284 | goto err; | ||
285 | #ifdef DEBUG_SIGN | ||
286 | fprintf(stderr, "V.R="); | ||
287 | BN_print_fp(stderr, s->r); | ||
288 | fprintf(stderr, "\nV.S="); | ||
289 | BN_print_fp(stderr, s->s); | ||
290 | fprintf(stderr, "\n"); | ||
291 | #endif | ||
292 | ok = gost2001_do_verify(md, s, pub_key->pkey.gost); | ||
293 | |||
294 | err: | ||
295 | BN_free(md); | ||
296 | ECDSA_SIG_free(s); | ||
297 | return ok; | ||
298 | } | ||
299 | |||
300 | static int gost01_VKO_key(EVP_PKEY * pub_key, EVP_PKEY * priv_key, | ||
301 | const unsigned char *ukm, unsigned char *key) | ||
302 | { | ||
303 | unsigned char hashbuf[128]; | ||
304 | int digest_nid; | ||
305 | int ret; | ||
306 | BN_CTX *ctx = BN_CTX_new(); | ||
307 | BIGNUM *UKM, *X, *Y; | ||
308 | |||
309 | BN_CTX_start(ctx); | ||
310 | UKM = BN_CTX_get(ctx); | ||
311 | X = BN_CTX_get(ctx); | ||
312 | Y = BN_CTX_get(ctx); | ||
313 | |||
314 | GOST_le2bn(ukm, 8, UKM); | ||
315 | |||
316 | digest_nid = GOST_KEY_get_digest(priv_key->pkey.gost); | ||
317 | VKO_compute_key(X, Y, pub_key->pkey.gost, priv_key->pkey.gost, UKM); | ||
318 | switch (digest_nid) { | ||
319 | case NID_id_GostR3411_94_CryptoProParamSet: | ||
320 | GOST_bn2le(X, hashbuf, 32); | ||
321 | GOST_bn2le(Y, hashbuf + 32, 32); | ||
322 | GOSTR341194(hashbuf, 64, key, digest_nid); | ||
323 | ret = 1; | ||
324 | break; | ||
325 | case NID_id_tc26_gost3411_2012_256: | ||
326 | GOST_bn2le(X, hashbuf, 32); | ||
327 | GOST_bn2le(Y, hashbuf + 32, 32); | ||
328 | STREEBOG256(hashbuf, 64, key); | ||
329 | ret = 1; | ||
330 | break; | ||
331 | case NID_id_tc26_gost3411_2012_512: | ||
332 | GOST_bn2le(X, hashbuf, 64); | ||
333 | GOST_bn2le(Y, hashbuf + 64, 64); | ||
334 | STREEBOG256(hashbuf, 128, key); | ||
335 | ret = 1; | ||
336 | break; | ||
337 | default: | ||
338 | ret = -2; | ||
339 | break; | ||
340 | } | ||
341 | BN_CTX_end(ctx); | ||
342 | BN_CTX_free(ctx); | ||
343 | return ret; | ||
344 | } | ||
345 | |||
346 | int pkey_gost01_decrypt(EVP_PKEY_CTX * pctx, unsigned char *key, | ||
347 | size_t * key_len, const unsigned char *in, | ||
348 | size_t in_len) | ||
349 | { | ||
350 | const unsigned char *p = in; | ||
351 | EVP_PKEY *priv = EVP_PKEY_CTX_get0_pkey(pctx); | ||
352 | GOST_KEY_TRANSPORT *gkt = NULL; | ||
353 | int ret = 0; | ||
354 | unsigned char wrappedKey[44]; | ||
355 | unsigned char sharedKey[32]; | ||
356 | EVP_PKEY *eph_key = NULL, *peerkey = NULL; | ||
357 | int nid; | ||
358 | |||
359 | if (!key) { | ||
360 | *key_len = 32; | ||
361 | return 1; | ||
362 | } | ||
363 | gkt = d2i_GOST_KEY_TRANSPORT(NULL, (const unsigned char **)&p, in_len); | ||
364 | if (!gkt) { | ||
365 | GOSTerr(GOST_F_PKEY_GOST01_DECRYPT, | ||
366 | GOST_R_ERROR_PARSING_KEY_TRANSPORT_INFO); | ||
367 | return -1; | ||
368 | } | ||
369 | |||
370 | /* If key transport structure contains public key, use it */ | ||
371 | eph_key = X509_PUBKEY_get(gkt->key_agreement_info->ephem_key); | ||
372 | if (eph_key) { | ||
373 | if (EVP_PKEY_derive_set_peer(pctx, eph_key) <= 0) { | ||
374 | GOSTerr(GOST_F_PKEY_GOST01_DECRYPT, | ||
375 | GOST_R_INCOMPATIBLE_PEER_KEY); | ||
376 | goto err; | ||
377 | } | ||
378 | } else { | ||
379 | /* Set control "public key from client certificate used" */ | ||
380 | if (EVP_PKEY_CTX_ctrl(pctx, -1, -1, EVP_PKEY_CTRL_PEER_KEY, 3, NULL) <= 0) { | ||
381 | GOSTerr(GOST_F_PKEY_GOST01_DECRYPT, GOST_R_CTRL_CALL_FAILED); | ||
382 | goto err; | ||
383 | } | ||
384 | } | ||
385 | peerkey = EVP_PKEY_CTX_get0_peerkey(pctx); | ||
386 | if (!peerkey) { | ||
387 | GOSTerr(GOST_F_PKEY_GOST01_DECRYPT, GOST_R_NO_PEER_KEY); | ||
388 | goto err; | ||
389 | } | ||
390 | |||
391 | nid = OBJ_obj2nid(gkt->key_agreement_info->cipher); | ||
392 | |||
393 | OPENSSL_assert(gkt->key_agreement_info->eph_iv->length == 8); | ||
394 | memcpy(wrappedKey, gkt->key_agreement_info->eph_iv->data, 8); | ||
395 | OPENSSL_assert(gkt->key_info->encrypted_key->length == 32); | ||
396 | memcpy(wrappedKey + 8, gkt->key_info->encrypted_key->data, 32); | ||
397 | OPENSSL_assert(gkt->key_info->imit->length == 4); | ||
398 | memcpy(wrappedKey + 40, gkt->key_info->imit->data, 4); | ||
399 | gost01_VKO_key(peerkey, priv, wrappedKey, sharedKey); | ||
400 | if (!key_unwrap_crypto_pro(nid, sharedKey, wrappedKey, key)) { | ||
401 | GOSTerr(GOST_F_PKEY_GOST01_DECRYPT, | ||
402 | GOST_R_ERROR_COMPUTING_SHARED_KEY); | ||
403 | goto err; | ||
404 | } | ||
405 | |||
406 | ret = 1; | ||
407 | err: | ||
408 | if (eph_key) | ||
409 | EVP_PKEY_free(eph_key); | ||
410 | if (gkt) | ||
411 | GOST_KEY_TRANSPORT_free(gkt); | ||
412 | return ret; | ||
413 | } | ||
414 | |||
415 | int pkey_gost01_derive(EVP_PKEY_CTX * ctx, unsigned char *key, | ||
416 | size_t * keylen) | ||
417 | { | ||
418 | /* Public key of peer in the ctx field peerkey | ||
419 | * Our private key in the ctx pkey | ||
420 | * ukm is in the algorithm specific context data | ||
421 | */ | ||
422 | EVP_PKEY *my_key = EVP_PKEY_CTX_get0_pkey(ctx); | ||
423 | EVP_PKEY *peer_key = EVP_PKEY_CTX_get0_peerkey(ctx); | ||
424 | struct gost_pmeth_data *data = EVP_PKEY_CTX_get_data(ctx); | ||
425 | |||
426 | if (!data->shared_ukm) { | ||
427 | GOSTerr(GOST_F_PKEY_GOST01_DERIVE, GOST_R_UKM_NOT_SET); | ||
428 | return 0; | ||
429 | } | ||
430 | |||
431 | if (key == NULL) { | ||
432 | *keylen = 32; | ||
433 | return 32; | ||
434 | } | ||
435 | |||
436 | gost01_VKO_key(peer_key, my_key, data->shared_ukm, key); | ||
437 | *keylen = 32; | ||
438 | return 1; | ||
439 | } | ||
440 | |||
441 | int pkey_gost01_encrypt(EVP_PKEY_CTX * pctx, unsigned char *out, | ||
442 | size_t * out_len, const unsigned char *key, | ||
443 | size_t key_len) | ||
444 | { | ||
445 | GOST_KEY_TRANSPORT *gkt = NULL; | ||
446 | EVP_PKEY *pubk = EVP_PKEY_CTX_get0_pkey(pctx); | ||
447 | struct gost_pmeth_data *data = EVP_PKEY_CTX_get_data(pctx); | ||
448 | unsigned char ukm[8], shared_key[32], crypted_key[44]; | ||
449 | int ret = 0; | ||
450 | int key_is_ephemeral = 1; | ||
451 | EVP_PKEY *sec_key = EVP_PKEY_CTX_get0_peerkey(pctx); | ||
452 | int nid = NID_id_Gost28147_89_CryptoPro_A_ParamSet; | ||
453 | |||
454 | if (data->shared_ukm) { | ||
455 | memcpy(ukm, data->shared_ukm, 8); | ||
456 | } else if (out) { | ||
457 | if (RAND_bytes(ukm, 8) <= 0) { | ||
458 | GOSTerr(GOST_F_PKEY_GOST01_ENCRYPT, | ||
459 | GOST_R_RANDOM_GENERATOR_FAILURE); | ||
460 | return 0; | ||
461 | } | ||
462 | } | ||
463 | /* Check for private key in the peer_key of context */ | ||
464 | if (sec_key) { | ||
465 | key_is_ephemeral = 0; | ||
466 | if (!GOST_KEY_get0_private_key(sec_key->pkey.gost)) { | ||
467 | GOSTerr(GOST_F_PKEY_GOST01_ENCRYPT, | ||
468 | GOST_R_NO_PRIVATE_PART_OF_NON_EPHEMERAL_KEYPAIR); | ||
469 | goto err; | ||
470 | } | ||
471 | } else { | ||
472 | key_is_ephemeral = 1; | ||
473 | if (out) { | ||
474 | sec_key = EVP_PKEY_new(); | ||
475 | EVP_PKEY_assign(sec_key, EVP_PKEY_base_id(pubk), | ||
476 | GOST_KEY_new()); | ||
477 | EVP_PKEY_copy_parameters(sec_key, pubk); | ||
478 | if (!gost2001_keygen(sec_key->pkey.gost)) { | ||
479 | goto err; | ||
480 | } | ||
481 | } | ||
482 | } | ||
483 | |||
484 | if (out) { | ||
485 | gost01_VKO_key(pubk, sec_key, ukm, shared_key); | ||
486 | key_wrap_crypto_pro(nid, shared_key, ukm, key, crypted_key); | ||
487 | } | ||
488 | gkt = GOST_KEY_TRANSPORT_new(); | ||
489 | if (!gkt) { | ||
490 | goto err; | ||
491 | } | ||
492 | if (!ASN1_OCTET_STRING_set(gkt->key_agreement_info->eph_iv, ukm, 8)) { | ||
493 | goto err; | ||
494 | } | ||
495 | if (!ASN1_OCTET_STRING_set(gkt->key_info->imit, crypted_key + 40, 4)) { | ||
496 | goto err; | ||
497 | } | ||
498 | if (!ASN1_OCTET_STRING_set(gkt->key_info->encrypted_key, crypted_key + 8, 32)) { | ||
499 | goto err; | ||
500 | } | ||
501 | if (key_is_ephemeral) { | ||
502 | if (!X509_PUBKEY_set | ||
503 | (&gkt->key_agreement_info->ephem_key, | ||
504 | out ? sec_key : pubk)) { | ||
505 | GOSTerr(GOST_F_PKEY_GOST01_ENCRYPT, | ||
506 | GOST_R_CANNOT_PACK_EPHEMERAL_KEY); | ||
507 | goto err; | ||
508 | } | ||
509 | } | ||
510 | ASN1_OBJECT_free(gkt->key_agreement_info->cipher); | ||
511 | gkt->key_agreement_info->cipher = OBJ_nid2obj(nid); | ||
512 | if (key_is_ephemeral && sec_key) | ||
513 | EVP_PKEY_free(sec_key); | ||
514 | if (!key_is_ephemeral) { | ||
515 | /* Set control "public key from client certificate used" */ | ||
516 | if (EVP_PKEY_CTX_ctrl | ||
517 | (pctx, -1, -1, EVP_PKEY_CTRL_PEER_KEY, 3, NULL) <= 0) { | ||
518 | GOSTerr(GOST_F_PKEY_GOST01_ENCRYPT, | ||
519 | GOST_R_CTRL_CALL_FAILED); | ||
520 | goto err; | ||
521 | } | ||
522 | } | ||
523 | if ((*out_len = i2d_GOST_KEY_TRANSPORT(gkt, out ? &out : NULL)) > 0) | ||
524 | ret = 1; | ||
525 | GOST_KEY_TRANSPORT_free(gkt); | ||
526 | return ret; | ||
527 | err: | ||
528 | if (key_is_ephemeral && sec_key) | ||
529 | EVP_PKEY_free(sec_key); | ||
530 | GOST_KEY_TRANSPORT_free(gkt); | ||
531 | return -1; | ||
532 | } | ||
533 | |||
534 | |||
535 | static int pkey_gost01_ctrl(EVP_PKEY_CTX * ctx, int type, int p1, void *p2) | ||
536 | { | ||
537 | struct gost_pmeth_data *pctx = EVP_PKEY_CTX_get_data(ctx); | ||
538 | switch (type) { | ||
539 | case EVP_PKEY_CTRL_MD: | ||
540 | if (EVP_MD_type(p2) != GostR3410_get_md_digest(pctx->digest_nid)) { | ||
541 | GOSTerr(GOST_F_PKEY_GOST01_CTRL, GOST_R_INVALID_DIGEST_TYPE); | ||
542 | return 0; | ||
543 | } | ||
544 | pctx->md = p2; | ||
545 | return 1; | ||
546 | case EVP_PKEY_CTRL_PKCS7_ENCRYPT: | ||
547 | case EVP_PKEY_CTRL_PKCS7_DECRYPT: | ||
548 | case EVP_PKEY_CTRL_PKCS7_SIGN: | ||
549 | case EVP_PKEY_CTRL_DIGESTINIT: | ||
550 | #ifndef OPENSSL_NO_CMS | ||
551 | case EVP_PKEY_CTRL_CMS_ENCRYPT: | ||
552 | case EVP_PKEY_CTRL_CMS_DECRYPT: | ||
553 | case EVP_PKEY_CTRL_CMS_SIGN: | ||
554 | #endif | ||
555 | return 1; | ||
556 | |||
557 | case EVP_PKEY_CTRL_GOST_PARAMSET: | ||
558 | pctx->sign_param_nid = (int)p1; | ||
559 | return 1; | ||
560 | |||
561 | case EVP_PKEY_CTRL_SET_IV: | ||
562 | pctx->shared_ukm = malloc((int)p1); | ||
563 | memcpy(pctx->shared_ukm, p2, (int)p1); | ||
564 | return 1; | ||
565 | |||
566 | case EVP_PKEY_CTRL_PEER_KEY: | ||
567 | if (p1 == 0 || p1 == 1) /* call from EVP_PKEY_derive_set_peer */ | ||
568 | return 1; | ||
569 | if (p1 == 2) /* TLS: peer key used? */ | ||
570 | return pctx->peer_key_used; | ||
571 | if (p1 == 3) /* TLS: peer key used! */ | ||
572 | return (pctx->peer_key_used = 1); | ||
573 | return -2; | ||
574 | case EVP_PKEY_CTRL_GOST_SIG_FORMAT: | ||
575 | switch (p1) { | ||
576 | case GOST_SIG_FORMAT_SR_BE: | ||
577 | case GOST_SIG_FORMAT_RS_LE: | ||
578 | pctx->sig_format = p1; | ||
579 | return 1; | ||
580 | default: | ||
581 | return 0; | ||
582 | } | ||
583 | break; | ||
584 | case EVP_PKEY_CTRL_GOST_SET_DIGEST: | ||
585 | pctx->digest_nid = (int)p1; | ||
586 | return 1; | ||
587 | case EVP_PKEY_CTRL_GOST_GET_DIGEST: | ||
588 | *(int *)p2 = pctx->digest_nid; | ||
589 | return 1; | ||
590 | default: | ||
591 | return -2; | ||
592 | } | ||
593 | } | ||
594 | |||
595 | static int pkey_gost01_ctrl_str(EVP_PKEY_CTX * ctx, | ||
596 | const char *type, const char *value) | ||
597 | { | ||
598 | int param_nid = NID_undef; | ||
599 | int digest_nid = NID_undef; | ||
600 | |||
601 | if (!strcmp(type, "paramset")) { | ||
602 | if (!value) { | ||
603 | return 0; | ||
604 | } | ||
605 | if (!pkey_gost01_ctrl(ctx, EVP_PKEY_CTRL_GOST_GET_DIGEST, 0, &digest_nid)) | ||
606 | return 0; | ||
607 | if (digest_nid == NID_id_tc26_gost3411_2012_512) | ||
608 | param_nid = GostR3410_512_param_id(value); | ||
609 | else | ||
610 | param_nid = GostR3410_256_param_id(value); | ||
611 | if (param_nid == NID_undef) | ||
612 | param_nid = OBJ_txt2nid(value); | ||
613 | if (param_nid == NID_undef) | ||
614 | return 0; | ||
615 | |||
616 | return pkey_gost01_ctrl(ctx, EVP_PKEY_CTRL_GOST_PARAMSET, | ||
617 | param_nid, NULL); | ||
618 | } | ||
619 | if (!strcmp(type, "dgst")) { | ||
620 | if (!value) | ||
621 | return 0; | ||
622 | else if (!strcmp(value, "gost94") || !strcmp(value, "md_gost94")) | ||
623 | digest_nid = NID_id_GostR3411_94_CryptoProParamSet; | ||
624 | else if (!strcmp(value, "streebog256")) | ||
625 | digest_nid = NID_id_tc26_gost3411_2012_256; | ||
626 | else if (!strcmp(value, "streebog512")) | ||
627 | digest_nid = NID_id_tc26_gost3411_2012_512; | ||
628 | |||
629 | if (digest_nid == NID_undef) | ||
630 | return 0; | ||
631 | |||
632 | return pkey_gost01_ctrl(ctx, EVP_PKEY_CTRL_GOST_SET_DIGEST, | ||
633 | digest_nid, NULL); | ||
634 | } | ||
635 | return -2; | ||
636 | } | ||
637 | |||
638 | const EVP_PKEY_METHOD gostr01_pkey_meth = { | ||
639 | .pkey_id = EVP_PKEY_GOSTR01, | ||
640 | |||
641 | .init = pkey_gost01_init, | ||
642 | .copy = pkey_gost01_copy, | ||
643 | .cleanup = pkey_gost01_cleanup, | ||
644 | |||
645 | .paramgen = pkey_gost01_paramgen, | ||
646 | .keygen = pkey_gost01_keygen, | ||
647 | .sign = pkey_gost01_sign, | ||
648 | .verify = pkey_gost01_verify, | ||
649 | |||
650 | .encrypt = pkey_gost01_encrypt, | ||
651 | .decrypt = pkey_gost01_decrypt, | ||
652 | .derive = pkey_gost01_derive, | ||
653 | |||
654 | .ctrl = pkey_gost01_ctrl, | ||
655 | .ctrl_str = pkey_gost01_ctrl_str, | ||
656 | }; | ||
657 | #endif | ||
diff --git a/src/lib/libssl/src/crypto/gost/gostr341194.c b/src/lib/libssl/src/crypto/gost/gostr341194.c new file mode 100644 index 0000000000..706bf3d431 --- /dev/null +++ b/src/lib/libssl/src/crypto/gost/gostr341194.c | |||
@@ -0,0 +1,259 @@ | |||
1 | /* $OpenBSD: gostr341194.c,v 1.1 2014/11/09 19:17:13 miod Exp $ */ | ||
2 | /* | ||
3 | * Copyright (c) 2014 Dmitry Eremin-Solenikov <dbaryshkov@gmail.com> | ||
4 | * Copyright (c) 2005-2006 Cryptocom LTD | ||
5 | * | ||
6 | * Redistribution and use in source and binary forms, with or without | ||
7 | * modification, are permitted provided that the following conditions | ||
8 | * are met: | ||
9 | * | ||
10 | * 1. Redistributions of source code must retain the above copyright | ||
11 | * notice, this list of conditions and the following disclaimer. | ||
12 | * | ||
13 | * 2. Redistributions in binary form must reproduce the above copyright | ||
14 | * notice, this list of conditions and the following disclaimer in | ||
15 | * the documentation and/or other materials provided with the | ||
16 | * distribution. | ||
17 | * | ||
18 | * 3. All advertising materials mentioning features or use of this | ||
19 | * software must display the following acknowledgment: | ||
20 | * "This product includes software developed by the OpenSSL Project | ||
21 | * for use in the OpenSSL Toolkit. (http://www.openssl.org/)" | ||
22 | * | ||
23 | * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to | ||
24 | * endorse or promote products derived from this software without | ||
25 | * prior written permission. For written permission, please contact | ||
26 | * openssl-core@openssl.org. | ||
27 | * | ||
28 | * 5. Products derived from this software may not be called "OpenSSL" | ||
29 | * nor may "OpenSSL" appear in their names without prior written | ||
30 | * permission of the OpenSSL Project. | ||
31 | * | ||
32 | * 6. Redistributions of any form whatsoever must retain the following | ||
33 | * acknowledgment: | ||
34 | * "This product includes software developed by the OpenSSL Project | ||
35 | * for use in the OpenSSL Toolkit (http://www.openssl.org/)" | ||
36 | * | ||
37 | * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY | ||
38 | * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | ||
39 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR | ||
40 | * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR | ||
41 | * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, | ||
42 | * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT | ||
43 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; | ||
44 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | ||
45 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, | ||
46 | * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) | ||
47 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED | ||
48 | * OF THE POSSIBILITY OF SUCH DAMAGE. | ||
49 | * ==================================================================== | ||
50 | */ | ||
51 | |||
52 | #include <string.h> | ||
53 | |||
54 | #include <openssl/opensslconf.h> | ||
55 | |||
56 | #ifndef OPENSSL_NO_GOST | ||
57 | #include <openssl/crypto.h> | ||
58 | #include <openssl/objects.h> | ||
59 | #include <openssl/gost.h> | ||
60 | |||
61 | #include "gost_locl.h" | ||
62 | |||
63 | /* Following functions are various bit meshing routines used in | ||
64 | * GOST R 34.11-94 algorithms */ | ||
65 | static void swap_bytes(unsigned char *w, unsigned char *k) | ||
66 | { | ||
67 | int i, j; | ||
68 | for (i = 0; i < 4; i++) | ||
69 | for (j = 0; j < 8; j++) | ||
70 | k[i + 4 * j] = w[8 * i + j]; | ||
71 | |||
72 | } | ||
73 | |||
74 | /* was A_A */ | ||
75 | static void circle_xor8(const unsigned char *w, unsigned char *k) | ||
76 | { | ||
77 | unsigned char buf[8]; | ||
78 | int i; | ||
79 | |||
80 | memcpy(buf, w, 8); | ||
81 | memmove(k, w + 8, 24); | ||
82 | for (i = 0; i < 8; i++) | ||
83 | k[i + 24] = buf[i] ^ k[i]; | ||
84 | } | ||
85 | |||
86 | /* was R_R */ | ||
87 | static void transform_3(unsigned char *data) | ||
88 | { | ||
89 | unsigned short int acc; | ||
90 | acc = (data[0] ^ data[2] ^ data[4] ^ data[6] ^ data[24] ^ data[30]) | | ||
91 | ((data[1] ^ data[3] ^ data[5] ^ data[7] ^ data[25] ^ data[31]) << 8); | ||
92 | memmove(data, data + 2, 30); | ||
93 | data[30] = acc & 0xff; | ||
94 | data[31] = acc >> 8; | ||
95 | } | ||
96 | |||
97 | /* Adds blocks of N bytes modulo 2**(8*n). Returns carry*/ | ||
98 | static int add_blocks(int n, unsigned char *left, const unsigned char *right) | ||
99 | { | ||
100 | int i; | ||
101 | int carry = 0; | ||
102 | int sum; | ||
103 | |||
104 | for (i = 0; i < n; i++) { | ||
105 | sum = (int)left[i] + (int)right[i] + carry; | ||
106 | left[i] = sum & 0xff; | ||
107 | carry = sum >> 8; | ||
108 | } | ||
109 | return carry; | ||
110 | } | ||
111 | |||
112 | /* Xor two sequences of bytes */ | ||
113 | static void xor_blocks(unsigned char *result, const unsigned char *a, | ||
114 | const unsigned char *b, size_t len) | ||
115 | { | ||
116 | size_t i; | ||
117 | for (i = 0; i < len; i++) | ||
118 | result[i] = a[i] ^ b[i]; | ||
119 | } | ||
120 | |||
121 | /* | ||
122 | * Calculate H(i+1) = Hash(Hi,Mi) | ||
123 | * Where H and M are 32 bytes long | ||
124 | */ | ||
125 | static int hash_step(GOSTR341194_CTX *c, unsigned char *H, const unsigned char *M) | ||
126 | { | ||
127 | unsigned char U[32], W[32], V[32], S[32], Key[32]; | ||
128 | int i; | ||
129 | |||
130 | /* Compute first key */ | ||
131 | xor_blocks(W, H, M, 32); | ||
132 | swap_bytes(W, Key); | ||
133 | /* Encrypt first 8 bytes of H with first key */ | ||
134 | Gost2814789_set_key(&c->cipher, Key, 256); | ||
135 | Gost2814789_encrypt(H, S, &c->cipher); | ||
136 | |||
137 | /* Compute second key */ | ||
138 | circle_xor8(H, U); | ||
139 | circle_xor8(M, V); | ||
140 | circle_xor8(V, V); | ||
141 | xor_blocks(W, U, V, 32); | ||
142 | swap_bytes(W, Key); | ||
143 | /* encrypt second 8 bytes of H with second key */ | ||
144 | Gost2814789_set_key(&c->cipher, Key, 256); | ||
145 | Gost2814789_encrypt(H+8, S+8, &c->cipher); | ||
146 | |||
147 | /* compute third key */ | ||
148 | circle_xor8(U, U); | ||
149 | U[31] = ~U[31]; | ||
150 | U[29] = ~U[29]; | ||
151 | U[28] = ~U[28]; | ||
152 | U[24] = ~U[24]; | ||
153 | U[23] = ~U[23]; | ||
154 | U[20] = ~U[20]; | ||
155 | U[18] = ~U[18]; | ||
156 | U[17] = ~U[17]; | ||
157 | U[14] = ~U[14]; | ||
158 | U[12] = ~U[12]; | ||
159 | U[10] = ~U[10]; | ||
160 | U[8] = ~U[8]; | ||
161 | U[7] = ~U[7]; | ||
162 | U[5] = ~U[5]; | ||
163 | U[3] = ~U[3]; | ||
164 | U[1] = ~U[1]; | ||
165 | circle_xor8(V, V); | ||
166 | circle_xor8(V, V); | ||
167 | xor_blocks(W, U, V, 32); | ||
168 | swap_bytes(W, Key); | ||
169 | /* encrypt third 8 bytes of H with third key */ | ||
170 | Gost2814789_set_key(&c->cipher, Key, 256); | ||
171 | Gost2814789_encrypt(H+16, S+16, &c->cipher); | ||
172 | |||
173 | /* Compute fourth key */ | ||
174 | circle_xor8(U, U); | ||
175 | circle_xor8(V, V); | ||
176 | circle_xor8(V, V); | ||
177 | xor_blocks(W, U, V, 32); | ||
178 | swap_bytes(W, Key); | ||
179 | /* Encrypt last 8 bytes with fourth key */ | ||
180 | Gost2814789_set_key(&c->cipher, Key, 256); | ||
181 | Gost2814789_encrypt(H+24, S+24, &c->cipher); | ||
182 | |||
183 | for (i = 0; i < 12; i++) | ||
184 | transform_3(S); | ||
185 | xor_blocks(S, S, M, 32); | ||
186 | transform_3(S); | ||
187 | xor_blocks(S, S, H, 32); | ||
188 | for (i = 0; i < 61; i++) | ||
189 | transform_3(S); | ||
190 | memcpy(H, S, 32); | ||
191 | return 1; | ||
192 | } | ||
193 | |||
194 | int GOSTR341194_Init(GOSTR341194_CTX *c, int nid) | ||
195 | { | ||
196 | memset (c,0,sizeof(*c)); | ||
197 | return Gost2814789_set_sbox(&c->cipher, nid); | ||
198 | } | ||
199 | |||
200 | static void GOSTR341194_block_data_order(GOSTR341194_CTX *ctx, const void *p, size_t num) | ||
201 | { | ||
202 | int i; | ||
203 | for (i = 0; i < num; i++) { | ||
204 | hash_step(ctx, ctx->H, p); | ||
205 | add_blocks(32, ctx->S, p); | ||
206 | p += 32; | ||
207 | } | ||
208 | } | ||
209 | |||
210 | #define DATA_ORDER_IS_LITTLE_ENDIAN | ||
211 | |||
212 | #define HASH_CBLOCK GOSTR341194_CBLOCK | ||
213 | #define HASH_LONG GOSTR341194_LONG | ||
214 | #define HASH_CTX GOSTR341194_CTX | ||
215 | #define HASH_UPDATE GOSTR341194_Update | ||
216 | #define HASH_TRANSFORM GOSTR341194_Transform | ||
217 | #define HASH_NO_FINAL 1 | ||
218 | #define HASH_BLOCK_DATA_ORDER GOSTR341194_block_data_order | ||
219 | |||
220 | #include "md32_common.h" | ||
221 | |||
222 | int GOSTR341194_Final(unsigned char *md, GOSTR341194_CTX * c) | ||
223 | { | ||
224 | unsigned char *p = (unsigned char *)c->data; | ||
225 | unsigned char T[32]; | ||
226 | |||
227 | if (c->num > 0) { | ||
228 | memset(p + c->num, 0, 32); | ||
229 | hash_step(c, c->H, p); | ||
230 | add_blocks(32, c->S, p); | ||
231 | } | ||
232 | |||
233 | p = T; | ||
234 | HOST_l2c(c->Nl, p); | ||
235 | HOST_l2c(c->Nh, p); | ||
236 | memset(p, 0, 32-8); | ||
237 | hash_step(c, c->H, T); | ||
238 | hash_step(c, c->H, c->S); | ||
239 | |||
240 | memcpy(md, c->H, 32); | ||
241 | |||
242 | return 1; | ||
243 | } | ||
244 | |||
245 | unsigned char *GOSTR341194(const unsigned char *d, size_t n, unsigned char *md, int nid) | ||
246 | { | ||
247 | GOSTR341194_CTX c; | ||
248 | static unsigned char m[GOSTR341194_LENGTH]; | ||
249 | |||
250 | if (md == NULL) | ||
251 | md = m; | ||
252 | if (!GOSTR341194_Init(&c, nid)) | ||
253 | return 0; | ||
254 | GOSTR341194_Update(&c, d, n); | ||
255 | GOSTR341194_Final(md, &c); | ||
256 | OPENSSL_cleanse(&c, sizeof(c)); | ||
257 | return (md); | ||
258 | } | ||
259 | #endif | ||
diff --git a/src/lib/libssl/src/crypto/gost/streebog.c b/src/lib/libssl/src/crypto/gost/streebog.c new file mode 100644 index 0000000000..c621c41daa --- /dev/null +++ b/src/lib/libssl/src/crypto/gost/streebog.c | |||
@@ -0,0 +1,1436 @@ | |||
1 | /* $OpenBSD: streebog.c,v 1.1 2014/11/09 19:17:13 miod Exp $ */ | ||
2 | /* | ||
3 | * Copyright (c) 2014 Dmitry Eremin-Solenikov <dbaryshkov@gmail.com> | ||
4 | * Copyright (c) 2005-2006 Cryptocom LTD | ||
5 | * | ||
6 | * Redistribution and use in source and binary forms, with or without | ||
7 | * modification, are permitted provided that the following conditions | ||
8 | * are met: | ||
9 | * | ||
10 | * 1. Redistributions of source code must retain the above copyright | ||
11 | * notice, this list of conditions and the following disclaimer. | ||
12 | * | ||
13 | * 2. Redistributions in binary form must reproduce the above copyright | ||
14 | * notice, this list of conditions and the following disclaimer in | ||
15 | * the documentation and/or other materials provided with the | ||
16 | * distribution. | ||
17 | * | ||
18 | * 3. All advertising materials mentioning features or use of this | ||
19 | * software must display the following acknowledgment: | ||
20 | * "This product includes software developed by the OpenSSL Project | ||
21 | * for use in the OpenSSL Toolkit. (http://www.openssl.org/)" | ||
22 | * | ||
23 | * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to | ||
24 | * endorse or promote products derived from this software without | ||
25 | * prior written permission. For written permission, please contact | ||
26 | * openssl-core@openssl.org. | ||
27 | * | ||
28 | * 5. Products derived from this software may not be called "OpenSSL" | ||
29 | * nor may "OpenSSL" appear in their names without prior written | ||
30 | * permission of the OpenSSL Project. | ||
31 | * | ||
32 | * 6. Redistributions of any form whatsoever must retain the following | ||
33 | * acknowledgment: | ||
34 | * "This product includes software developed by the OpenSSL Project | ||
35 | * for use in the OpenSSL Toolkit (http://www.openssl.org/)" | ||
36 | * | ||
37 | * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY | ||
38 | * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | ||
39 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR | ||
40 | * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR | ||
41 | * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, | ||
42 | * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT | ||
43 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; | ||
44 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | ||
45 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, | ||
46 | * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) | ||
47 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED | ||
48 | * OF THE POSSIBILITY OF SUCH DAMAGE. | ||
49 | * ==================================================================== | ||
50 | */ | ||
51 | |||
52 | #include <string.h> | ||
53 | |||
54 | #include <openssl/opensslconf.h> | ||
55 | |||
56 | #ifndef OPENSSL_NO_GOST | ||
57 | #include <openssl/crypto.h> | ||
58 | #include <openssl/objects.h> | ||
59 | #include <openssl/gost.h> | ||
60 | |||
61 | #include "gost_locl.h" | ||
62 | |||
63 | static const STREEBOG_LONG64 A_PI_table[8][256] = | ||
64 | { | ||
65 | { /* 0 */ | ||
66 | U64(0xd01f715b5c7ef8e6), U64(0x16fa240980778325), | ||
67 | U64(0xa8a42e857ee049c8), U64(0x6ac1068fa186465b), | ||
68 | U64(0x6e417bd7a2e9320b), U64(0x665c8167a437daab), | ||
69 | U64(0x7666681aa89617f6), U64(0x4b959163700bdcf5), | ||
70 | U64(0xf14be6b78df36248), U64(0xc585bd689a625cff), | ||
71 | U64(0x9557d7fca67d82cb), U64(0x89f0b969af6dd366), | ||
72 | U64(0xb0833d48749f6c35), U64(0xa1998c23b1ecbc7c), | ||
73 | U64(0x8d70c431ac02a736), U64(0xd6dfbc2fd0a8b69e), | ||
74 | U64(0x37aeb3e551fa198b), U64(0x0b7d128a40b5cf9c), | ||
75 | U64(0x5a8f2008b5780cbc), U64(0xedec882284e333e5), | ||
76 | U64(0xd25fc177d3c7c2ce), U64(0x5e0f5d50b61778ec), | ||
77 | U64(0x1d873683c0c24cb9), U64(0xad040bcbb45d208c), | ||
78 | U64(0x2f89a0285b853c76), U64(0x5732fff6791b8d58), | ||
79 | U64(0x3e9311439ef6ec3f), U64(0xc9183a809fd3c00f), | ||
80 | U64(0x83adf3f5260a01ee), U64(0xa6791941f4e8ef10), | ||
81 | U64(0x103ae97d0ca1cd5d), U64(0x2ce948121dee1b4a), | ||
82 | U64(0x39738421dbf2bf53), U64(0x093da2a6cf0cf5b4), | ||
83 | U64(0xcd9847d89cbcb45f), U64(0xf9561c078b2d8ae8), | ||
84 | U64(0x9c6a755a6971777f), U64(0xbc1ebaa0712ef0c5), | ||
85 | U64(0x72e61542abf963a6), U64(0x78bb5fde229eb12e), | ||
86 | U64(0x14ba94250fceb90d), U64(0x844d6697630e5282), | ||
87 | U64(0x98ea08026a1e032f), U64(0xf06bbea144217f5c), | ||
88 | U64(0xdb6263d11ccb377a), U64(0x641c314b2b8ee083), | ||
89 | U64(0x320e96ab9b4770cf), U64(0x1ee7deb986a96b85), | ||
90 | U64(0xe96cf57a878c47b5), U64(0xfdd6615f8842feb8), | ||
91 | U64(0xc83862965601dd1b), U64(0x2ea9f83e92572162), | ||
92 | U64(0xf876441142ff97fc), U64(0xeb2c455608357d9d), | ||
93 | U64(0x5612a7e0b0c9904c), U64(0x6c01cbfb2d500823), | ||
94 | U64(0x4548a6a7fa037a2d), U64(0xabc4c6bf388b6ef4), | ||
95 | U64(0xbade77d4fdf8bebd), U64(0x799b07c8eb4cac3a), | ||
96 | U64(0x0c9d87e805b19cf0), U64(0xcb588aac106afa27), | ||
97 | U64(0xea0c1d40c1e76089), U64(0x2869354a1e816f1a), | ||
98 | U64(0xff96d17307fbc490), U64(0x9f0a9d602f1a5043), | ||
99 | U64(0x96373fc6e016a5f7), U64(0x5292dab8b3a6e41c), | ||
100 | U64(0x9b8ae0382c752413), U64(0x4f15ec3b7364a8a5), | ||
101 | U64(0x3fb349555724f12b), U64(0xc7c50d4415db66d7), | ||
102 | U64(0x92b7429ee379d1a7), U64(0xd37f99611a15dfda), | ||
103 | U64(0x231427c05e34a086), U64(0xa439a96d7b51d538), | ||
104 | U64(0xb403401077f01865), U64(0xdda2aea5901d7902), | ||
105 | U64(0x0a5d4a9c8967d288), U64(0xc265280adf660f93), | ||
106 | U64(0x8bb0094520d4e94e), U64(0x2a29856691385532), | ||
107 | U64(0x42a833c5bf072941), U64(0x73c64d54622b7eb2), | ||
108 | U64(0x07e095624504536c), U64(0x8a905153e906f45a), | ||
109 | U64(0x6f6123c16b3b2f1f), U64(0xc6e55552dc097bc3), | ||
110 | U64(0x4468feb133d16739), U64(0xe211e7f0c7398829), | ||
111 | U64(0xa2f96419f7879b40), U64(0x19074bdbc3ad38e9), | ||
112 | U64(0xf4ebc3f9474e0b0c), U64(0x43886bd376d53455), | ||
113 | U64(0xd8028beb5aa01046), U64(0x51f23282f5cdc320), | ||
114 | U64(0xe7b1c2be0d84e16d), U64(0x081dfab006dee8a0), | ||
115 | U64(0x3b33340d544b857b), U64(0x7f5bcabc679ae242), | ||
116 | U64(0x0edd37c48a08a6d8), U64(0x81ed43d9a9b33bc6), | ||
117 | U64(0xb1a3655ebd4d7121), U64(0x69a1eeb5e7ed6167), | ||
118 | U64(0xf6ab73d5c8f73124), U64(0x1a67a3e185c61fd5), | ||
119 | U64(0x2dc91004d43c065e), U64(0x0240b02c8fb93a28), | ||
120 | U64(0x90f7f2b26cc0eb8f), U64(0x3cd3a16f114fd617), | ||
121 | U64(0xaae49ea9f15973e0), U64(0x06c0cd748cd64e78), | ||
122 | U64(0xda423bc7d5192a6e), U64(0xc345701c16b41287), | ||
123 | U64(0x6d2193ede4821537), U64(0xfcf639494190e3ac), | ||
124 | U64(0x7c3b228621f1c57e), U64(0xfb16ac2b0494b0c0), | ||
125 | U64(0xbf7e529a3745d7f9), U64(0x6881b6a32e3f7c73), | ||
126 | U64(0xca78d2bad9b8e733), U64(0xbbfe2fc2342aa3a9), | ||
127 | U64(0x0dbddffecc6381e4), U64(0x70a6a56e2440598e), | ||
128 | U64(0xe4d12a844befc651), U64(0x8c509c2765d0ba22), | ||
129 | U64(0xee8c6018c28814d9), U64(0x17da7c1f49a59e31), | ||
130 | U64(0x609c4c1328e194d3), U64(0xb3e3d57232f44b09), | ||
131 | U64(0x91d7aaa4a512f69b), U64(0x0ffd6fd243dabbcc), | ||
132 | U64(0x50d26a943c1fde34), U64(0x6be15e9968545b4f), | ||
133 | U64(0x94778fea6faf9fdf), U64(0x2b09dd7058ea4826), | ||
134 | U64(0x677cd9716de5c7bf), U64(0x49d5214fffb2e6dd), | ||
135 | U64(0x0360e83a466b273c), U64(0x1fc786af4f7b7691), | ||
136 | U64(0xa0b9d435783ea168), U64(0xd49f0c035f118cb6), | ||
137 | U64(0x01205816c9d21d14), U64(0xac2453dd7d8f3d98), | ||
138 | U64(0x545217cc3f70aa64), U64(0x26b4028e9489c9c2), | ||
139 | U64(0xdec2469fd6765e3e), U64(0x04807d58036f7450), | ||
140 | U64(0xe5f17292823ddb45), U64(0xf30b569b024a5860), | ||
141 | U64(0x62dcfc3fa758aefb), U64(0xe84cad6c4e5e5aa1), | ||
142 | U64(0xccb81fce556ea94b), U64(0x53b282ae7a74f908), | ||
143 | U64(0x1b47fbf74c1402c1), U64(0x368eebf39828049f), | ||
144 | U64(0x7afbeff2ad278b06), U64(0xbe5e0a8cfe97caed), | ||
145 | U64(0xcfd8f7f413058e77), U64(0xf78b2bc301252c30), | ||
146 | U64(0x4d555c17fcdd928d), U64(0x5f2f05467fc565f8), | ||
147 | U64(0x24f4b2a21b30f3ea), U64(0x860dd6bbecb768aa), | ||
148 | U64(0x4c750401350f8f99), U64(0x0000000000000000), | ||
149 | U64(0xecccd0344d312ef1), U64(0xb5231806be220571), | ||
150 | U64(0xc105c030990d28af), U64(0x653c695de25cfd97), | ||
151 | U64(0x159acc33c61ca419), U64(0xb89ec7f872418495), | ||
152 | U64(0xa9847693b73254dc), U64(0x58cf90243ac13694), | ||
153 | U64(0x59efc832f3132b80), U64(0x5c4fed7c39ae42c4), | ||
154 | U64(0x828dabe3efd81cfa), U64(0xd13f294d95ace5f2), | ||
155 | U64(0x7d1b7a90e823d86a), U64(0xb643f03cf849224d), | ||
156 | U64(0x3df3f979d89dcb03), U64(0x7426d836272f2dde), | ||
157 | U64(0xdfe21e891fa4432a), U64(0x3a136c1b9d99986f), | ||
158 | U64(0xfa36f43dcd46add4), U64(0xc025982650df35bb), | ||
159 | U64(0x856d3e81aadc4f96), U64(0xc4a5e57e53b041eb), | ||
160 | U64(0x4708168b75ba4005), U64(0xaf44bbe73be41aa4), | ||
161 | U64(0x971767d029c4b8e3), U64(0xb9be9feebb939981), | ||
162 | U64(0x215497ecd18d9aae), U64(0x316e7e91dd2c57f3), | ||
163 | U64(0xcef8afe2dad79363), U64(0x3853dc371220a247), | ||
164 | U64(0x35ee03c9de4323a3), U64(0xe6919aa8c456fc79), | ||
165 | U64(0xe05157dc4880b201), U64(0x7bdbb7e464f59612), | ||
166 | U64(0x127a59518318f775), U64(0x332ecebd52956ddb), | ||
167 | U64(0x8f30741d23bb9d1e), U64(0xd922d3fd93720d52), | ||
168 | U64(0x7746300c61440ae2), U64(0x25d4eab4d2e2eefe), | ||
169 | U64(0x75068020eefd30ca), U64(0x135a01474acaea61), | ||
170 | U64(0x304e268714fe4ae7), U64(0xa519f17bb283c82c), | ||
171 | U64(0xdc82f6b359cf6416), U64(0x5baf781e7caa11a8), | ||
172 | U64(0xb2c38d64fb26561d), U64(0x34ce5bdf17913eb7), | ||
173 | U64(0x5d6fb56af07c5fd0), U64(0x182713cd0a7f25fd), | ||
174 | U64(0x9e2ac576e6c84d57), U64(0x9aaab82ee5a73907), | ||
175 | U64(0xa3d93c0f3e558654), U64(0x7e7b92aaae48ff56), | ||
176 | U64(0x872d8ead256575be), U64(0x41c8dbfff96c0e7d), | ||
177 | U64(0x99ca5014a3cc1e3b), U64(0x40e883e930be1369), | ||
178 | U64(0x1ca76e95091051ad), U64(0x4e35b42dbab6b5b1), | ||
179 | U64(0x05a0254ecabd6944), U64(0xe1710fca8152af15), | ||
180 | U64(0xf22b0e8dcb984574), U64(0xb763a82a319b3f59), | ||
181 | U64(0x63fca4296e8ab3ef), U64(0x9d4a2d4ca0a36a6b), | ||
182 | U64(0xe331bfe60eeb953d), U64(0xd5bf541596c391a2), | ||
183 | U64(0xf5cb9bef8e9c1618), U64(0x46284e9dbc685d11), | ||
184 | U64(0x2074cffa185f87ba), U64(0xbd3ee2b6b8fcedd1), | ||
185 | U64(0xae64e3f1f23607b0), U64(0xfeb68965ce29d984), | ||
186 | U64(0x55724fdaf6a2b770), U64(0x29496d5cd753720e), | ||
187 | U64(0xa75941573d3af204), U64(0x8e102c0bea69800a), | ||
188 | U64(0x111ab16bc573d049), U64(0xd7ffe439197aab8a), | ||
189 | U64(0xefac380e0b5a09cd), U64(0x48f579593660fbc9), | ||
190 | U64(0x22347fd697e6bd92), U64(0x61bc1405e13389c7), | ||
191 | U64(0x4ab5c975b9d9c1e1), U64(0x80cd1bcf606126d2), | ||
192 | U64(0x7186fd78ed92449a), U64(0x93971a882aabccb3), | ||
193 | U64(0x88d0e17f66bfce72), U64(0x27945a985d5bd4d6) | ||
194 | }, { /* 1 */ | ||
195 | U64(0xde553f8c05a811c8), U64(0x1906b59631b4f565), | ||
196 | U64(0x436e70d6b1964ff7), U64(0x36d343cb8b1e9d85), | ||
197 | U64(0x843dfacc858aab5a), U64(0xfdfc95c299bfc7f9), | ||
198 | U64(0x0f634bdea1d51fa2), U64(0x6d458b3b76efb3cd), | ||
199 | U64(0x85c3f77cf8593f80), U64(0x3c91315fbe737cb2), | ||
200 | U64(0x2148b03366ace398), U64(0x18f8b8264c6761bf), | ||
201 | U64(0xc830c1c495c9fb0f), U64(0x981a76102086a0aa), | ||
202 | U64(0xaa16012142f35760), U64(0x35cc54060c763cf6), | ||
203 | U64(0x42907d66cc45db2d), U64(0x8203d44b965af4bc), | ||
204 | U64(0x3d6f3cefc3a0e868), U64(0xbc73ff69d292bda7), | ||
205 | U64(0x8722ed0102e20a29), U64(0x8f8185e8cd34deb7), | ||
206 | U64(0x9b0561dda7ee01d9), U64(0x5335a0193227fad6), | ||
207 | U64(0xc9cecc74e81a6fd5), U64(0x54f5832e5c2431ea), | ||
208 | U64(0x99e47ba05d553470), U64(0xf7bee756acd226ce), | ||
209 | U64(0x384e05a5571816fd), U64(0xd1367452a47d0e6a), | ||
210 | U64(0xf29fde1c386ad85b), U64(0x320c77316275f7ca), | ||
211 | U64(0xd0c879e2d9ae9ab0), U64(0xdb7406c69110ef5d), | ||
212 | U64(0x45505e51a2461011), U64(0xfc029872e46c5323), | ||
213 | U64(0xfa3cb6f5f7bc0cc5), U64(0x031f17cd8768a173), | ||
214 | U64(0xbd8df2d9af41297d), U64(0x9d3b4f5ab43e5e3f), | ||
215 | U64(0x4071671b36feee84), U64(0x716207e7d3e3b83d), | ||
216 | U64(0x48d20ff2f9283a1a), U64(0x27769eb4757cbc7e), | ||
217 | U64(0x5c56ebc793f2e574), U64(0xa48b474f9ef5dc18), | ||
218 | U64(0x52cbada94ff46e0c), U64(0x60c7da982d8199c6), | ||
219 | U64(0x0e9d466edc068b78), U64(0x4eec2175eaf865fc), | ||
220 | U64(0x550b8e9e21f7a530), U64(0x6b7ba5bc653fec2b), | ||
221 | U64(0x5eb7f1ba6949d0dd), U64(0x57ea94e3db4c9099), | ||
222 | U64(0xf640eae6d101b214), U64(0xdd4a284182c0b0bb), | ||
223 | U64(0xff1d8fbf6304f250), U64(0xb8accb933bf9d7e8), | ||
224 | U64(0xe8867c478eb68c4d), U64(0x3f8e2692391bddc1), | ||
225 | U64(0xcb2fd60912a15a7c), U64(0xaec935dbab983d2f), | ||
226 | U64(0xf55ffd2b56691367), U64(0x80e2ce366ce1c115), | ||
227 | U64(0x179bf3f8edb27e1d), U64(0x01fe0db07dd394da), | ||
228 | U64(0xda8a0b76ecc37b87), U64(0x44ae53e1df9584cb), | ||
229 | U64(0xb310b4b77347a205), U64(0xdfab323c787b8512), | ||
230 | U64(0x3b511268d070b78e), U64(0x65e6e3d2b9396753), | ||
231 | U64(0x6864b271e2574d58), U64(0x259784c98fc789d7), | ||
232 | U64(0x02e11a7dfabb35a9), U64(0x8841a6dfa337158b), | ||
233 | U64(0x7ade78c39b5dcdd0), U64(0xb7cf804d9a2cc84a), | ||
234 | U64(0x20b6bd831b7f7742), U64(0x75bd331d3a88d272), | ||
235 | U64(0x418f6aab4b2d7a5e), U64(0xd9951cbb6babdaf4), | ||
236 | U64(0xb6318dfde7ff5c90), U64(0x1f389b112264aa83), | ||
237 | U64(0x492c024284fbaec0), U64(0xe33a0363c608f9a0), | ||
238 | U64(0x2688930408af28a4), U64(0xc7538a1a341ce4ad), | ||
239 | U64(0x5da8e677ee2171ae), U64(0x8c9e92254a5c7fc4), | ||
240 | U64(0x63d8cd55aae938b5), U64(0x29ebd8daa97a3706), | ||
241 | U64(0x959827b37be88aa1), U64(0x1484e4356adadf6e), | ||
242 | U64(0xa7945082199d7d6b), U64(0xbf6ce8a455fa1cd4), | ||
243 | U64(0x9cc542eac9edcae5), U64(0x79c16f0e1c356ca3), | ||
244 | U64(0x89bfab6fdee48151), U64(0xd4174d1830c5f0ff), | ||
245 | U64(0x9258048415eb419d), U64(0x6139d72850520d1c), | ||
246 | U64(0x6a85a80c18ec78f1), U64(0xcd11f88e0171059a), | ||
247 | U64(0xcceff53e7ca29140), U64(0xd229639f2315af19), | ||
248 | U64(0x90b91ef9ef507434), U64(0x5977d28d074a1be1), | ||
249 | U64(0x311360fce51d56b9), U64(0xc093a92d5a1f2f91), | ||
250 | U64(0x1a19a25bb6dc5416), U64(0xeb996b8a09de2d3e), | ||
251 | U64(0xfee3820f1ed7668a), U64(0xd7085ad5b7ad518c), | ||
252 | U64(0x7fff41890fe53345), U64(0xec5948bd67dde602), | ||
253 | U64(0x2fd5f65dbaaa68e0), U64(0xa5754affe32648c2), | ||
254 | U64(0xf8ddac880d07396c), U64(0x6fa491468c548664), | ||
255 | U64(0x0c7c5c1326bdbed1), U64(0x4a33158f03930fb3), | ||
256 | U64(0x699abfc19f84d982), U64(0xe4fa2054a80b329c), | ||
257 | U64(0x6707f9af438252fa), U64(0x08a368e9cfd6d49e), | ||
258 | U64(0x47b1442c58fd25b8), U64(0xbbb3dc5ebc91769b), | ||
259 | U64(0x1665fe489061eac7), U64(0x33f27a811fa66310), | ||
260 | U64(0x93a609346838d547), U64(0x30ed6d4c98cec263), | ||
261 | U64(0x1dd9816cd8df9f2a), U64(0x94662a03063b1e7b), | ||
262 | U64(0x83fdd9fbeb896066), U64(0x7b207573e68e590a), | ||
263 | U64(0x5f49fc0a149a4407), U64(0x343259b671a5a82c), | ||
264 | U64(0xfbc2bb458a6f981f), U64(0xc272b350a0a41a38), | ||
265 | U64(0x3aaf1fd8ada32354), U64(0x6cbb868b0b3c2717), | ||
266 | U64(0xa2b569c88d2583fe), U64(0xf180c9d1bf027928), | ||
267 | U64(0xaf37386bd64ba9f5), U64(0x12bacab2790a8088), | ||
268 | U64(0x4c0d3b0810435055), U64(0xb2eeb9070e9436df), | ||
269 | U64(0xc5b29067cea7d104), U64(0xdcb425f1ff132461), | ||
270 | U64(0x4f122cc5972bf126), U64(0xac282fa651230886), | ||
271 | U64(0xe7e537992f6393ef), U64(0xe61b3a2952b00735), | ||
272 | U64(0x709c0a57ae302ce7), U64(0xe02514ae416058d3), | ||
273 | U64(0xc44c9dd7b37445de), U64(0x5a68c5408022ba92), | ||
274 | U64(0x1c278cdca50c0bf0), U64(0x6e5a9cf6f18712be), | ||
275 | U64(0x86dce0b17f319ef3), U64(0x2d34ec2040115d49), | ||
276 | U64(0x4bcd183f7e409b69), U64(0x2815d56ad4a9a3dc), | ||
277 | U64(0x24698979f2141d0d), U64(0x0000000000000000), | ||
278 | U64(0x1ec696a15fb73e59), U64(0xd86b110b16784e2e), | ||
279 | U64(0x8e7f8858b0e74a6d), U64(0x063e2e8713d05fe6), | ||
280 | U64(0xe2c40ed3bbdb6d7a), U64(0xb1f1aeca89fc97ac), | ||
281 | U64(0xe1db191e3cb3cc09), U64(0x6418ee62c4eaf389), | ||
282 | U64(0xc6ad87aa49cf7077), U64(0xd6f65765ca7ec556), | ||
283 | U64(0x9afb6c6dda3d9503), U64(0x7ce05644888d9236), | ||
284 | U64(0x8d609f95378feb1e), U64(0x23a9aa4e9c17d631), | ||
285 | U64(0x6226c0e5d73aac6f), U64(0x56149953a69f0443), | ||
286 | U64(0xeeb852c09d66d3ab), U64(0x2b0ac2a753c102af), | ||
287 | U64(0x07c023376e03cb3c), U64(0x2ccae1903dc2c993), | ||
288 | U64(0xd3d76e2f5ec63bc3), U64(0x9e2458973356ff4c), | ||
289 | U64(0xa66a5d32644ee9b1), U64(0x0a427294356de137), | ||
290 | U64(0x783f62be61e6f879), U64(0x1344c70204d91452), | ||
291 | U64(0x5b96c8f0fdf12e48), U64(0xa90916ecc59bf613), | ||
292 | U64(0xbe92e5142829880e), U64(0x727d102a548b194e), | ||
293 | U64(0x1be7afebcb0fc0cc), U64(0x3e702b2244c8491b), | ||
294 | U64(0xd5e940a84d166425), U64(0x66f9f41f3e51c620), | ||
295 | U64(0xabe80c913f20c3ba), U64(0xf07ec461c2d1edf2), | ||
296 | U64(0xf361d3ac45b94c81), U64(0x0521394a94b8fe95), | ||
297 | U64(0xadd622162cf09c5c), U64(0xe97871f7f3651897), | ||
298 | U64(0xf4a1f09b2bba87bd), U64(0x095d6559b2054044), | ||
299 | U64(0x0bbc7f2448be75ed), U64(0x2af4cf172e129675), | ||
300 | U64(0x157ae98517094bb4), U64(0x9fda55274e856b96), | ||
301 | U64(0x914713499283e0ee), U64(0xb952c623462a4332), | ||
302 | U64(0x74433ead475b46a8), U64(0x8b5eb112245fb4f8), | ||
303 | U64(0xa34b6478f0f61724), U64(0x11a5dd7ffe6221fb), | ||
304 | U64(0xc16da49d27ccbb4b), U64(0x76a224d0bde07301), | ||
305 | U64(0x8aa0bca2598c2022), U64(0x4df336b86d90c48f), | ||
306 | U64(0xea67663a740db9e4), U64(0xef465f70e0b54771), | ||
307 | U64(0x39b008152acb8227), U64(0x7d1e5bf4f55e06ec), | ||
308 | U64(0x105bd0cf83b1b521), U64(0x775c2960c033e7db), | ||
309 | U64(0x7e014c397236a79f), U64(0x811cc386113255cf), | ||
310 | U64(0xeda7450d1a0e72d8), U64(0x5889df3d7a998f3b), | ||
311 | U64(0x2e2bfbedc779fc3a), U64(0xce0eef438619a4e9), | ||
312 | U64(0x372d4e7bf6cd095f), U64(0x04df34fae96b6a4f), | ||
313 | U64(0xf923a13870d4adb6), U64(0xa1aa7e050a4d228d), | ||
314 | U64(0xa8f71b5cb84862c9), U64(0xb52e9a306097fde3), | ||
315 | U64(0x0d8251a35b6e2a0b), U64(0x2257a7fee1c442eb), | ||
316 | U64(0x73831d9a29588d94), U64(0x51d4ba64c89ccf7f), | ||
317 | U64(0x502ab7d4b54f5ba5), U64(0x97793dce8153bf08), | ||
318 | U64(0xe5042de4d5d8a646), U64(0x9687307efc802bd2), | ||
319 | U64(0xa05473b5779eb657), U64(0xb4d097801d446939), | ||
320 | U64(0xcff0e2f3fbca3033), U64(0xc38cbee0dd778ee2), | ||
321 | U64(0x464f499c252eb162), U64(0xcad1dbb96f72cea6), | ||
322 | U64(0xba4dd1eec142e241), U64(0xb00fa37af42f0376) | ||
323 | }, { /* 2 */ | ||
324 | U64(0xcce4cd3aa968b245), U64(0x089d5484e80b7faf), | ||
325 | U64(0x638246c1b3548304), U64(0xd2fe0ec8c2355492), | ||
326 | U64(0xa7fbdf7ff2374eee), U64(0x4df1600c92337a16), | ||
327 | U64(0x84e503ea523b12fb), U64(0x0790bbfd53ab0c4a), | ||
328 | U64(0x198a780f38f6ea9d), U64(0x2ab30c8f55ec48cb), | ||
329 | U64(0xe0f7fed6b2c49db5), U64(0xb6ecf3f422cadbdc), | ||
330 | U64(0x409c9a541358df11), U64(0xd3ce8a56dfde3fe3), | ||
331 | U64(0xc3e9224312c8c1a0), U64(0x0d6dfa58816ba507), | ||
332 | U64(0xddf3e1b179952777), U64(0x04c02a42748bb1d9), | ||
333 | U64(0x94c2abff9f2decb8), U64(0x4f91752da8f8acf4), | ||
334 | U64(0x78682befb169bf7b), U64(0xe1c77a48af2ff6c4), | ||
335 | U64(0x0c5d7ec69c80ce76), U64(0x4cc1e4928fd81167), | ||
336 | U64(0xfeed3d24d9997b62), U64(0x518bb6dfc3a54a23), | ||
337 | U64(0x6dbf2d26151f9b90), U64(0xb5bc624b05ea664f), | ||
338 | U64(0xe86aaa525acfe21a), U64(0x4801ced0fb53a0be), | ||
339 | U64(0xc91463e6c00868ed), U64(0x1027a815cd16fe43), | ||
340 | U64(0xf67069a0319204cd), U64(0xb04ccc976c8abce7), | ||
341 | U64(0xc0b9b3fc35e87c33), U64(0xf380c77c58f2de65), | ||
342 | U64(0x50bb3241de4e2152), U64(0xdf93f490435ef195), | ||
343 | U64(0xf1e0d25d62390887), U64(0xaf668bfb1a3c3141), | ||
344 | U64(0xbc11b251f00a7291), U64(0x73a5eed47e427d47), | ||
345 | U64(0x25bee3f6ee4c3b2e), U64(0x43cc0beb34786282), | ||
346 | U64(0xc824e778dde3039c), U64(0xf97d86d98a327728), | ||
347 | U64(0xf2b043e24519b514), U64(0xe297ebf7880f4b57), | ||
348 | U64(0x3a94a49a98fab688), U64(0x868516cb68f0c419), | ||
349 | U64(0xeffa11af0964ee50), U64(0xa4ab4ec0d517f37d), | ||
350 | U64(0xa9c6b498547c567a), U64(0x8e18424f80fbbbb6), | ||
351 | U64(0x0bcdc53bcf2bc23c), U64(0x137739aaea3643d0), | ||
352 | U64(0x2c1333ec1bac2ff0), U64(0x8d48d3f0a7db0625), | ||
353 | U64(0x1e1ac3f26b5de6d7), U64(0xf520f81f16b2b95e), | ||
354 | U64(0x9f0f6ec450062e84), U64(0x0130849e1deb6b71), | ||
355 | U64(0xd45e31ab8c7533a9), U64(0x652279a2fd14e43f), | ||
356 | U64(0x3209f01e70f1c927), U64(0xbe71a770cac1a473), | ||
357 | U64(0x0e3d6be7a64b1894), U64(0x7ec8148cff29d840), | ||
358 | U64(0xcb7476c7fac3be0f), U64(0x72956a4a63a91636), | ||
359 | U64(0x37f95ec21991138f), U64(0x9e3fea5a4ded45f5), | ||
360 | U64(0x7b38ba50964902e8), U64(0x222e580bbde73764), | ||
361 | U64(0x61e253e0899f55e6), U64(0xfc8d2805e352ad80), | ||
362 | U64(0x35994be3235ac56d), U64(0x09add01af5e014de), | ||
363 | U64(0x5e8659a6780539c6), U64(0xb17c48097161d796), | ||
364 | U64(0x026015213acbd6e2), U64(0xd1ae9f77e515e901), | ||
365 | U64(0xb7dc776a3f21b0ad), U64(0xaba6a1b96eb78098), | ||
366 | U64(0x9bcf4486248d9f5d), U64(0x582666c536455efd), | ||
367 | U64(0xfdbdac9bfeb9c6f1), U64(0xc47999be4163cdea), | ||
368 | U64(0x765540081722a7ef), U64(0x3e548ed8ec710751), | ||
369 | U64(0x3d041f67cb51bac2), U64(0x7958af71ac82d40a), | ||
370 | U64(0x36c9da5c047a78fe), U64(0xed9a048e33af38b2), | ||
371 | U64(0x26ee7249c96c86bd), U64(0x900281bdeba65d61), | ||
372 | U64(0x11172c8bd0fd9532), U64(0xea0abf73600434f8), | ||
373 | U64(0x42fc8f75299309f3), U64(0x34a9cf7d3eb1ae1c), | ||
374 | U64(0x2b838811480723ba), U64(0x5ce64c8742ceef24), | ||
375 | U64(0x1adae9b01fd6570e), U64(0x3c349bf9d6bad1b3), | ||
376 | U64(0x82453c891c7b75c0), U64(0x97923a40b80d512b), | ||
377 | U64(0x4a61dbf1c198765c), U64(0xb48ce6d518010d3e), | ||
378 | U64(0xcfb45c858e480fd6), U64(0xd933cbf30d1e96ae), | ||
379 | U64(0xd70ea014ab558e3a), U64(0xc189376228031742), | ||
380 | U64(0x9262949cd16d8b83), U64(0xeb3a3bed7def5f89), | ||
381 | U64(0x49314a4ee6b8cbcf), U64(0xdcc3652f647e4c06), | ||
382 | U64(0xda635a4c2a3e2b3d), U64(0x470c21a940f3d35b), | ||
383 | U64(0x315961a157d174b4), U64(0x6672e81dda3459ac), | ||
384 | U64(0x5b76f77a1165e36e), U64(0x445cb01667d36ec8), | ||
385 | U64(0xc5491d205c88a69b), U64(0x456c34887a3805b9), | ||
386 | U64(0xffddb9bac4721013), U64(0x99af51a71e4649bf), | ||
387 | U64(0xa15be01cbc7729d5), U64(0x52db2760e485f7b0), | ||
388 | U64(0x8c78576eba306d54), U64(0xae560f6507d75a30), | ||
389 | U64(0x95f22f6182c687c9), U64(0x71c5fbf54489aba5), | ||
390 | U64(0xca44f259e728d57e), U64(0x88b87d2ccebbdc8d), | ||
391 | U64(0xbab18d32be4a15aa), U64(0x8be8ec93e99b611e), | ||
392 | U64(0x17b713e89ebdf209), U64(0xb31c5d284baa0174), | ||
393 | U64(0xeeca9531148f8521), U64(0xb8d198138481c348), | ||
394 | U64(0x8988f9b2d350b7fc), U64(0xb9e11c8d996aa839), | ||
395 | U64(0x5a4673e40c8e881f), U64(0x1687977683569978), | ||
396 | U64(0xbf4123eed72acf02), U64(0x4ea1f1b3b513c785), | ||
397 | U64(0xe767452be16f91ff), U64(0x7505d1b730021a7c), | ||
398 | U64(0xa59bca5ec8fc980c), U64(0xad069eda20f7e7a3), | ||
399 | U64(0x38f4b1bba231606a), U64(0x60d2d77e94743e97), | ||
400 | U64(0x9affc0183966f42c), U64(0x248e6768f3a7505f), | ||
401 | U64(0xcdd449a4b483d934), U64(0x87b59255751baf68), | ||
402 | U64(0x1bea6d2e023d3c7f), U64(0x6b1f12455b5ffcab), | ||
403 | U64(0x743555292de9710d), U64(0xd8034f6d10f5fddf), | ||
404 | U64(0xc6198c9f7ba81b08), U64(0xbb8109aca3a17edb), | ||
405 | U64(0xfa2d1766ad12cabb), U64(0xc729080166437079), | ||
406 | U64(0x9c5fff7b77269317), U64(0x0000000000000000), | ||
407 | U64(0x15d706c9a47624eb), U64(0x6fdf38072fd44d72), | ||
408 | U64(0x5fb6dd3865ee52b7), U64(0xa33bf53d86bcff37), | ||
409 | U64(0xe657c1b5fc84fa8e), U64(0xaa962527735cebe9), | ||
410 | U64(0x39c43525bfda0b1b), U64(0x204e4d2a872ce186), | ||
411 | U64(0x7a083ece8ba26999), U64(0x554b9c9db72efbfa), | ||
412 | U64(0xb22cd9b656416a05), U64(0x96a2bedea5e63a5a), | ||
413 | U64(0x802529a826b0a322), U64(0x8115ad363b5bc853), | ||
414 | U64(0x8375b81701901eb1), U64(0x3069e53f4a3a1fc5), | ||
415 | U64(0xbd2136cfede119e0), U64(0x18bafc91251d81ec), | ||
416 | U64(0x1d4a524d4c7d5b44), U64(0x05f0aedc6960daa8), | ||
417 | U64(0x29e39d3072ccf558), U64(0x70f57f6b5962c0d4), | ||
418 | U64(0x989fd53903ad22ce), U64(0xf84d024797d91c59), | ||
419 | U64(0x547b1803aac5908b), U64(0xf0d056c37fd263f6), | ||
420 | U64(0xd56eb535919e58d8), U64(0x1c7ad6d351963035), | ||
421 | U64(0x2e7326cd2167f912), U64(0xac361a443d1c8cd2), | ||
422 | U64(0x697f076461942a49), U64(0x4b515f6fdc731d2d), | ||
423 | U64(0x8ad8680df4700a6f), U64(0x41ac1eca0eb3b460), | ||
424 | U64(0x7d988533d80965d3), U64(0xa8f6300649973d0b), | ||
425 | U64(0x7765c4960ac9cc9e), U64(0x7ca801adc5e20ea2), | ||
426 | U64(0xdea3700e5eb59ae4), U64(0xa06b6482a19c42a4), | ||
427 | U64(0x6a2f96db46b497da), U64(0x27def6d7d487edcc), | ||
428 | U64(0x463ca5375d18b82a), U64(0xa6cb5be1efdc259f), | ||
429 | U64(0x53eba3fef96e9cc1), U64(0xce84d81b93a364a7), | ||
430 | U64(0xf4107c810b59d22f), U64(0x333974806d1aa256), | ||
431 | U64(0x0f0def79bba073e5), U64(0x231edc95a00c5c15), | ||
432 | U64(0xe437d494c64f2c6c), U64(0x91320523f64d3610), | ||
433 | U64(0x67426c83c7df32dd), U64(0x6eefbc99323f2603), | ||
434 | U64(0x9d6f7be56acdf866), U64(0x5916e25b2bae358c), | ||
435 | U64(0x7ff89012e2c2b331), U64(0x035091bf2720bd93), | ||
436 | U64(0x561b0d22900e4669), U64(0x28d319ae6f279e29), | ||
437 | U64(0x2f43a2533c8c9263), U64(0xd09e1be9f8fe8270), | ||
438 | U64(0xf740ed3e2c796fbc), U64(0xdb53ded237d5404c), | ||
439 | U64(0x62b2c25faebfe875), U64(0x0afd41a5d2c0a94d), | ||
440 | U64(0x6412fd3ce0ff8f4e), U64(0xe3a76f6995e42026), | ||
441 | U64(0x6c8fa9b808f4f0e1), U64(0xc2d9a6dd0f23aad1), | ||
442 | U64(0x8f28c6d19d10d0c7), U64(0x85d587744fd0798a), | ||
443 | U64(0xa20b71a39b579446), U64(0x684f83fa7c7f4138), | ||
444 | U64(0xe507500adba4471d), U64(0x3f640a46f19a6c20), | ||
445 | U64(0x1247bd34f7dd28a1), U64(0x2d23b77206474481), | ||
446 | U64(0x93521002cc86e0f2), U64(0x572b89bc8de52d18), | ||
447 | U64(0xfb1d93f8b0f9a1ca), U64(0xe95a2ecc4724896b), | ||
448 | U64(0x3ba420048511ddf9), U64(0xd63e248ab6bee54b), | ||
449 | U64(0x5dd6c8195f258455), U64(0x06a03f634e40673b), | ||
450 | U64(0x1f2a476c76b68da6), U64(0x217ec9b49ac78af7), | ||
451 | U64(0xecaa80102e4453c3), U64(0x14e78257b99d4f9a) | ||
452 | }, { /* 3 */ | ||
453 | U64(0x20329b2cc87bba05), U64(0x4f5eb6f86546a531), | ||
454 | U64(0xd4f44775f751b6b1), U64(0x8266a47b850dfa8b), | ||
455 | U64(0xbb986aa15a6ca985), U64(0xc979eb08f9ae0f99), | ||
456 | U64(0x2da6f447a2375ea1), U64(0x1e74275dcd7d8576), | ||
457 | U64(0xbc20180a800bc5f8), U64(0xb4a2f701b2dc65be), | ||
458 | U64(0xe726946f981b6d66), U64(0x48e6c453bf21c94c), | ||
459 | U64(0x42cad9930f0a4195), U64(0xefa47b64aacccd20), | ||
460 | U64(0x71180a8960409a42), U64(0x8bb3329bf6a44e0c), | ||
461 | U64(0xd34c35de2d36dacc), U64(0xa92f5b7cbc23dc96), | ||
462 | U64(0xb31a85aa68bb09c3), U64(0x13e04836a73161d2), | ||
463 | U64(0xb24dfc4129c51d02), U64(0x8ae44b70b7da5acd), | ||
464 | U64(0xe671ed84d96579a7), U64(0xa4bb3417d66f3832), | ||
465 | U64(0x4572ab38d56d2de8), U64(0xb1b47761ea47215c), | ||
466 | U64(0xe81c09cf70aba15d), U64(0xffbdb872ce7f90ac), | ||
467 | U64(0xa8782297fd5dc857), U64(0x0d946f6b6a4ce4a4), | ||
468 | U64(0xe4df1f4f5b995138), U64(0x9ebc71edca8c5762), | ||
469 | U64(0x0a2c1dc0b02b88d9), U64(0x3b503c115d9d7b91), | ||
470 | U64(0xc64376a8111ec3a2), U64(0xcec199a323c963e4), | ||
471 | U64(0xdc76a87ec58616f7), U64(0x09d596e073a9b487), | ||
472 | U64(0x14583a9d7d560daf), U64(0xf4c6dc593f2a0cb4), | ||
473 | U64(0xdd21d19584f80236), U64(0x4a4836983ddde1d3), | ||
474 | U64(0xe58866a41ae745f9), U64(0xf591a5b27e541875), | ||
475 | U64(0x891dc05074586693), U64(0x5b068c651810a89e), | ||
476 | U64(0xa30346bc0c08544f), U64(0x3dbf3751c684032d), | ||
477 | U64(0x2a1e86ec785032dc), U64(0xf73f5779fca830ea), | ||
478 | U64(0xb60c05ca30204d21), U64(0x0cc316802b32f065), | ||
479 | U64(0x8770241bdd96be69), U64(0xb861e18199ee95db), | ||
480 | U64(0xf805cad91418fcd1), U64(0x29e70dccbbd20e82), | ||
481 | U64(0xc7140f435060d763), U64(0x0f3a9da0e8b0cc3b), | ||
482 | U64(0xa2543f574d76408e), U64(0xbd7761e1c175d139), | ||
483 | U64(0x4b1f4f737ca3f512), U64(0x6dc2df1f2fc137ab), | ||
484 | U64(0xf1d05c3967b14856), U64(0xa742bf3715ed046c), | ||
485 | U64(0x654030141d1697ed), U64(0x07b872abda676c7d), | ||
486 | U64(0x3ce84eba87fa17ec), U64(0xc1fb0403cb79afdf), | ||
487 | U64(0x3e46bc7105063f73), U64(0x278ae987121cd678), | ||
488 | U64(0xa1adb4778ef47cd0), U64(0x26dd906c5362c2b9), | ||
489 | U64(0x05168060589b44e2), U64(0xfbfc41f9d79ac08f), | ||
490 | U64(0x0e6de44ba9ced8fa), U64(0x9feb08068bf243a3), | ||
491 | U64(0x7b341749d06b129b), U64(0x229c69e74a87929a), | ||
492 | U64(0xe09ee6c4427c011b), U64(0x5692e30e725c4c3a), | ||
493 | U64(0xda99a33e5e9f6e4b), U64(0x353dd85af453a36b), | ||
494 | U64(0x25241b4c90e0fee7), U64(0x5de987258309d022), | ||
495 | U64(0xe230140fc0802984), U64(0x93281e86a0c0b3c6), | ||
496 | U64(0xf229d719a4337408), U64(0x6f6c2dd4ad3d1f34), | ||
497 | U64(0x8ea5b2fbae3f0aee), U64(0x8331dd90c473ee4a), | ||
498 | U64(0x346aa1b1b52db7aa), U64(0xdf8f235e06042aa9), | ||
499 | U64(0xcc6f6b68a1354b7b), U64(0x6c95a6f46ebf236a), | ||
500 | U64(0x52d31a856bb91c19), U64(0x1a35ded6d498d555), | ||
501 | U64(0xf37eaef2e54d60c9), U64(0x72e181a9a3c2a61c), | ||
502 | U64(0x98537aad51952fde), U64(0x16f6c856ffaa2530), | ||
503 | U64(0xd960281e9d1d5215), U64(0x3a0745fa1ce36f50), | ||
504 | U64(0x0b7b642bf1559c18), U64(0x59a87eae9aec8001), | ||
505 | U64(0x5e100c05408bec7c), U64(0x0441f98b19e55023), | ||
506 | U64(0xd70dcc5534d38aef), U64(0x927f676de1bea707), | ||
507 | U64(0x9769e70db925e3e5), U64(0x7a636ea29115065a), | ||
508 | U64(0x468b201816ef11b6), U64(0xab81a9b73edff409), | ||
509 | U64(0xc0ac7de88a07bb1e), U64(0x1f235eb68c0391b7), | ||
510 | U64(0x6056b074458dd30f), U64(0xbe8eeac102f7ed67), | ||
511 | U64(0xcd381283e04b5fba), U64(0x5cbefecec277c4e3), | ||
512 | U64(0xd21b4c356c48ce0d), U64(0x1019c31664b35d8c), | ||
513 | U64(0x247362a7d19eea26), U64(0xebe582efb3299d03), | ||
514 | U64(0x02aef2cb82fc289f), U64(0x86275df09ce8aaa8), | ||
515 | U64(0x28b07427faac1a43), U64(0x38a9b7319e1f47cf), | ||
516 | U64(0xc82e92e3b8d01b58), U64(0x06ef0b409b1978bc), | ||
517 | U64(0x62f842bfc771fb90), U64(0x9904034610eb3b1f), | ||
518 | U64(0xded85ab5477a3e68), U64(0x90d195a663428f98), | ||
519 | U64(0x5384636e2ac708d8), U64(0xcbd719c37b522706), | ||
520 | U64(0xae9729d76644b0eb), U64(0x7c8c65e20a0c7ee6), | ||
521 | U64(0x80c856b007f1d214), U64(0x8c0b40302cc32271), | ||
522 | U64(0xdbcedad51fe17a8a), U64(0x740e8ae938dbdea0), | ||
523 | U64(0xa615c6dc549310ad), U64(0x19cc55f6171ae90b), | ||
524 | U64(0x49b1bdb8fe5fdd8d), U64(0xed0a89af2830e5bf), | ||
525 | U64(0x6a7aadb4f5a65bd6), U64(0x7e22972988f05679), | ||
526 | U64(0xf952b3325566e810), U64(0x39fecedadf61530e), | ||
527 | U64(0x6101c99f04f3c7ce), U64(0x2e5f7f6761b562ff), | ||
528 | U64(0xf08725d226cf5c97), U64(0x63af3b54860fef51), | ||
529 | U64(0x8ff2cb10ef411e2f), U64(0x884ab9bb35267252), | ||
530 | U64(0x4df04433e7ba8dae), U64(0x9afd8866d3690741), | ||
531 | U64(0x66b9bb34de94abb3), U64(0x9baaf18d92171380), | ||
532 | U64(0x543c11c5f0a064a5), U64(0x17a1b1bdbed431f1), | ||
533 | U64(0xb5f58eeaf3a2717f), U64(0xc355f6c849858740), | ||
534 | U64(0xec5df044694ef17e), U64(0xd83751f5dc6346d4), | ||
535 | U64(0xfc4433520dfdacf2), U64(0x0000000000000000), | ||
536 | U64(0x5a51f58e596ebc5f), U64(0x3285aaf12e34cf16), | ||
537 | U64(0x8d5c39db6dbd36b0), U64(0x12b731dde64f7513), | ||
538 | U64(0x94906c2d7aa7dfbb), U64(0x302b583aacc8e789), | ||
539 | U64(0x9d45facd090e6b3c), U64(0x2165e2c78905aec4), | ||
540 | U64(0x68d45f7f775a7349), U64(0x189b2c1d5664fdca), | ||
541 | U64(0xe1c99f2f030215da), U64(0x6983269436246788), | ||
542 | U64(0x8489af3b1e148237), U64(0xe94b702431d5b59c), | ||
543 | U64(0x33d2d31a6f4adbd7), U64(0xbfd9932a4389f9a6), | ||
544 | U64(0xb0e30e8aab39359d), U64(0xd1e2c715afcaf253), | ||
545 | U64(0x150f43763c28196e), U64(0xc4ed846393e2eb3d), | ||
546 | U64(0x03f98b20c3823c5e), U64(0xfd134ab94c83b833), | ||
547 | U64(0x556b682eb1de7064), U64(0x36c4537a37d19f35), | ||
548 | U64(0x7559f30279a5ca61), U64(0x799ae58252973a04), | ||
549 | U64(0x9c12832648707ffd), U64(0x78cd9c6913e92ec5), | ||
550 | U64(0x1d8dac7d0effb928), U64(0x439da0784e745554), | ||
551 | U64(0x413352b3cc887dcb), U64(0xbacf134a1b12bd44), | ||
552 | U64(0x114ebafd25cd494d), U64(0x2f08068c20cb763e), | ||
553 | U64(0x76a07822ba27f63f), U64(0xeab2fb04f25789c2), | ||
554 | U64(0xe3676de481fe3d45), U64(0x1b62a73d95e6c194), | ||
555 | U64(0x641749ff5c68832c), U64(0xa5ec4dfc97112cf3), | ||
556 | U64(0xf6682e92bdd6242b), U64(0x3f11c59a44782bb2), | ||
557 | U64(0x317c21d1edb6f348), U64(0xd65ab5be75ad9e2e), | ||
558 | U64(0x6b2dd45fb4d84f17), U64(0xfaab381296e4d44e), | ||
559 | U64(0xd0b5befeeeb4e692), U64(0x0882ef0b32d7a046), | ||
560 | U64(0x512a91a5a83b2047), U64(0x963e9ee6f85bf724), | ||
561 | U64(0x4e09cf132438b1f0), U64(0x77f701c9fb59e2fe), | ||
562 | U64(0x7ddb1c094b726a27), U64(0x5f4775ee01f5f8bd), | ||
563 | U64(0x9186ec4d223c9b59), U64(0xfeeac1998f01846d), | ||
564 | U64(0xac39db1ce4b89874), U64(0xb75b7c21715e59e0), | ||
565 | U64(0xafc0503c273aa42a), U64(0x6e3b543fec430bf5), | ||
566 | U64(0x704f7362213e8e83), U64(0x58ff0745db9294c0), | ||
567 | U64(0x67eec2df9feabf72), U64(0xa0facd9ccf8a6811), | ||
568 | U64(0xb936986ad890811a), U64(0x95c715c63bd9cb7a), | ||
569 | U64(0xca8060283a2c33c7), U64(0x507de84ee9453486), | ||
570 | U64(0x85ded6d05f6a96f6), U64(0x1cdad5964f81ade9), | ||
571 | U64(0xd5a33e9eb62fa270), U64(0x40642b588df6690a), | ||
572 | U64(0x7f75eec2c98e42b8), U64(0x2cf18dace3494a60), | ||
573 | U64(0x23cb100c0bf9865b), U64(0xeef3028febb2d9e1), | ||
574 | U64(0x4425d2d394133929), U64(0xaad6d05c7fa1e0c8), | ||
575 | U64(0xad6ea2f7a5c68cb5), U64(0xc2028f2308fb9381), | ||
576 | U64(0x819f2f5b468fc6d5), U64(0xc5bafd88d29cfffc), | ||
577 | U64(0x47dc59f357910577), U64(0x2b49ff07392e261d), | ||
578 | U64(0x57c59ae5332258fb), U64(0x73b6f842e2bcb2dd), | ||
579 | U64(0xcf96e04862b77725), U64(0x4ca73dd8a6c4996f), | ||
580 | U64(0x015779eb417e14c1), U64(0x37932a9176af8bf4) | ||
581 | }, { /* 4 */ | ||
582 | U64(0x190a2c9b249df23e), U64(0x2f62f8b62263e1e9), | ||
583 | U64(0x7a7f754740993655), U64(0x330b7ba4d5564d9f), | ||
584 | U64(0x4c17a16a46672582), U64(0xb22f08eb7d05f5b8), | ||
585 | U64(0x535f47f40bc148cc), U64(0x3aec5d27d4883037), | ||
586 | U64(0x10ed0a1825438f96), U64(0x516101f72c233d17), | ||
587 | U64(0x13cc6f949fd04eae), U64(0x739853c441474bfd), | ||
588 | U64(0x653793d90d3f5b1b), U64(0x5240647b96b0fc2f), | ||
589 | U64(0x0c84890ad27623e0), U64(0xd7189b32703aaea3), | ||
590 | U64(0x2685de3523bd9c41), U64(0x99317c5b11bffefa), | ||
591 | U64(0x0d9baa854f079703), U64(0x70b93648fbd48ac5), | ||
592 | U64(0xa80441fce30bc6be), U64(0x7287704bdc36ff1e), | ||
593 | U64(0xb65384ed33dc1f13), U64(0xd36417343ee34408), | ||
594 | U64(0x39cd38ab6e1bf10f), U64(0x5ab861770a1f3564), | ||
595 | U64(0x0ebacf09f594563b), U64(0xd04572b884708530), | ||
596 | U64(0x3cae9722bdb3af47), U64(0x4a556b6f2f5cbaf2), | ||
597 | U64(0xe1704f1f76c4bd74), U64(0x5ec4ed7144c6dfcf), | ||
598 | U64(0x16afc01d4c7810e6), U64(0x283f113cd629ca7a), | ||
599 | U64(0xaf59a8761741ed2d), U64(0xeed5a3991e215fac), | ||
600 | U64(0x3bf37ea849f984d4), U64(0xe413e096a56ce33c), | ||
601 | U64(0x2c439d3a98f020d1), U64(0x637559dc6404c46b), | ||
602 | U64(0x9e6c95d1e5f5d569), U64(0x24bb9836045fe99a), | ||
603 | U64(0x44efa466dac8ecc9), U64(0xc6eab2a5c80895d6), | ||
604 | U64(0x803b50c035220cc4), U64(0x0321658cba93c138), | ||
605 | U64(0x8f9ebc465dc7ee1c), U64(0xd15a5137190131d3), | ||
606 | U64(0x0fa5ec8668e5e2d8), U64(0x91c979578d1037b1), | ||
607 | U64(0x0642ca05693b9f70), U64(0xefca80168350eb4f), | ||
608 | U64(0x38d21b24f36a45ec), U64(0xbeab81e1af73d658), | ||
609 | U64(0x8cbfd9cae7542f24), U64(0xfd19cc0d81f11102), | ||
610 | U64(0x0ac6430fbb4dbc90), U64(0x1d76a09d6a441895), | ||
611 | U64(0x2a01573ff1cbbfa1), U64(0xb572e161894fde2b), | ||
612 | U64(0x8124734fa853b827), U64(0x614b1fdf43e6b1b0), | ||
613 | U64(0x68ac395c4238cc18), U64(0x21d837bfd7f7b7d2), | ||
614 | U64(0x20c714304a860331), U64(0x5cfaab726324aa14), | ||
615 | U64(0x74c5ba4eb50d606e), U64(0xf3a3030474654739), | ||
616 | U64(0x23e671bcf015c209), U64(0x45f087e947b9582a), | ||
617 | U64(0xd8bd77b418df4c7b), U64(0xe06f6c90ebb50997), | ||
618 | U64(0x0bd96080263c0873), U64(0x7e03f9410e40dcfe), | ||
619 | U64(0xb8e94be4c6484928), U64(0xfb5b0608e8ca8e72), | ||
620 | U64(0x1a2b49179e0e3306), U64(0x4e29e76961855059), | ||
621 | U64(0x4f36c4e6fcf4e4ba), U64(0x49740ee395cf7bca), | ||
622 | U64(0xc2963ea386d17f7d), U64(0x90d65ad810618352), | ||
623 | U64(0x12d34c1b02a1fa4d), U64(0xfa44258775bb3a91), | ||
624 | U64(0x18150f14b9ec46dd), U64(0x1491861e6b9a653d), | ||
625 | U64(0x9a1019d7ab2c3fc2), U64(0x3668d42d06fe13d7), | ||
626 | U64(0xdcc1fbb25606a6d0), U64(0x969490dd795a1c22), | ||
627 | U64(0x3549b1a1bc6dd2ef), U64(0xc94f5e23a0ed770e), | ||
628 | U64(0xb9f6686b5b39fdcb), U64(0xc4d4f4a6efeae00d), | ||
629 | U64(0xe732851a1fff2204), U64(0x94aad6de5eb869f9), | ||
630 | U64(0x3f8ff2ae07206e7f), U64(0xfe38a9813b62d03a), | ||
631 | U64(0xa7a1ad7a8bee2466), U64(0x7b6056c8dde882b6), | ||
632 | U64(0x302a1e286fc58ca7), U64(0x8da0fa457a259bc7), | ||
633 | U64(0xb3302b64e074415b), U64(0x5402ae7eff8b635f), | ||
634 | U64(0x08f8050c9cafc94b), U64(0xae468bf98a3059ce), | ||
635 | U64(0x88c355cca98dc58f), U64(0xb10e6d67c7963480), | ||
636 | U64(0xbad70de7e1aa3cf3), U64(0xbfb4a26e320262bb), | ||
637 | U64(0xcb711820870f02d5), U64(0xce12b7a954a75c9d), | ||
638 | U64(0x563ce87dd8691684), U64(0x9f73b65e7884618a), | ||
639 | U64(0x2b1e74b06cba0b42), U64(0x47cec1ea605b2df1), | ||
640 | U64(0x1c698312f735ac76), U64(0x5fdbcefed9b76b2c), | ||
641 | U64(0x831a354c8fb1cdfc), U64(0x820516c312c0791f), | ||
642 | U64(0xb74ca762aeadabf0), U64(0xfc06ef821c80a5e1), | ||
643 | U64(0x5723cbf24518a267), U64(0x9d4df05d5f661451), | ||
644 | U64(0x588627742dfd40bf), U64(0xda8331b73f3d39a0), | ||
645 | U64(0x17b0e392d109a405), U64(0xf965400bcf28fba9), | ||
646 | U64(0x7c3dbf4229a2a925), U64(0x023e460327e275db), | ||
647 | U64(0x6cd0b55a0ce126b3), U64(0xe62da695828e96e7), | ||
648 | U64(0x42ad6e63b3f373b9), U64(0xe50cc319381d57df), | ||
649 | U64(0xc5cbd729729b54ee), U64(0x46d1e265fd2a9912), | ||
650 | U64(0x6428b056904eeff8), U64(0x8be23040131e04b7), | ||
651 | U64(0x6709d5da2add2ec0), U64(0x075de98af44a2b93), | ||
652 | U64(0x8447dcc67bfbe66f), U64(0x6616f655b7ac9a23), | ||
653 | U64(0xd607b8bded4b1a40), U64(0x0563af89d3a85e48), | ||
654 | U64(0x3db1b4ad20c21ba4), U64(0x11f22997b8323b75), | ||
655 | U64(0x292032b34b587e99), U64(0x7f1cdace9331681d), | ||
656 | U64(0x8e819fc9c0b65aff), U64(0xa1e3677fe2d5bb16), | ||
657 | U64(0xcd33d225ee349da5), U64(0xd9a2543b85aef898), | ||
658 | U64(0x795e10cbfa0af76d), U64(0x25a4bbb9992e5d79), | ||
659 | U64(0x78413344677b438e), U64(0xf0826688cef68601), | ||
660 | U64(0xd27b34bba392f0eb), U64(0x551d8df162fad7bc), | ||
661 | U64(0x1e57c511d0d7d9ad), U64(0xdeffbdb171e4d30b), | ||
662 | U64(0xf4feea8e802f6caa), U64(0xa480c8f6317de55e), | ||
663 | U64(0xa0fc44f07fa40ff5), U64(0x95b5f551c3c9dd1a), | ||
664 | U64(0x22f952336d6476ea), U64(0x0000000000000000), | ||
665 | U64(0xa6be8ef5169f9085), U64(0xcc2cf1aa73452946), | ||
666 | U64(0x2e7ddb39bf12550a), U64(0xd526dd3157d8db78), | ||
667 | U64(0x486b2d6c08becf29), U64(0x9b0f3a58365d8b21), | ||
668 | U64(0xac78cdfaadd22c15), U64(0xbc95c7e28891a383), | ||
669 | U64(0x6a927f5f65dab9c3), U64(0xc3891d2c1ba0cb9e), | ||
670 | U64(0xeaa92f9f50f8b507), U64(0xcf0d9426c9d6e87e), | ||
671 | U64(0xca6e3baf1a7eb636), U64(0xab25247059980786), | ||
672 | U64(0x69b31ad3df4978fb), U64(0xe2512a93cc577c4c), | ||
673 | U64(0xff278a0ea61364d9), U64(0x71a615c766a53e26), | ||
674 | U64(0x89dc764334fc716c), U64(0xf87a638452594f4a), | ||
675 | U64(0xf2bc208be914f3da), U64(0x8766b94ac1682757), | ||
676 | U64(0xbbc82e687cdb8810), U64(0x626a7a53f9757088), | ||
677 | U64(0xa2c202f358467a2e), U64(0x4d0882e5db169161), | ||
678 | U64(0x09e7268301de7da8), U64(0xe897699c771ac0dc), | ||
679 | U64(0xc8507dac3d9cc3ed), U64(0xc0a878a0a1330aa6), | ||
680 | U64(0x978bb352e42ba8c1), U64(0xe9884a13ea6b743f), | ||
681 | U64(0x279afdbabecc28a2), U64(0x047c8c064ed9eaab), | ||
682 | U64(0x507e2278b15289f4), U64(0x599904fbb08cf45c), | ||
683 | U64(0xbd8ae46d15e01760), U64(0x31353da7f2b43844), | ||
684 | U64(0x8558ff49e68a528c), U64(0x76fbfc4d92ef15b5), | ||
685 | U64(0x3456922e211c660c), U64(0x86799ac55c1993b4), | ||
686 | U64(0x3e90d1219a51da9c), U64(0x2d5cbeb505819432), | ||
687 | U64(0x982e5fd48cce4a19), U64(0xdb9c1238a24c8d43), | ||
688 | U64(0xd439febecaa96f9b), U64(0x418c0bef0960b281), | ||
689 | U64(0x158ea591f6ebd1de), U64(0x1f48e69e4da66d4e), | ||
690 | U64(0x8afd13cf8e6fb054), U64(0xf5e1c9011d5ed849), | ||
691 | U64(0xe34e091c5126c8af), U64(0xad67ee7530a398f6), | ||
692 | U64(0x43b24dec2e82c75a), U64(0x75da99c1287cd48d), | ||
693 | U64(0x92e81cdb3783f689), U64(0xa3dd217cc537cecd), | ||
694 | U64(0x60543c50de970553), U64(0x93f73f54aaf2426a), | ||
695 | U64(0xa91b62737e7a725d), U64(0xf19d4507538732e2), | ||
696 | U64(0x77e4dfc20f9ea156), U64(0x7d229ccdb4d31dc6), | ||
697 | U64(0x1b346a98037f87e5), U64(0xedf4c615a4b29e94), | ||
698 | U64(0x4093286094110662), U64(0xb0114ee85ae78063), | ||
699 | U64(0x6ff1d0d6b672e78b), U64(0x6dcf96d591909250), | ||
700 | U64(0xdfe09e3eec9567e8), U64(0x3214582b4827f97c), | ||
701 | U64(0xb46dc2ee143e6ac8), U64(0xf6c0ac8da7cd1971), | ||
702 | U64(0xebb60c10cd8901e4), U64(0xf7df8f023abcad92), | ||
703 | U64(0x9c52d3d2c217a0b2), U64(0x6b8d5cd0f8ab0d20), | ||
704 | U64(0x3777f7a29b8fa734), U64(0x011f238f9d71b4e3), | ||
705 | U64(0xc1b75b2f3c42be45), U64(0x5de588fdfe551ef7), | ||
706 | U64(0x6eeef3592b035368), U64(0xaa3a07ffc4e9b365), | ||
707 | U64(0xecebe59a39c32a77), U64(0x5ba742f8976e8187), | ||
708 | U64(0x4b4a48e0b22d0e11), U64(0xddded83dcb771233), | ||
709 | U64(0xa59feb79ac0c51bd), U64(0xc7f5912a55792135) | ||
710 | }, { /* 5 */ | ||
711 | U64(0x6d6ae04668a9b08a), U64(0x3ab3f04b0be8c743), | ||
712 | U64(0xe51e166b54b3c908), U64(0xbe90a9eb35c2f139), | ||
713 | U64(0xb2c7066637f2bec1), U64(0xaa6945613392202c), | ||
714 | U64(0x9a28c36f3b5201eb), U64(0xddce5a93ab536994), | ||
715 | U64(0x0e34133ef6382827), U64(0x52a02ba1ec55048b), | ||
716 | U64(0xa2f88f97c4b2a177), U64(0x8640e513ca2251a5), | ||
717 | U64(0xcdf1d36258137622), U64(0xfe6cb708dedf8ddb), | ||
718 | U64(0x8a174a9ec8121e5d), U64(0x679896036b81560e), | ||
719 | U64(0x59ed033395795fee), U64(0x1dd778ab8b74edaf), | ||
720 | U64(0xee533ef92d9f926d), U64(0x2a8c79baf8a8d8f5), | ||
721 | U64(0x6bcf398e69b119f6), U64(0xe20491742fafdd95), | ||
722 | U64(0x276488e0809c2aec), U64(0xea955b82d88f5cce), | ||
723 | U64(0x7102c63a99d9e0c4), U64(0xf9763017a5c39946), | ||
724 | U64(0x429fa2501f151b3d), U64(0x4659c72bea05d59e), | ||
725 | U64(0x984b7fdccf5a6634), U64(0xf742232953fbb161), | ||
726 | U64(0x3041860e08c021c7), U64(0x747bfd9616cd9386), | ||
727 | U64(0x4bb1367192312787), U64(0x1b72a1638a6c44d3), | ||
728 | U64(0x4a0e68a6e8359a66), U64(0x169a5039f258b6ca), | ||
729 | U64(0xb98a2ef44edee5a4), U64(0xd9083fe85e43a737), | ||
730 | U64(0x967f6ce239624e13), U64(0x8874f62d3c1a7982), | ||
731 | U64(0x3c1629830af06e3f), U64(0x9165ebfd427e5a8e), | ||
732 | U64(0xb5dd81794ceeaa5c), U64(0x0de8f15a7834f219), | ||
733 | U64(0x70bd98ede3dd5d25), U64(0xaccc9ca9328a8950), | ||
734 | U64(0x56664eda1945ca28), U64(0x221db34c0f8859ae), | ||
735 | U64(0x26dbd637fa98970d), U64(0x1acdffb4f068f932), | ||
736 | U64(0x4585254f64090fa0), U64(0x72de245e17d53afa), | ||
737 | U64(0x1546b25d7c546cf4), U64(0x207e0ffffb803e71), | ||
738 | U64(0xfaaad2732bcf4378), U64(0xb462dfae36ea17bd), | ||
739 | U64(0xcf926fd1ac1b11fd), U64(0xe0672dc7dba7ba4a), | ||
740 | U64(0xd3fa49ad5d6b41b3), U64(0x8ba81449b216a3bc), | ||
741 | U64(0x14f9ec8a0650d115), U64(0x40fc1ee3eb1d7ce2), | ||
742 | U64(0x23a2ed9b758ce44f), U64(0x782c521b14fddc7e), | ||
743 | U64(0x1c68267cf170504e), U64(0xbcf31558c1ca96e6), | ||
744 | U64(0xa781b43b4ba6d235), U64(0xf6fd7dfe29ff0c80), | ||
745 | U64(0xb0a4bad5c3fad91e), U64(0xd199f51ea963266c), | ||
746 | U64(0x414340349119c103), U64(0x5405f269ed4dadf7), | ||
747 | U64(0xabd61bb649969dcd), U64(0x6813dbeae7bdc3c8), | ||
748 | U64(0x65fb2ab09f8931d1), U64(0xf1e7fae152e3181d), | ||
749 | U64(0xc1a67cef5a2339da), U64(0x7a4feea8e0f5bba1), | ||
750 | U64(0x1e0b9acf05783791), U64(0x5b8ebf8061713831), | ||
751 | U64(0x80e53cdbcb3af8d9), U64(0x7e898bd315e57502), | ||
752 | U64(0xc6bcfbf0213f2d47), U64(0x95a38e86b76e942d), | ||
753 | U64(0x092e94218d243cba), U64(0x8339debf453622e7), | ||
754 | U64(0xb11be402b9fe64ff), U64(0x57d9100d634177c9), | ||
755 | U64(0xcc4e8db52217cbc3), U64(0x3b0cae9c71ec7aa2), | ||
756 | U64(0xfb158ca451cbfe99), U64(0x2b33276d82ac6514), | ||
757 | U64(0x01bf5ed77a04bde1), U64(0xc5601994af33f779), | ||
758 | U64(0x75c4a3416cc92e67), U64(0xf3844652a6eb7fc2), | ||
759 | U64(0x3487e375fdd0ef64), U64(0x18ae430704609eed), | ||
760 | U64(0x4d14efb993298efb), U64(0x815a620cb13e4538), | ||
761 | U64(0x125c354207487869), U64(0x9eeea614ce42cf48), | ||
762 | U64(0xce2d3106d61fac1c), U64(0xbbe99247bad6827b), | ||
763 | U64(0x071a871f7b1c149d), U64(0x2e4a1cc10db81656), | ||
764 | U64(0x77a71ff298c149b8), U64(0x06a5d9c80118a97c), | ||
765 | U64(0xad73c27e488e34b1), U64(0x443a7b981e0db241), | ||
766 | U64(0xe3bbcfa355ab6074), U64(0x0af276450328e684), | ||
767 | U64(0x73617a896dd1871b), U64(0x58525de4ef7de20f), | ||
768 | U64(0xb7be3dcab8e6cd83), U64(0x19111dd07e64230c), | ||
769 | U64(0x842359a03e2a367a), U64(0x103f89f1f3401fb6), | ||
770 | U64(0xdc710444d157d475), U64(0xb835702334da5845), | ||
771 | U64(0x4320fc876511a6dc), U64(0xd026abc9d3679b8d), | ||
772 | U64(0x17250eee885c0b2b), U64(0x90dab52a387ae76f), | ||
773 | U64(0x31fed8d972c49c26), U64(0x89cba8fa461ec463), | ||
774 | U64(0x2ff5421677bcabb7), U64(0x396f122f85e41d7d), | ||
775 | U64(0xa09b332430bac6a8), U64(0xc888e8ced7070560), | ||
776 | U64(0xaeaf201ac682ee8f), U64(0x1180d7268944a257), | ||
777 | U64(0xf058a43628e7a5fc), U64(0xbd4c4b8fbbce2b07), | ||
778 | U64(0xa1246df34abe7b49), U64(0x7d5569b79be9af3c), | ||
779 | U64(0xa9b5a705bd9efa12), U64(0xdb6b835baa4bc0e8), | ||
780 | U64(0x05793bac8f147342), U64(0x21c1512881848390), | ||
781 | U64(0xfdb0556c50d357e5), U64(0x613d4fcb6a99ff72), | ||
782 | U64(0x03dce2648e0cda3e), U64(0xe949b9e6568386f0), | ||
783 | U64(0xfc0f0bbb2ad7ea04), U64(0x6a70675913b5a417), | ||
784 | U64(0x7f36d5046fe1c8e3), U64(0x0c57af8d02304ff8), | ||
785 | U64(0x32223abdfcc84618), U64(0x0891caf6f720815b), | ||
786 | U64(0xa63eeaec31a26fd4), U64(0x2507345374944d33), | ||
787 | U64(0x49d28ac266394058), U64(0xf5219f9aa7f3d6be), | ||
788 | U64(0x2d96fea583b4cc68), U64(0x5a31e1571b7585d0), | ||
789 | U64(0x8ed12fe53d02d0fe), U64(0xdfade6205f5b0e4b), | ||
790 | U64(0x4cabb16ee92d331a), U64(0x04c6657bf510cea3), | ||
791 | U64(0xd73c2cd6a87b8f10), U64(0xe1d87310a1a307ab), | ||
792 | U64(0x6cd5be9112ad0d6b), U64(0x97c032354366f3f2), | ||
793 | U64(0xd4e0ceb22677552e), U64(0x0000000000000000), | ||
794 | U64(0x29509bde76a402cb), U64(0xc27a9e8bd42fe3e4), | ||
795 | U64(0x5ef7842cee654b73), U64(0xaf107ecdbc86536e), | ||
796 | U64(0x3fcacbe784fcb401), U64(0xd55f90655c73e8cf), | ||
797 | U64(0xe6c2f40fdabf1336), U64(0xe8f6e7312c873b11), | ||
798 | U64(0xeb2a0555a28be12f), U64(0xe4a148bc2eb774e9), | ||
799 | U64(0x9b979db84156bc0a), U64(0x6eb60222e6a56ab4), | ||
800 | U64(0x87ffbbc4b026ec44), U64(0xc703a5275b3b90a6), | ||
801 | U64(0x47e699fc9001687f), U64(0x9c8d1aa73a4aa897), | ||
802 | U64(0x7cea3760e1ed12dd), U64(0x4ec80ddd1d2554c5), | ||
803 | U64(0x13e36b957d4cc588), U64(0x5d2b66486069914d), | ||
804 | U64(0x92b90999cc7280b0), U64(0x517cc9c56259deb5), | ||
805 | U64(0xc937b619ad03b881), U64(0xec30824ad997f5b2), | ||
806 | U64(0xa45d565fc5aa080b), U64(0xd6837201d27f32f1), | ||
807 | U64(0x635ef3789e9198ad), U64(0x531f75769651b96a), | ||
808 | U64(0x4f77530a6721e924), U64(0x486dd4151c3dfdb9), | ||
809 | U64(0x5f48dafb9461f692), U64(0x375b011173dc355a), | ||
810 | U64(0x3da9775470f4d3de), U64(0x8d0dcd81b30e0ac0), | ||
811 | U64(0x36e45fc609d888bb), U64(0x55baacbe97491016), | ||
812 | U64(0x8cb29356c90ab721), U64(0x76184125e2c5f459), | ||
813 | U64(0x99f4210bb55edbd5), U64(0x6f095cf59ca1d755), | ||
814 | U64(0x9f51f8c3b44672a9), U64(0x3538bda287d45285), | ||
815 | U64(0x50c39712185d6354), U64(0xf23b1885dcefc223), | ||
816 | U64(0x79930ccc6ef9619f), U64(0xed8fdc9da3934853), | ||
817 | U64(0xcb540aaa590bdf5e), U64(0x5c94389f1a6d2cac), | ||
818 | U64(0xe77daad8a0bbaed7), U64(0x28efc5090ca0bf2a), | ||
819 | U64(0xbf2ff73c4fc64cd8), U64(0xb37858b14df60320), | ||
820 | U64(0xf8c96ec0dfc724a7), U64(0x828680683f329f06), | ||
821 | U64(0x941cd051cd6a29cc), U64(0xc3c5c05cae2b5e05), | ||
822 | U64(0xb601631dc2e27062), U64(0xc01922382027843b), | ||
823 | U64(0x24b86a840e90f0d2), U64(0xd245177a276ffc52), | ||
824 | U64(0x0f8b4de98c3c95c6), U64(0x3e759530fef809e0), | ||
825 | U64(0x0b4d2892792c5b65), U64(0xc4df4743d5374a98), | ||
826 | U64(0xa5e20888bfaeb5ea), U64(0xba56cc90c0d23f9a), | ||
827 | U64(0x38d04cf8ffe0a09c), U64(0x62e1adafe495254c), | ||
828 | U64(0x0263bcb3f40867df), U64(0xcaeb547d230f62bf), | ||
829 | U64(0x6082111c109d4293), U64(0xdad4dd8cd04f7d09), | ||
830 | U64(0xefec602e579b2f8c), U64(0x1fb4c4187f7c8a70), | ||
831 | U64(0xffd3e9dfa4db303a), U64(0x7bf0b07f9af10640), | ||
832 | U64(0xf49ec14dddf76b5f), U64(0x8f6e713247066d1f), | ||
833 | U64(0x339d646a86ccfbf9), U64(0x64447467e58d8c30), | ||
834 | U64(0x2c29a072f9b07189), U64(0xd8b7613f24471ad6), | ||
835 | U64(0x6627c8d41185ebef), U64(0xa347d140beb61c96), | ||
836 | U64(0xde12b8f7255fb3aa), U64(0x9d324470404e1576), | ||
837 | U64(0x9306574eb6763d51), U64(0xa80af9d2c79a47f3), | ||
838 | U64(0x859c0777442e8b9b), U64(0x69ac853d9db97e29) | ||
839 | }, { /* 6 */ | ||
840 | U64(0xc3407dfc2de6377e), U64(0x5b9e93eea4256f77), | ||
841 | U64(0xadb58fdd50c845e0), U64(0x5219ff11a75bed86), | ||
842 | U64(0x356b61cfd90b1de9), U64(0xfb8f406e25abe037), | ||
843 | U64(0x7a5a0231c0f60796), U64(0x9d3cd216e1f5020b), | ||
844 | U64(0x0c6550fb6b48d8f3), U64(0xf57508c427ff1c62), | ||
845 | U64(0x4ad35ffa71cb407d), U64(0x6290a2da1666aa6d), | ||
846 | U64(0xe284ec2349355f9f), U64(0xb3c307c53d7c84ec), | ||
847 | U64(0x05e23c0468365a02), U64(0x190bac4d6c9ebfa8), | ||
848 | U64(0x94bbbee9e28b80fa), U64(0xa34fc777529cb9b5), | ||
849 | U64(0xcc7b39f095bcd978), U64(0x2426addb0ce532e3), | ||
850 | U64(0x7e79329312ce4fc7), U64(0xab09a72eebec2917), | ||
851 | U64(0xf8d15499f6b9d6c2), U64(0x1a55b8babf8c895d), | ||
852 | U64(0xdb8add17fb769a85), U64(0xb57f2f368658e81b), | ||
853 | U64(0x8acd36f18f3f41f6), U64(0x5ce3b7bba50f11d3), | ||
854 | U64(0x114dcc14d5ee2f0a), U64(0xb91a7fcded1030e8), | ||
855 | U64(0x81d5425fe55de7a1), U64(0xb6213bc1554adeee), | ||
856 | U64(0x80144ef95f53f5f2), U64(0x1e7688186db4c10c), | ||
857 | U64(0x3b912965db5fe1bc), U64(0xc281715a97e8252d), | ||
858 | U64(0x54a5d7e21c7f8171), U64(0x4b12535ccbc5522e), | ||
859 | U64(0x1d289cefbea6f7f9), U64(0x6ef5f2217d2e729e), | ||
860 | U64(0xe6a7dc819b0d17ce), U64(0x1b94b41c05829b0e), | ||
861 | U64(0x33d7493c622f711e), U64(0xdcf7f942fa5ce421), | ||
862 | U64(0x600fba8b7f7a8ecb), U64(0x46b60f011a83988e), | ||
863 | U64(0x235b898e0dcf4c47), U64(0x957ab24f588592a9), | ||
864 | U64(0x4354330572b5c28c), U64(0xa5f3ef84e9b8d542), | ||
865 | U64(0x8c711e02341b2d01), U64(0x0b1874ae6a62a657), | ||
866 | U64(0x1213d8e306fc19ff), U64(0xfe6d7c6a4d9dba35), | ||
867 | U64(0x65ed868f174cd4c9), U64(0x88522ea0e6236550), | ||
868 | U64(0x899322065c2d7703), U64(0xc01e690bfef4018b), | ||
869 | U64(0x915982ed8abddaf8), U64(0xbe675b98ec3a4e4c), | ||
870 | U64(0xa996bf7f82f00db1), U64(0xe1daf8d49a27696a), | ||
871 | U64(0x2effd5d3dc8986e7), U64(0xd153a51f2b1a2e81), | ||
872 | U64(0x18caa0ebd690adfb), U64(0x390e3134b243c51a), | ||
873 | U64(0x2778b92cdff70416), U64(0x029f1851691c24a6), | ||
874 | U64(0x5e7cafeacc133575), U64(0xfa4e4cc89fa5f264), | ||
875 | U64(0x5a5f9f481e2b7d24), U64(0x484c47ab18d764db), | ||
876 | U64(0x400a27f2a1a7f479), U64(0xaeeb9b2a83da7315), | ||
877 | U64(0x721c626879869734), U64(0x042330a2d2384851), | ||
878 | U64(0x85f672fd3765aff0), U64(0xba446b3a3e02061d), | ||
879 | U64(0x73dd6ecec3888567), U64(0xffac70ccf793a866), | ||
880 | U64(0xdfa9edb5294ed2d4), U64(0x6c6aea7014325638), | ||
881 | U64(0x834a5a0e8c41c307), U64(0xcdba35562fb2cb2b), | ||
882 | U64(0x0ad97808d06cb404), U64(0x0f3b440cb85aee06), | ||
883 | U64(0xe5f9c876481f213b), U64(0x98deee1289c35809), | ||
884 | U64(0x59018bbfcd394bd1), U64(0xe01bf47220297b39), | ||
885 | U64(0xde68e1139340c087), U64(0x9fa3ca4788e926ad), | ||
886 | U64(0xbb85679c840c144e), U64(0x53d8f3b71d55ffd5), | ||
887 | U64(0x0da45c5dd146caa0), U64(0x6f34fe87c72060cd), | ||
888 | U64(0x57fbc315cf6db784), U64(0xcee421a1fca0fdde), | ||
889 | U64(0x3d2d0196607b8d4b), U64(0x642c8a29ad42c69a), | ||
890 | U64(0x14aff010bdd87508), U64(0xac74837beac657b3), | ||
891 | U64(0x3216459ad821634d), U64(0x3fb219c70967a9ed), | ||
892 | U64(0x06bc28f3bb246cf7), U64(0xf2082c9126d562c6), | ||
893 | U64(0x66b39278c45ee23c), U64(0xbd394f6f3f2878b9), | ||
894 | U64(0xfd33689d9e8f8cc0), U64(0x37f4799eb017394f), | ||
895 | U64(0x108cc0b26fe03d59), U64(0xda4bd1b1417888d6), | ||
896 | U64(0xb09d1332ee6eb219), U64(0x2f3ed975668794b4), | ||
897 | U64(0x58c0871977375982), U64(0x7561463d78ace990), | ||
898 | U64(0x09876cff037e82f1), U64(0x7fb83e35a8c05d94), | ||
899 | U64(0x26b9b58a65f91645), U64(0xef20b07e9873953f), | ||
900 | U64(0x3148516d0b3355b8), U64(0x41cb2b541ba9e62a), | ||
901 | U64(0x790416c613e43163), U64(0xa011d380818e8f40), | ||
902 | U64(0x3a5025c36151f3ef), U64(0xd57095bdf92266d0), | ||
903 | U64(0x498d4b0da2d97688), U64(0x8b0c3a57353153a5), | ||
904 | U64(0x21c491df64d368e1), U64(0x8f2f0af5e7091bf4), | ||
905 | U64(0x2da1c1240f9bb012), U64(0xc43d59a92ccc49da), | ||
906 | U64(0xbfa6573e56345c1f), U64(0x828b56a8364fd154), | ||
907 | U64(0x9a41f643e0df7caf), U64(0xbcf843c985266aea), | ||
908 | U64(0x2b1de9d7b4bfdce5), U64(0x20059d79dedd7ab2), | ||
909 | U64(0x6dabe6d6ae3c446b), U64(0x45e81bf6c991ae7b), | ||
910 | U64(0x6351ae7cac68b83e), U64(0xa432e32253b6c711), | ||
911 | U64(0xd092a9b991143cd2), U64(0xcac711032e98b58f), | ||
912 | U64(0xd8d4c9e02864ac70), U64(0xc5fc550f96c25b89), | ||
913 | U64(0xd7ef8dec903e4276), U64(0x67729ede7e50f06f), | ||
914 | U64(0xeac28c7af045cf3d), U64(0xb15c1f945460a04a), | ||
915 | U64(0x9cfddeb05bfb1058), U64(0x93c69abce3a1fe5e), | ||
916 | U64(0xeb0380dc4a4bdd6e), U64(0xd20db1e8f8081874), | ||
917 | U64(0x229a8528b7c15e14), U64(0x44291750739fbc28), | ||
918 | U64(0xd3ccbd4e42060a27), U64(0xf62b1c33f4ed2a97), | ||
919 | U64(0x86a8660ae4779905), U64(0xd62e814a2a305025), | ||
920 | U64(0x477703a7a08d8add), U64(0x7b9b0e977af815c5), | ||
921 | U64(0x78c51a60a9ea2330), U64(0xa6adfb733aaae3b7), | ||
922 | U64(0x97e5aa1e3199b60f), U64(0x0000000000000000), | ||
923 | U64(0xf4b404629df10e31), U64(0x5564db44a6719322), | ||
924 | U64(0x9207961a59afec0d), U64(0x9624a6b88b97a45c), | ||
925 | U64(0x363575380a192b1c), U64(0x2c60cd82b595a241), | ||
926 | U64(0x7d272664c1dc7932), U64(0x7142769faa94a1c1), | ||
927 | U64(0xa1d0df263b809d13), U64(0x1630e841d4c451ae), | ||
928 | U64(0xc1df65ad44fa13d8), U64(0x13d2d445bcf20bac), | ||
929 | U64(0xd915c546926abe23), U64(0x38cf3d92084dd749), | ||
930 | U64(0xe766d0272103059d), U64(0xc7634d5effde7f2f), | ||
931 | U64(0x077d2455012a7ea4), U64(0xedbfa82ff16fb199), | ||
932 | U64(0xaf2a978c39d46146), U64(0x42953fa3c8bbd0df), | ||
933 | U64(0xcb061da59496a7dc), U64(0x25e7a17db6eb20b0), | ||
934 | U64(0x34aa6d6963050fba), U64(0xa76cf7d580a4f1e4), | ||
935 | U64(0xf7ea10954ee338c4), U64(0xfcf2643b24819e93), | ||
936 | U64(0xcf252d0746aeef8d), U64(0x4ef06f58a3f3082c), | ||
937 | U64(0x563acfb37563a5d7), U64(0x5086e740ce47c920), | ||
938 | U64(0x2982f186dda3f843), U64(0x87696aac5e798b56), | ||
939 | U64(0x5d22bb1d1f010380), U64(0x035e14f7d31236f5), | ||
940 | U64(0x3cec0d30da759f18), U64(0xf3c920379cdb7095), | ||
941 | U64(0xb8db736b571e22bb), U64(0xdd36f5e44052f672), | ||
942 | U64(0xaac8ab8851e23b44), U64(0xa857b3d938fe1fe2), | ||
943 | U64(0x17f1e4e76eca43fd), U64(0xec7ea4894b61a3ca), | ||
944 | U64(0x9e62c6e132e734fe), U64(0xd4b1991b432c7483), | ||
945 | U64(0x6ad6c283af163acf), U64(0x1ce9904904a8e5aa), | ||
946 | U64(0x5fbda34c761d2726), U64(0xf910583f4cb7c491), | ||
947 | U64(0xc6a241f845d06d7c), U64(0x4f3163fe19fd1a7f), | ||
948 | U64(0xe99c988d2357f9c8), U64(0x8eee06535d0709a7), | ||
949 | U64(0x0efa48aa0254fc55), U64(0xb4be23903c56fa48), | ||
950 | U64(0x763f52caabbedf65), U64(0xeee1bcd8227d876c), | ||
951 | U64(0xe345e085f33b4dcc), U64(0x3e731561b369bbbe), | ||
952 | U64(0x2843fd2067adea10), U64(0x2adce5710eb1ceb6), | ||
953 | U64(0xb7e03767ef44ccbd), U64(0x8db012a48e153f52), | ||
954 | U64(0x61ceb62dc5749c98), U64(0xe85d942b9959eb9b), | ||
955 | U64(0x4c6f7709caef2c8a), U64(0x84377e5b8d6bbda3), | ||
956 | U64(0x30895dcbb13d47eb), U64(0x74a04a9bc2a2fbc3), | ||
957 | U64(0x6b17ce251518289c), U64(0xe438c4d0f2113368), | ||
958 | U64(0x1fb784bed7bad35f), U64(0x9b80fae55ad16efc), | ||
959 | U64(0x77fe5e6c11b0cd36), U64(0xc858095247849129), | ||
960 | U64(0x08466059b97090a2), U64(0x01c10ca6ba0e1253), | ||
961 | U64(0x6988d6747c040c3a), U64(0x6849dad2c60a1e69), | ||
962 | U64(0x5147ebe67449db73), U64(0xc99905f4fd8a837a), | ||
963 | U64(0x991fe2b433cd4a5a), U64(0xf09734c04fc94660), | ||
964 | U64(0xa28ecbd1e892abe6), U64(0xf1563866f5c75433), | ||
965 | U64(0x4dae7baf70e13ed9), U64(0x7ce62ac27bd26b61), | ||
966 | U64(0x70837a39109ab392), U64(0x90988e4b30b3c8ab), | ||
967 | U64(0xb2020b63877296bf), U64(0x156efcb607d6675b) | ||
968 | }, { /* 7 */ | ||
969 | U64(0xe63f55ce97c331d0), U64(0x25b506b0015bba16), | ||
970 | U64(0xc8706e29e6ad9ba8), U64(0x5b43d3775d521f6a), | ||
971 | U64(0x0bfa3d577035106e), U64(0xab95fc172afb0e66), | ||
972 | U64(0xf64b63979e7a3276), U64(0xf58b4562649dad4b), | ||
973 | U64(0x48f7c3dbae0c83f1), U64(0xff31916642f5c8c5), | ||
974 | U64(0xcbb048dc1c4a0495), U64(0x66b8f83cdf622989), | ||
975 | U64(0x35c130e908e2b9b0), U64(0x7c761a61f0b34fa1), | ||
976 | U64(0x3601161cf205268d), U64(0x9e54ccfe2219b7d6), | ||
977 | U64(0x8b7d90a538940837), U64(0x9cd403588ea35d0b), | ||
978 | U64(0xbc3c6fea9ccc5b5a), U64(0xe5ff733b6d24aeed), | ||
979 | U64(0xceed22de0f7eb8d2), U64(0xec8581cab1ab545e), | ||
980 | U64(0xb96105e88ff8e71d), U64(0x8ca03501871a5ead), | ||
981 | U64(0x76ccce65d6db2a2f), U64(0x5883f582a7b58057), | ||
982 | U64(0x3f7be4ed2e8adc3e), U64(0x0fe7be06355cd9c9), | ||
983 | U64(0xee054e6c1d11be83), U64(0x1074365909b903a6), | ||
984 | U64(0x5dde9f80b4813c10), U64(0x4a770c7d02b6692c), | ||
985 | U64(0x5379c8d5d7809039), U64(0xb4067448161ed409), | ||
986 | U64(0x5f5e5026183bd6cd), U64(0xe898029bf4c29df9), | ||
987 | U64(0x7fb63c940a54d09c), U64(0xc5171f897f4ba8bc), | ||
988 | U64(0xa6f28db7b31d3d72), U64(0x2e4f3be7716eaa78), | ||
989 | U64(0x0d6771a099e63314), U64(0x82076254e41bf284), | ||
990 | U64(0x2f0fd2b42733df98), U64(0x5c9e76d3e2dc49f0), | ||
991 | U64(0x7aeb569619606cdb), U64(0x83478b07b2468764), | ||
992 | U64(0xcfadcb8d5923cd32), U64(0x85dac7f05b95a41e), | ||
993 | U64(0xb5469d1b4043a1e9), U64(0xb821ecbbd9a592fd), | ||
994 | U64(0x1b8e0b0e798c13c8), U64(0x62a57b6d9a0be02e), | ||
995 | U64(0xfcf1b793b81257f8), U64(0x9d94ea0bd8fe28eb), | ||
996 | U64(0x4cea408aeb654a56), U64(0x23284a47e888996c), | ||
997 | U64(0x2d8f1d128b893545), U64(0xf4cbac3132c0d8ab), | ||
998 | U64(0xbd7c86b9ca912eba), U64(0x3a268eef3dbe6079), | ||
999 | U64(0xf0d62f6077a9110c), U64(0x2735c916ade150cb), | ||
1000 | U64(0x89fd5f03942ee2ea), U64(0x1acee25d2fd16628), | ||
1001 | U64(0x90f39bab41181bff), U64(0x430dfe8cde39939f), | ||
1002 | U64(0xf70b8ac4c8274796), U64(0x1c53aeaac6024552), | ||
1003 | U64(0x13b410acf35e9c9b), U64(0xa532ab4249faa24f), | ||
1004 | U64(0x2b1251e5625a163f), U64(0xd7e3e676da4841c7), | ||
1005 | U64(0xa7b264e4e5404892), U64(0xda8497d643ae72d3), | ||
1006 | U64(0x861ae105a1723b23), U64(0x38a6414991048aa4), | ||
1007 | U64(0x6578dec92585b6b4), U64(0x0280cfa6acbaeadd), | ||
1008 | U64(0x88bdb650c273970a), U64(0x9333bd5ebbff84c2), | ||
1009 | U64(0x4e6a8f2c47dfa08b), U64(0x321c954db76cef2a), | ||
1010 | U64(0x418d312a72837942), U64(0xb29b38bfffcdf773), | ||
1011 | U64(0x6c022c38f90a4c07), U64(0x5a033a240b0f6a8a), | ||
1012 | U64(0x1f93885f3ce5da6f), U64(0xc38a537e96988bc6), | ||
1013 | U64(0x39e6a81ac759ff44), U64(0x29929e43cee0fce2), | ||
1014 | U64(0x40cdd87924de0ca2), U64(0xe9d8ebc8a29fe819), | ||
1015 | U64(0x0c2798f3cfbb46f4), U64(0x55e484223e53b343), | ||
1016 | U64(0x4650948ecd0d2fd8), U64(0x20e86cb2126f0651), | ||
1017 | U64(0x6d42c56baf5739e7), U64(0xa06fc1405ace1e08), | ||
1018 | U64(0x7babbfc54f3d193b), U64(0x424d17df8864e67f), | ||
1019 | U64(0xd8045870ef14980e), U64(0xc6d7397c85ac3781), | ||
1020 | U64(0x21a885e1443273b1), U64(0x67f8116f893f5c69), | ||
1021 | U64(0x24f5efe35706cff6), U64(0xd56329d076f2ab1a), | ||
1022 | U64(0x5e1eb9754e66a32d), U64(0x28d2771098bd8902), | ||
1023 | U64(0x8f6013f47dfdc190), U64(0x17a993fdb637553c), | ||
1024 | U64(0xe0a219397e1012aa), U64(0x786b9930b5da8606), | ||
1025 | U64(0x6e82e39e55b0a6da), U64(0x875a0856f72f4ec3), | ||
1026 | U64(0x3741ff4fa458536d), U64(0xac4859b3957558fc), | ||
1027 | U64(0x7ef6d5c75c09a57c), U64(0xc04a758b6c7f14fb), | ||
1028 | U64(0xf9acdd91ab26ebbf), U64(0x7391a467c5ef9668), | ||
1029 | U64(0x335c7c1ee1319aca), U64(0xa91533b18641e4bb), | ||
1030 | U64(0xe4bf9a683b79db0d), U64(0x8e20faa72ba0b470), | ||
1031 | U64(0x51f907737b3a7ae4), U64(0x2268a314bed5ec8c), | ||
1032 | U64(0xd944b123b949edee), U64(0x31dcb3b84d8b7017), | ||
1033 | U64(0xd3fe65279f218860), U64(0x097af2f1dc8ffab3), | ||
1034 | U64(0x9b09a6fc312d0b91), U64(0xcc6ded78a3c4520f), | ||
1035 | U64(0x3481d9ba5ebfcc50), U64(0x4f2a667f1182d56b), | ||
1036 | U64(0xdfd9fdd4509ace94), U64(0x26752045fbbc252b), | ||
1037 | U64(0xbffc491f662bc467), U64(0xdd593272fc202449), | ||
1038 | U64(0x3cbbc218d46d4303), U64(0x91b372f817456e1f), | ||
1039 | U64(0x681faf69bc6385a0), U64(0xb686bbeebaa43ed4), | ||
1040 | U64(0x1469b5084cd0ca01), U64(0x98c98009cbca94ac), | ||
1041 | U64(0x6438379a73d8c354), U64(0xc2caba2dc0c5fe26), | ||
1042 | U64(0x3e3b0dbe78d7a9de), U64(0x50b9ee202d670f04), | ||
1043 | U64(0x4590b27b37eab0e5), U64(0x6025b4cb36b10af3), | ||
1044 | U64(0xfb2c1237079c0162), U64(0xa12f28130c936be8), | ||
1045 | U64(0x4b37e52e54eb1ccc), U64(0x083a1ba28ad28f53), | ||
1046 | U64(0xc10a9cd83a22611b), U64(0x9f1425ad7444c236), | ||
1047 | U64(0x069d4cf7e9d3237a), U64(0xedc56899e7f621be), | ||
1048 | U64(0x778c273680865fcf), U64(0x309c5aeb1bd605f7), | ||
1049 | U64(0x8de0dc52d1472b4d), U64(0xf8ec34c2fd7b9e5f), | ||
1050 | U64(0xea18cd3d58787724), U64(0xaad515447ca67b86), | ||
1051 | U64(0x9989695a9d97e14c), U64(0x0000000000000000), | ||
1052 | U64(0xf196c63321f464ec), U64(0x71116bc169557cb5), | ||
1053 | U64(0xaf887f466f92c7c1), U64(0x972e3e0ffe964d65), | ||
1054 | U64(0x190ec4a8d536f915), U64(0x95aef1a9522ca7b8), | ||
1055 | U64(0xdc19db21aa7d51a9), U64(0x94ee18fa0471d258), | ||
1056 | U64(0x8087adf248a11859), U64(0xc457f6da2916dd5c), | ||
1057 | U64(0xfa6cfb6451c17482), U64(0xf256e0c6db13fbd1), | ||
1058 | U64(0x6a9f60cf10d96f7d), U64(0x4daaa9d9bd383fb6), | ||
1059 | U64(0x03c026f5fae79f3d), U64(0xde99148706c7bb74), | ||
1060 | U64(0x2a52b8b6340763df), U64(0x6fc20acd03edd33a), | ||
1061 | U64(0xd423c08320afdefa), U64(0xbbe1ca4e23420dc0), | ||
1062 | U64(0x966ed75ca8cb3885), U64(0xeb58246e0e2502c4), | ||
1063 | U64(0x055d6a021334bc47), U64(0xa47242111fa7d7af), | ||
1064 | U64(0xe3623fcc84f78d97), U64(0x81c744a11efc6db9), | ||
1065 | U64(0xaec8961539cfb221), U64(0xf31609958d4e8e31), | ||
1066 | U64(0x63e5923ecc5695ce), U64(0x47107ddd9b505a38), | ||
1067 | U64(0xa3afe7b5a0298135), U64(0x792b7063e387f3e6), | ||
1068 | U64(0x0140e953565d75e0), U64(0x12f4f9ffa503e97b), | ||
1069 | U64(0x750ce8902c3cb512), U64(0xdbc47e8515f30733), | ||
1070 | U64(0x1ed3610c6ab8af8f), U64(0x5239218681dde5d9), | ||
1071 | U64(0xe222d69fd2aaf877), U64(0xfe71783514a8bd25), | ||
1072 | U64(0xcaf0a18f4a177175), U64(0x61655d9860ec7f13), | ||
1073 | U64(0xe77fbc9dc19e4430), U64(0x2ccff441ddd440a5), | ||
1074 | U64(0x16e97aaee06a20dc), U64(0xa855dae2d01c915b), | ||
1075 | U64(0x1d1347f9905f30b2), U64(0xb7c652bdecf94b34), | ||
1076 | U64(0xd03e43d265c6175d), U64(0xfdb15ec0ee4f2218), | ||
1077 | U64(0x57644b8492e9599e), U64(0x07dda5a4bf8e569a), | ||
1078 | U64(0x54a46d71680ec6a3), U64(0x5624a2d7c4b42c7e), | ||
1079 | U64(0xbebca04c3076b187), U64(0x7d36f332a6ee3a41), | ||
1080 | U64(0x3b6667bc6be31599), U64(0x695f463aea3ef040), | ||
1081 | U64(0xad08b0e0c3282d1c), U64(0xb15b1e4a052a684e), | ||
1082 | U64(0x44d05b2861b7c505), U64(0x15295c5b1a8dbfe1), | ||
1083 | U64(0x744c01c37a61c0f2), U64(0x59c31cd1f1e8f5b7), | ||
1084 | U64(0xef45a73f4b4ccb63), U64(0x6bdf899c46841a9d), | ||
1085 | U64(0x3dfb2b4b823036e3), U64(0xa2ef0ee6f674f4d5), | ||
1086 | U64(0x184e2dfb836b8cf5), U64(0x1134df0a5fe47646), | ||
1087 | U64(0xbaa1231d751f7820), U64(0xd17eaa81339b62bd), | ||
1088 | U64(0xb01bf71953771dae), U64(0x849a2ea30dc8d1fe), | ||
1089 | U64(0x705182923f080955), U64(0x0ea757556301ac29), | ||
1090 | U64(0x041d83514569c9a7), U64(0x0abad4042668658e), | ||
1091 | U64(0x49b72a88f851f611), U64(0x8a3d79f66ec97dd7), | ||
1092 | U64(0xcd2d042bf59927ef), U64(0xc930877ab0f0ee48), | ||
1093 | U64(0x9273540deda2f122), U64(0xc797d02fd3f14261), | ||
1094 | U64(0xe1e2f06a284d674a), U64(0xd2be8c74c97cfd80), | ||
1095 | U64(0x9a494faf67707e71), U64(0xb3dbd1eca9908293), | ||
1096 | U64(0x72d14d3493b2e388), U64(0xd6a30f258c153427) | ||
1097 | }, | ||
1098 | }; | ||
1099 | |||
1100 | static const STREEBOG_LONG64 C16[12][8] = | ||
1101 | { | ||
1102 | { | ||
1103 | U64(0xdd806559f2a64507), U64(0x05767436cc744d23), | ||
1104 | U64(0xa2422a08a460d315), U64(0x4b7ce09192676901), | ||
1105 | U64(0x714eb88d7585c4fc), U64(0x2f6a76432e45d016), | ||
1106 | U64(0xebcb2f81c0657c1f), U64(0xb1085bda1ecadae9) | ||
1107 | }, { | ||
1108 | U64(0xe679047021b19bb7), U64(0x55dda21bd7cbcd56), | ||
1109 | U64(0x5cb561c2db0aa7ca), U64(0x9ab5176b12d69958), | ||
1110 | U64(0x61d55e0f16b50131), U64(0xf3feea720a232b98), | ||
1111 | U64(0x4fe39d460f70b5d7), U64(0x6fa3b58aa99d2f1a) | ||
1112 | }, { | ||
1113 | U64(0x991e96f50aba0ab2), U64(0xc2b6f443867adb31), | ||
1114 | U64(0xc1c93a376062db09), U64(0xd3e20fe490359eb1), | ||
1115 | U64(0xf2ea7514b1297b7b), U64(0x06f15e5f529c1f8b), | ||
1116 | U64(0x0a39fc286a3d8435), U64(0xf574dcac2bce2fc7) | ||
1117 | }, { | ||
1118 | U64(0x220cbebc84e3d12e), U64(0x3453eaa193e837f1), | ||
1119 | U64(0xd8b71333935203be), U64(0xa9d72c82ed03d675), | ||
1120 | U64(0x9d721cad685e353f), U64(0x488e857e335c3c7d), | ||
1121 | U64(0xf948e1a05d71e4dd), U64(0xef1fdfb3e81566d2) | ||
1122 | }, { | ||
1123 | U64(0x601758fd7c6cfe57), U64(0x7a56a27ea9ea63f5), | ||
1124 | U64(0xdfff00b723271a16), U64(0xbfcd1747253af5a3), | ||
1125 | U64(0x359e35d7800fffbd), U64(0x7f151c1f1686104a), | ||
1126 | U64(0x9a3f410c6ca92363), U64(0x4bea6bacad474799) | ||
1127 | }, { | ||
1128 | U64(0xfa68407a46647d6e), U64(0xbf71c57236904f35), | ||
1129 | U64(0x0af21f66c2bec6b6), U64(0xcffaa6b71c9ab7b4), | ||
1130 | U64(0x187f9ab49af08ec6), U64(0x2d66c4f95142a46c), | ||
1131 | U64(0x6fa4c33b7a3039c0), U64(0xae4faeae1d3ad3d9) | ||
1132 | }, { | ||
1133 | U64(0x8886564d3a14d493), U64(0x3517454ca23c4af3), | ||
1134 | U64(0x06476983284a0504), U64(0x0992abc52d822c37), | ||
1135 | U64(0xd3473e33197a93c9), U64(0x399ec6c7e6bf87c9), | ||
1136 | U64(0x51ac86febf240954), U64(0xf4c70e16eeaac5ec) | ||
1137 | }, { | ||
1138 | U64(0xa47f0dd4bf02e71e), U64(0x36acc2355951a8d9), | ||
1139 | U64(0x69d18d2bd1a5c42f), U64(0xf4892bcb929b0690), | ||
1140 | U64(0x89b4443b4ddbc49a), U64(0x4eb7f8719c36de1e), | ||
1141 | U64(0x03e7aa020c6e4141), U64(0x9b1f5b424d93c9a7) | ||
1142 | }, { | ||
1143 | U64(0x7261445183235adb), U64(0x0e38dc92cb1f2a60), | ||
1144 | U64(0x7b2b8a9aa6079c54), U64(0x800a440bdbb2ceb1), | ||
1145 | U64(0x3cd955b7e00d0984), U64(0x3a7d3a1b25894224), | ||
1146 | U64(0x944c9ad8ec165fde), U64(0x378f5a541631229b) | ||
1147 | }, { | ||
1148 | U64(0x74b4c7fb98459ced), U64(0x3698fad1153bb6c3), | ||
1149 | U64(0x7a1e6c303b7652f4), U64(0x9fe76702af69334b), | ||
1150 | U64(0x1fffe18a1b336103), U64(0x8941e71cff8a78db), | ||
1151 | U64(0x382ae548b2e4f3f3), U64(0xabbedea680056f52) | ||
1152 | }, { | ||
1153 | U64(0x6bcaa4cd81f32d1b), U64(0xdea2594ac06fd85d), | ||
1154 | U64(0xefbacd1d7d476e98), U64(0x8a1d71efea48b9ca), | ||
1155 | U64(0x2001802114846679), U64(0xd8fa6bbbebab0761), | ||
1156 | U64(0x3002c6cd635afe94), U64(0x7bcd9ed0efc889fb) | ||
1157 | }, { | ||
1158 | U64(0x48bc924af11bd720), U64(0xfaf417d5d9b21b99), | ||
1159 | U64(0xe71da4aa88e12852), U64(0x5d80ef9d1891cc86), | ||
1160 | U64(0xf82012d430219f9b), U64(0xcda43c32bcdf1d77), | ||
1161 | U64(0xd21380b00449b17a), U64(0x378ee767f11631ba) | ||
1162 | }, | ||
1163 | }; | ||
1164 | |||
1165 | #define B(x,i,j) (((STREEBOG_LONG64)(*(((const unsigned char *)(&x))+i)))<<(j*8)) | ||
1166 | #define PULL64(x) (B(x,0,0)|B(x,1,1)|B(x,2,2)|B(x,3,3)|B(x,4,4)|B(x,5,5)|B(x,6,6)|B(x,7,7)) | ||
1167 | #define SWAB64(x) (B(x,0,7)|B(x,1,6)|B(x,2,5)|B(x,3,4)|B(x,4,3)|B(x,5,2)|B(x,6,1)|B(x,7,0)) | ||
1168 | |||
1169 | static inline STREEBOG_LONG64 multipermute(const STREEBOG_LONG64 *in, int i) { | ||
1170 | STREEBOG_LONG64 t = 0; | ||
1171 | |||
1172 | t ^= A_PI_table[0][(in[0] >> (i * 8)) & 0xff]; | ||
1173 | t ^= A_PI_table[1][(in[1] >> (i * 8)) & 0xff]; | ||
1174 | t ^= A_PI_table[2][(in[2] >> (i * 8)) & 0xff]; | ||
1175 | t ^= A_PI_table[3][(in[3] >> (i * 8)) & 0xff]; | ||
1176 | t ^= A_PI_table[4][(in[4] >> (i * 8)) & 0xff]; | ||
1177 | t ^= A_PI_table[5][(in[5] >> (i * 8)) & 0xff]; | ||
1178 | t ^= A_PI_table[6][(in[6] >> (i * 8)) & 0xff]; | ||
1179 | t ^= A_PI_table[7][(in[7] >> (i * 8)) & 0xff]; | ||
1180 | |||
1181 | return t; | ||
1182 | } | ||
1183 | |||
1184 | static void transform(STREEBOG_LONG64 *out, const STREEBOG_LONG64 *a, const STREEBOG_LONG64 *b) | ||
1185 | { | ||
1186 | STREEBOG_LONG64 tmp[8]; | ||
1187 | |||
1188 | tmp[0] = a[0] ^ b[0]; | ||
1189 | tmp[1] = a[1] ^ b[1]; | ||
1190 | tmp[2] = a[2] ^ b[2]; | ||
1191 | tmp[3] = a[3] ^ b[3]; | ||
1192 | tmp[4] = a[4] ^ b[4]; | ||
1193 | tmp[5] = a[5] ^ b[5]; | ||
1194 | tmp[6] = a[6] ^ b[6]; | ||
1195 | tmp[7] = a[7] ^ b[7]; | ||
1196 | |||
1197 | out[0] = multipermute(tmp, 0); | ||
1198 | out[1] = multipermute(tmp, 1); | ||
1199 | out[2] = multipermute(tmp, 2); | ||
1200 | out[3] = multipermute(tmp, 3); | ||
1201 | out[4] = multipermute(tmp, 4); | ||
1202 | out[5] = multipermute(tmp, 5); | ||
1203 | out[6] = multipermute(tmp, 6); | ||
1204 | out[7] = multipermute(tmp, 7); | ||
1205 | } | ||
1206 | |||
1207 | static inline void gN(STREEBOG_LONG64 *h, STREEBOG_LONG64 *m, STREEBOG_LONG64 *N) | ||
1208 | { | ||
1209 | STREEBOG_LONG64 K[8]; | ||
1210 | STREEBOG_LONG64 T[8]; | ||
1211 | int i; | ||
1212 | |||
1213 | transform(K, h, N); | ||
1214 | |||
1215 | transform(T, K, m); | ||
1216 | transform(K, K, C16[0]); | ||
1217 | for (i = 1; i < 12; i++) { | ||
1218 | transform(T, K, T); | ||
1219 | transform(K, K, C16[i]); | ||
1220 | } | ||
1221 | |||
1222 | h[0] ^= T[0] ^ K[0] ^ m[0]; | ||
1223 | h[1] ^= T[1] ^ K[1] ^ m[1]; | ||
1224 | h[2] ^= T[2] ^ K[2] ^ m[2]; | ||
1225 | h[3] ^= T[3] ^ K[3] ^ m[3]; | ||
1226 | h[4] ^= T[4] ^ K[4] ^ m[4]; | ||
1227 | h[5] ^= T[5] ^ K[5] ^ m[5]; | ||
1228 | h[6] ^= T[6] ^ K[6] ^ m[6]; | ||
1229 | h[7] ^= T[7] ^ K[7] ^ m[7]; | ||
1230 | } | ||
1231 | |||
1232 | |||
1233 | static void streebog_single_block(STREEBOG_CTX * ctx, const unsigned char *in, size_t num) | ||
1234 | { | ||
1235 | STREEBOG_LONG64 M[8], l; | ||
1236 | int i; | ||
1237 | |||
1238 | for (i = 0; i < 8; i++) | ||
1239 | M[i] = PULL64(in[i*8]); | ||
1240 | |||
1241 | gN(ctx->h, M, ctx->N); | ||
1242 | |||
1243 | l = ctx->N[0]; | ||
1244 | ctx->N[0] += num; | ||
1245 | |||
1246 | if (ctx->N[0] < l || ctx->N[0] < num) { | ||
1247 | for (i = 1; i < 8; i++) { | ||
1248 | ctx->N[i]++; | ||
1249 | if (ctx->N[i] != 0) | ||
1250 | break; | ||
1251 | } | ||
1252 | } | ||
1253 | |||
1254 | ctx->Sigma[0] += M[0]; | ||
1255 | for (i = 1; i < 8; i++) | ||
1256 | if (ctx->Sigma[i-1] < M[i-1]) | ||
1257 | ctx->Sigma[i] += M[i] + 1; | ||
1258 | else | ||
1259 | ctx->Sigma[i] += M[i]; | ||
1260 | } | ||
1261 | |||
1262 | |||
1263 | |||
1264 | static void streebog_block_data_order(STREEBOG_CTX * ctx, const void *in, size_t num) | ||
1265 | { | ||
1266 | int i; | ||
1267 | for (i = 0; i < num; i++) | ||
1268 | streebog_single_block(ctx, in + i * STREEBOG_CBLOCK, 64 * 8); | ||
1269 | } | ||
1270 | |||
1271 | int STREEBOG512_Final(unsigned char *md, STREEBOG_CTX * c) | ||
1272 | { | ||
1273 | int n; | ||
1274 | unsigned char *p = (unsigned char *)c->data; | ||
1275 | STREEBOG_LONG64 Z[STREEBOG_LBLOCK] = {}; | ||
1276 | |||
1277 | if (c->num == STREEBOG_CBLOCK) { | ||
1278 | streebog_block_data_order(c, c->data, 1); | ||
1279 | c->num -= STREEBOG_CBLOCK; | ||
1280 | } | ||
1281 | |||
1282 | n = c->num; | ||
1283 | p[n++] = 1; | ||
1284 | memset(p+n, 0, STREEBOG_CBLOCK - n); | ||
1285 | |||
1286 | streebog_single_block(c, p, c->num * 8); | ||
1287 | |||
1288 | gN(c->h, c->N, Z); | ||
1289 | gN(c->h, c->Sigma, Z); | ||
1290 | |||
1291 | for (n = 0; n < STREEBOG_LBLOCK; n++) | ||
1292 | c->h[n] = SWAB64(c->h[n]); | ||
1293 | |||
1294 | if (md == 0) | ||
1295 | return 0; | ||
1296 | |||
1297 | switch (c->md_len) { | ||
1298 | /* Let compiler decide if it's appropriate to unroll... */ | ||
1299 | case STREEBOG256_LENGTH: | ||
1300 | for (n = 0; n < STREEBOG256_LENGTH / 8; n++) { | ||
1301 | STREEBOG_LONG64 t = c->h[4+n]; | ||
1302 | |||
1303 | *(md++) = (unsigned char)(t >> 56); | ||
1304 | *(md++) = (unsigned char)(t >> 48); | ||
1305 | *(md++) = (unsigned char)(t >> 40); | ||
1306 | *(md++) = (unsigned char)(t >> 32); | ||
1307 | *(md++) = (unsigned char)(t >> 24); | ||
1308 | *(md++) = (unsigned char)(t >> 16); | ||
1309 | *(md++) = (unsigned char)(t >> 8); | ||
1310 | *(md++) = (unsigned char)(t); | ||
1311 | } | ||
1312 | break; | ||
1313 | case STREEBOG512_LENGTH: | ||
1314 | for (n = 0; n < STREEBOG512_LENGTH / 8; n++) { | ||
1315 | STREEBOG_LONG64 t = c->h[n]; | ||
1316 | |||
1317 | *(md++) = (unsigned char)(t >> 56); | ||
1318 | *(md++) = (unsigned char)(t >> 48); | ||
1319 | *(md++) = (unsigned char)(t >> 40); | ||
1320 | *(md++) = (unsigned char)(t >> 32); | ||
1321 | *(md++) = (unsigned char)(t >> 24); | ||
1322 | *(md++) = (unsigned char)(t >> 16); | ||
1323 | *(md++) = (unsigned char)(t >> 8); | ||
1324 | *(md++) = (unsigned char)(t); | ||
1325 | } | ||
1326 | break; | ||
1327 | /* ... as well as make sure md_len is not abused. */ | ||
1328 | default: | ||
1329 | return 0; | ||
1330 | } | ||
1331 | |||
1332 | return 1; | ||
1333 | } | ||
1334 | |||
1335 | int STREEBOG256_Final(unsigned char *md, STREEBOG_CTX * c) | ||
1336 | { | ||
1337 | return STREEBOG512_Final(md, c); | ||
1338 | } | ||
1339 | |||
1340 | int STREEBOG512_Update(STREEBOG_CTX * c, const void *_data, size_t len) | ||
1341 | { | ||
1342 | unsigned char *p = (unsigned char *)c->data; | ||
1343 | const unsigned char *data = (const unsigned char *)_data; | ||
1344 | |||
1345 | if (len == 0) | ||
1346 | return 1; | ||
1347 | |||
1348 | if (c->num != 0) { | ||
1349 | size_t n = STREEBOG_CBLOCK - c->num; | ||
1350 | |||
1351 | if (len < n) { | ||
1352 | memcpy(p + c->num, data, len); | ||
1353 | c->num += (unsigned int)len; | ||
1354 | return 1; | ||
1355 | } else { | ||
1356 | memcpy(p + c->num, data, n); | ||
1357 | c->num = 0; | ||
1358 | len -= n; | ||
1359 | data += n; | ||
1360 | streebog_block_data_order(c, p, 1); | ||
1361 | } | ||
1362 | } | ||
1363 | |||
1364 | if (len >= STREEBOG_CBLOCK) { | ||
1365 | streebog_block_data_order(c, data, len / STREEBOG_CBLOCK); | ||
1366 | data += len; | ||
1367 | len %= STREEBOG_CBLOCK; | ||
1368 | data -= len; | ||
1369 | } | ||
1370 | |||
1371 | if (len != 0) { | ||
1372 | memcpy(p, data, len); | ||
1373 | c->num = (int)len; | ||
1374 | } | ||
1375 | |||
1376 | return 1; | ||
1377 | } | ||
1378 | |||
1379 | int STREEBOG256_Update(STREEBOG_CTX * c, const void *data, size_t len) | ||
1380 | { | ||
1381 | return STREEBOG512_Update(c, data, len); | ||
1382 | } | ||
1383 | |||
1384 | void STREEBOG512_Transform(STREEBOG_CTX * c, const unsigned char *data) | ||
1385 | { | ||
1386 | streebog_block_data_order(c, data, 1); | ||
1387 | } | ||
1388 | |||
1389 | int STREEBOG256_Init(STREEBOG_CTX * c) | ||
1390 | { | ||
1391 | memset(c, 0, sizeof(*c)); | ||
1392 | memset(c->h, 1, sizeof(c->h)); | ||
1393 | |||
1394 | c->md_len = STREEBOG256_LENGTH; | ||
1395 | return 1; | ||
1396 | } | ||
1397 | |||
1398 | int STREEBOG512_Init(STREEBOG_CTX * c) | ||
1399 | { | ||
1400 | memset(c, 0, sizeof(*c)); | ||
1401 | memset(c->h, 0, sizeof(c->h)); | ||
1402 | |||
1403 | c->num = 0; | ||
1404 | c->md_len = STREEBOG512_LENGTH; | ||
1405 | return 1; | ||
1406 | } | ||
1407 | |||
1408 | unsigned char *STREEBOG256(const unsigned char *d, size_t n, unsigned char *md) | ||
1409 | { | ||
1410 | STREEBOG_CTX c; | ||
1411 | static unsigned char m[STREEBOG256_LENGTH]; | ||
1412 | |||
1413 | if (md == NULL) | ||
1414 | md = m; | ||
1415 | STREEBOG256_Init(&c); | ||
1416 | STREEBOG256_Update(&c, d, n); | ||
1417 | STREEBOG256_Final(md, &c); | ||
1418 | OPENSSL_cleanse(&c, sizeof(c)); | ||
1419 | return (md); | ||
1420 | } | ||
1421 | |||
1422 | unsigned char *STREEBOG512(const unsigned char *d, size_t n, unsigned char *md) | ||
1423 | { | ||
1424 | STREEBOG_CTX c; | ||
1425 | static unsigned char m[STREEBOG512_LENGTH]; | ||
1426 | |||
1427 | if (md == NULL) | ||
1428 | md = m; | ||
1429 | STREEBOG512_Init(&c); | ||
1430 | STREEBOG512_Update(&c, d, n); | ||
1431 | STREEBOG512_Final(md, &c); | ||
1432 | OPENSSL_cleanse(&c, sizeof(c)); | ||
1433 | return (md); | ||
1434 | } | ||
1435 | |||
1436 | #endif | ||
diff --git a/src/lib/libssl/src/crypto/objects/obj_mac.num b/src/lib/libssl/src/crypto/objects/obj_mac.num index bcdda5163e..d3a658e59c 100644 --- a/src/lib/libssl/src/crypto/objects/obj_mac.num +++ b/src/lib/libssl/src/crypto/objects/obj_mac.num | |||
@@ -935,3 +935,15 @@ brainpoolP512r1 934 | |||
935 | brainpoolP512t1 935 | 935 | brainpoolP512t1 935 |
936 | FRP256v1 936 | 936 | FRP256v1 936 |
937 | chacha20 937 | 937 | chacha20 937 |
938 | gost89_ecb 938 | ||
939 | gost89_cbc 939 | ||
940 | tc26 940 | ||
941 | id_tc26_gost3411_2012_256 941 | ||
942 | id_tc26_gost3411_2012_512 942 | ||
943 | id_tc26_gost_3410_2012_512_paramSetA 943 | ||
944 | id_tc26_gost_3410_2012_512_paramSetB 944 | ||
945 | id_tc26_gost_28147_param_Z 945 | ||
946 | id_tc26_gost3410_2012_256 946 | ||
947 | id_tc26_gost3410_2012_512 947 | ||
948 | id_tc26_signwithdigest_gost3410_2012_256 948 | ||
949 | id_tc26_signwithdigest_gost3410_2012_512 949 | ||
diff --git a/src/lib/libssl/src/crypto/objects/obj_xref.h b/src/lib/libssl/src/crypto/objects/obj_xref.h index fec28d1127..4499456694 100644 --- a/src/lib/libssl/src/crypto/objects/obj_xref.h +++ b/src/lib/libssl/src/crypto/objects/obj_xref.h | |||
@@ -1,4 +1,4 @@ | |||
1 | /* $OpenBSD: obj_xref.h,v 1.2 2014/06/12 15:49:30 deraadt Exp $ */ | 1 | /* $OpenBSD: obj_xref.h,v 1.3 2014/11/09 19:17:13 miod Exp $ */ |
2 | /* AUTOGENERATED BY objxref.pl, DO NOT EDIT */ | 2 | /* AUTOGENERATED BY objxref.pl, DO NOT EDIT */ |
3 | 3 | ||
4 | typedef struct | 4 | typedef struct |
@@ -40,6 +40,8 @@ static const nid_triple sigoid_srt[] = | |||
40 | {NID_id_GostR3411_94_with_GostR3410_94_cc, NID_id_GostR3411_94, NID_id_GostR3410_94_cc}, | 40 | {NID_id_GostR3411_94_with_GostR3410_94_cc, NID_id_GostR3411_94, NID_id_GostR3410_94_cc}, |
41 | {NID_id_GostR3411_94_with_GostR3410_2001_cc, NID_id_GostR3411_94, NID_id_GostR3410_2001_cc}, | 41 | {NID_id_GostR3411_94_with_GostR3410_2001_cc, NID_id_GostR3411_94, NID_id_GostR3410_2001_cc}, |
42 | {NID_rsassaPss, NID_undef, NID_rsaEncryption}, | 42 | {NID_rsassaPss, NID_undef, NID_rsaEncryption}, |
43 | {NID_id_tc26_signwithdigest_gost3410_2012_256, NID_id_tc26_gost3411_2012_256, NID_id_GostR3410_2001}, | ||
44 | {NID_id_tc26_signwithdigest_gost3410_2012_512, NID_id_tc26_gost3411_2012_512, NID_id_GostR3410_2001}, | ||
43 | }; | 45 | }; |
44 | 46 | ||
45 | static const nid_triple * const sigoid_srt_xref[] = | 47 | static const nid_triple * const sigoid_srt_xref[] = |
@@ -74,5 +76,7 @@ static const nid_triple * const sigoid_srt_xref[] = | |||
74 | &sigoid_srt[26], | 76 | &sigoid_srt[26], |
75 | &sigoid_srt[27], | 77 | &sigoid_srt[27], |
76 | &sigoid_srt[28], | 78 | &sigoid_srt[28], |
79 | &sigoid_srt[30], | ||
80 | &sigoid_srt[31], | ||
77 | }; | 81 | }; |
78 | 82 | ||
diff --git a/src/lib/libssl/src/crypto/objects/obj_xref.txt b/src/lib/libssl/src/crypto/objects/obj_xref.txt index cb917182ee..dde52d8143 100644 --- a/src/lib/libssl/src/crypto/objects/obj_xref.txt +++ b/src/lib/libssl/src/crypto/objects/obj_xref.txt | |||
@@ -44,3 +44,5 @@ id_GostR3411_94_with_GostR3410_2001 id_GostR3411_94 id_GostR3410_2001 | |||
44 | id_GostR3411_94_with_GostR3410_94 id_GostR3411_94 id_GostR3410_94 | 44 | id_GostR3411_94_with_GostR3410_94 id_GostR3411_94 id_GostR3410_94 |
45 | id_GostR3411_94_with_GostR3410_94_cc id_GostR3411_94 id_GostR3410_94_cc | 45 | id_GostR3411_94_with_GostR3410_94_cc id_GostR3411_94 id_GostR3410_94_cc |
46 | id_GostR3411_94_with_GostR3410_2001_cc id_GostR3411_94 id_GostR3410_2001_cc | 46 | id_GostR3411_94_with_GostR3410_2001_cc id_GostR3411_94 id_GostR3410_2001_cc |
47 | id_tc26_signwithdigest_gost3410_2012_256 id_tc26_gost3411_2012_256 id_tc26_gost3410_2012_256 | ||
48 | id_tc26_signwithdigest_gost3410_2012_512 id_tc26_gost3411_2012_512 id_tc26_gost3410_2012_512 | ||
diff --git a/src/lib/libssl/src/crypto/objects/objects.txt b/src/lib/libssl/src/crypto/objects/objects.txt index bb44aa77a3..1ce73cc984 100644 --- a/src/lib/libssl/src/crypto/objects/objects.txt +++ b/src/lib/libssl/src/crypto/objects/objects.txt | |||
@@ -1313,3 +1313,18 @@ brainpool 1 14 : brainpoolP512t1 | |||
1313 | # ChaCha Stream Cipher | 1313 | # ChaCha Stream Cipher |
1314 | !Cname chacha20 | 1314 | !Cname chacha20 |
1315 | : ChaCha : chacha | 1315 | : ChaCha : chacha |
1316 | : gost89-ecb | ||
1317 | : gost89-cbc | ||
1318 | |||
1319 | member-body 643 7 1 : tc26 | ||
1320 | !Cname id-tc26-gost3411-2012-256 | ||
1321 | tc26 1 2 2 : streebog256 : GOST R 34.11-2012 (256 bit) | ||
1322 | !Cname id-tc26-gost3411-2012-512 | ||
1323 | tc26 1 2 3 : streebog512 : GOST R 34-11-2012 (512 bit) | ||
1324 | tc26 2 1 2 1 : id-tc26-gost-3410-2012-512-paramSetA | ||
1325 | tc26 2 1 2 2 : id-tc26-gost-3410-2012-512-paramSetB | ||
1326 | tc26 2 5 1 1 : id-tc26-gost-28147-param-Z | ||
1327 | tc26 1 1 1 : id-tc26-gost3410-2012-256 : GOST R 34.10-2012 (256 bit) | ||
1328 | tc26 1 1 2 : id-tc26-gost3410-2012-512 : GOST R 34.10-2012 (512 bit) | ||
1329 | tc26 1 3 2 : id-tc26-signwithdigest-gost3410-2012-256 : GOST R 34.11-2012 with GOST R 34.10-2012 (256 bit) | ||
1330 | tc26 1 3 3 : id-tc26-signwithdigest-gost3410-2012-512 : GOST R 34.11-2012 with GOST R 34.10-2012 (512 bit) | ||
diff --git a/src/lib/libssl/src/crypto/pkcs7/pk7_smime.c b/src/lib/libssl/src/crypto/pkcs7/pk7_smime.c index b76e2b1915..576866f5c2 100644 --- a/src/lib/libssl/src/crypto/pkcs7/pk7_smime.c +++ b/src/lib/libssl/src/crypto/pkcs7/pk7_smime.c | |||
@@ -1,4 +1,4 @@ | |||
1 | /* $OpenBSD: pk7_smime.c,v 1.18 2014/07/11 08:44:49 jsing Exp $ */ | 1 | /* $OpenBSD: pk7_smime.c,v 1.19 2014/11/09 19:17:13 miod Exp $ */ |
2 | /* Written by Dr Stephen N Henson (steve@openssl.org) for the OpenSSL | 2 | /* Written by Dr Stephen N Henson (steve@openssl.org) for the OpenSSL |
3 | * project. | 3 | * project. |
4 | */ | 4 | */ |
@@ -192,6 +192,8 @@ PKCS7_sign_add_signer(PKCS7 *p7, X509 *signcert, EVP_PKEY *pkey, | |||
192 | } | 192 | } |
193 | if (!add_cipher_smcap(smcap, NID_aes_256_cbc, -1) || | 193 | if (!add_cipher_smcap(smcap, NID_aes_256_cbc, -1) || |
194 | !add_digest_smcap(smcap, NID_id_GostR3411_94, -1) || | 194 | !add_digest_smcap(smcap, NID_id_GostR3411_94, -1) || |
195 | !add_digest_smcap(smcap, NID_id_tc26_gost3411_2012_256, -1) || | ||
196 | !add_digest_smcap(smcap, NID_id_tc26_gost3411_2012_512, -1) || | ||
195 | !add_cipher_smcap(smcap, NID_id_Gost28147_89, -1) || | 197 | !add_cipher_smcap(smcap, NID_id_Gost28147_89, -1) || |
196 | !add_cipher_smcap(smcap, NID_aes_192_cbc, -1) || | 198 | !add_cipher_smcap(smcap, NID_aes_192_cbc, -1) || |
197 | !add_cipher_smcap(smcap, NID_aes_128_cbc, -1) || | 199 | !add_cipher_smcap(smcap, NID_aes_128_cbc, -1) || |