summaryrefslogtreecommitdiff
path: root/src/lib/libcrypto/evp
diff options
context:
space:
mode:
Diffstat (limited to 'src/lib/libcrypto/evp')
-rw-r--r--src/lib/libcrypto/evp/c_allc.c8
-rw-r--r--src/lib/libcrypto/evp/c_alld.c8
-rw-r--r--src/lib/libcrypto/evp/e_gost2814789.c216
-rw-r--r--src/lib/libcrypto/evp/evp.h35
-rw-r--r--src/lib/libcrypto/evp/m_gost2814789.c105
-rw-r--r--src/lib/libcrypto/evp/m_gostr341194.c93
-rw-r--r--src/lib/libcrypto/evp/m_streebog.c125
-rw-r--r--src/lib/libcrypto/evp/pmeth_lib.c9
8 files changed, 594 insertions, 5 deletions
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
61typedef struct {
62 GOST2814789_KEY ks;
63 int param_nid;
64} EVP_GOST2814789_CTX;
65
66static 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
89static 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
97int 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
140int 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
179BLOCK_CIPHER_func_ecb(gost2814789, Gost2814789, EVP_GOST2814789_CTX, ks)
180BLOCK_CIPHER_func_cfb(gost2814789, Gost2814789, 64, EVP_GOST2814789_CTX, ks)
181
182static 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
204BLOCK_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)
208BLOCK_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)
212BLOCK_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
114extern "C" { 118extern "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);
530int EVP_MD_CTX_copy_ex(EVP_MD_CTX *out, const EVP_MD_CTX *in); 546int EVP_MD_CTX_copy_ex(EVP_MD_CTX *out, const EVP_MD_CTX *in);
531void EVP_MD_CTX_set_flags(EVP_MD_CTX *ctx, int flags); 547void EVP_MD_CTX_set_flags(EVP_MD_CTX *ctx, int flags);
532void EVP_MD_CTX_clear_flags(EVP_MD_CTX *ctx, int flags); 548void EVP_MD_CTX_clear_flags(EVP_MD_CTX *ctx, int flags);
549int EVP_MD_CTX_ctrl(EVP_MD_CTX *ctx, int type, int arg, void *ptr);
533int EVP_MD_CTX_test_flags(const EVP_MD_CTX *ctx, int flags); 550int EVP_MD_CTX_test_flags(const EVP_MD_CTX *ctx, int flags);
534int EVP_DigestInit_ex(EVP_MD_CTX *ctx, const EVP_MD *type, ENGINE *impl); 551int EVP_DigestInit_ex(EVP_MD_CTX *ctx, const EVP_MD *type, ENGINE *impl);
535int EVP_DigestUpdate(EVP_MD_CTX *ctx, const void *d, size_t cnt); 552int 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
666const EVP_MD *EVP_whirlpool(void); 683const EVP_MD *EVP_whirlpool(void);
667#endif 684#endif
685#ifndef OPENSSL_NO_GOST
686const EVP_MD *EVP_gostr341194(void);
687const EVP_MD *EVP_gost2814789imit(void);
688const EVP_MD *EVP_streebog256(void);
689const EVP_MD *EVP_streebog512(void);
690#endif
668const EVP_CIPHER *EVP_enc_null(void); /* does nothing :-) */ 691const EVP_CIPHER *EVP_enc_null(void); /* does nothing :-) */
669#ifndef OPENSSL_NO_DES 692#ifndef OPENSSL_NO_DES
670const EVP_CIPHER *EVP_des_ecb(void); 693const EVP_CIPHER *EVP_des_ecb(void);
@@ -804,6 +827,12 @@ const EVP_CIPHER *EVP_camellia_256_ofb(void);
804const EVP_CIPHER *EVP_chacha20(void); 827const EVP_CIPHER *EVP_chacha20(void);
805#endif 828#endif
806 829
830#ifndef OPENSSL_NO_GOST
831const EVP_CIPHER *EVP_gost2814789_ecb(void);
832const EVP_CIPHER *EVP_gost2814789_cfb64(void);
833const EVP_CIPHER *EVP_gost2814789_cnt(void);
834#endif
835
807void OPENSSL_add_all_algorithms_noconf(void); 836void OPENSSL_add_all_algorithms_noconf(void);
808void OPENSSL_add_all_algorithms_conf(void); 837void OPENSSL_add_all_algorithms_conf(void);
809 838
@@ -871,6 +900,9 @@ struct ec_key_st;
871int EVP_PKEY_set1_EC_KEY(EVP_PKEY *pkey, struct ec_key_st *key); 900int EVP_PKEY_set1_EC_KEY(EVP_PKEY *pkey, struct ec_key_st *key);
872struct ec_key_st *EVP_PKEY_get1_EC_KEY(EVP_PKEY *pkey); 901struct ec_key_st *EVP_PKEY_get1_EC_KEY(EVP_PKEY *pkey);
873#endif 902#endif
903#ifndef OPENSSL_NO_GOST
904struct gost_key_st;
905#endif
874 906
875EVP_PKEY *EVP_PKEY_new(void); 907EVP_PKEY *EVP_PKEY_new(void);
876void EVP_PKEY_free(EVP_PKEY *pkey); 908void 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
59static int init(EVP_MD_CTX *ctx)
60{
61 return GOST2814789IMIT_Init(ctx->md_data, NID_id_Gost28147_89_CryptoPro_A_ParamSet);
62}
63
64static int update(EVP_MD_CTX *ctx, const void *data, size_t count)
65{
66 return GOST2814789IMIT_Update(ctx->md_data, data, count);
67}
68
69static int final(EVP_MD_CTX *ctx, unsigned char *md)
70{
71 return GOST2814789IMIT_Final(md, ctx->md_data);
72}
73
74static 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
87static 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
100const EVP_MD *
101EVP_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
61static int init(EVP_MD_CTX *ctx)
62{
63 return GOSTR341194_Init(ctx->md_data, NID_id_GostR3411_94_CryptoProParamSet);
64}
65
66static int update(EVP_MD_CTX *ctx, const void *data, size_t count)
67{
68 return GOSTR341194_Update(ctx->md_data, data, count);
69}
70
71static int final(EVP_MD_CTX *ctx, unsigned char *md)
72{
73 return GOSTR341194_Final(md, ctx->md_data);
74}
75
76static 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
88const EVP_MD *
89EVP_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
60static int init256(EVP_MD_CTX *ctx)
61{
62 return STREEBOG256_Init(ctx->md_data);
63}
64
65static int update256(EVP_MD_CTX *ctx, const void *data, size_t count)
66{
67 return STREEBOG256_Update(ctx->md_data, data, count);
68}
69
70static int final256(EVP_MD_CTX *ctx, unsigned char *md)
71{
72 return STREEBOG256_Final(md, ctx->md_data);
73}
74
75static int init512(EVP_MD_CTX *ctx)
76{
77 return STREEBOG512_Init(ctx->md_data);
78}
79
80static int update512(EVP_MD_CTX *ctx, const void *data, size_t count)
81{
82 return STREEBOG512_Update(ctx->md_data, data, count);
83}
84
85static int final512(EVP_MD_CTX *ctx, unsigned char *md)
86{
87 return STREEBOG512_Final(md, ctx->md_data);
88}
89
90static 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
102static 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
114const EVP_MD *
115EVP_streebog256(void)
116{
117 return (&streebog256_md);
118}
119
120const EVP_MD *
121EVP_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
80extern const EVP_PKEY_METHOD rsa_pkey_meth, dh_pkey_meth, dsa_pkey_meth; 80extern const EVP_PKEY_METHOD rsa_pkey_meth, dh_pkey_meth, dsa_pkey_meth;
81extern const EVP_PKEY_METHOD ec_pkey_meth, hmac_pkey_meth, cmac_pkey_meth; 81extern const EVP_PKEY_METHOD ec_pkey_meth, hmac_pkey_meth, cmac_pkey_meth;
82extern const EVP_PKEY_METHOD gostimit_pkey_meth, gostr01_pkey_meth;
82 83
83static const EVP_PKEY_METHOD *standard_methods[] = { 84static 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
100DECLARE_OBJ_BSEARCH_CMP_FN(const EVP_PKEY_METHOD *, const EVP_PKEY_METHOD *, 105DECLARE_OBJ_BSEARCH_CMP_FN(const EVP_PKEY_METHOD *, const EVP_PKEY_METHOD *,