summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authortb <>2022-01-14 08:04:14 +0000
committertb <>2022-01-14 08:04:14 +0000
commit2937a039a92eb7f2f17179de8df55799204e6141 (patch)
treee6c9c95b7894bbe0a42a0f0d771270850f565812 /src
parent086a3376c584abf6d0f6e827e4dc60484eb236d2 (diff)
downloadopenbsd-2937a039a92eb7f2f17179de8df55799204e6141.tar.gz
openbsd-2937a039a92eb7f2f17179de8df55799204e6141.tar.bz2
openbsd-2937a039a92eb7f2f17179de8df55799204e6141.zip
Make structs in evp.h and hmac.h opaque
This moves most structs to evp_locl.h and moves HMAC_CTX to hmac_local.h. ok inoguchi jsing
Diffstat (limited to 'src')
-rw-r--r--src/lib/libcrypto/evp/evp.h135
-rw-r--r--src/lib/libcrypto/evp/evp_locl.h130
-rw-r--r--src/lib/libcrypto/hmac/hmac.h12
-rw-r--r--src/lib/libcrypto/hmac/hmac_local.h11
4 files changed, 142 insertions, 146 deletions
diff --git a/src/lib/libcrypto/evp/evp.h b/src/lib/libcrypto/evp/evp.h
index 012b06befc..acf0650f9a 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.97 2022/01/14 07:49:49 tb Exp $ */ 1/* $OpenBSD: evp.h,v 1.98 2022/01/14 08:04:14 tb 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 *
@@ -119,72 +119,12 @@
119extern "C" { 119extern "C" {
120#endif 120#endif
121 121
122/* Move to evp_locl.h */
123/* Type needs to be a bit field
124 * Sub-type needs to be for variations on the method, as in, can it do
125 * arbitrary encryption.... */
126struct evp_pkey_st {
127 int type;
128 int save_type;
129 int references;
130 const EVP_PKEY_ASN1_METHOD *ameth;
131 ENGINE *engine;
132 union {
133 char *ptr;
134#ifndef OPENSSL_NO_RSA
135 struct rsa_st *rsa; /* RSA */
136#endif
137#ifndef OPENSSL_NO_DSA
138 struct dsa_st *dsa; /* DSA */
139#endif
140#ifndef OPENSSL_NO_DH
141 struct dh_st *dh; /* DH */
142#endif
143#ifndef OPENSSL_NO_EC
144 struct ec_key_st *ec; /* ECC */
145#endif
146#ifndef OPENSSL_NO_GOST
147 struct gost_key_st *gost; /* GOST */
148#endif
149 } pkey;
150 int save_parameters;
151 STACK_OF(X509_ATTRIBUTE) *attributes; /* [ 0 ] */
152} /* EVP_PKEY */;
153
154#define EVP_PKEY_MO_SIGN 0x0001 122#define EVP_PKEY_MO_SIGN 0x0001
155#define EVP_PKEY_MO_VERIFY 0x0002 123#define EVP_PKEY_MO_VERIFY 0x0002
156#define EVP_PKEY_MO_ENCRYPT 0x0004 124#define EVP_PKEY_MO_ENCRYPT 0x0004
157#define EVP_PKEY_MO_DECRYPT 0x0008 125#define EVP_PKEY_MO_DECRYPT 0x0008
158 126
159typedef int evp_sign_method(int type, const unsigned char *m,
160 unsigned int m_length, unsigned char *sigret, unsigned int *siglen,
161 void *key);
162typedef int evp_verify_method(int type, const unsigned char *m,
163 unsigned int m_length, const unsigned char *sigbuf, unsigned int siglen,
164 void *key);
165
166#ifndef EVP_MD 127#ifndef EVP_MD
167/* Move to evp_locl.h */
168struct env_md_st {
169 int type;
170 int pkey_type;
171 int md_size;
172 unsigned long flags;
173 int (*init)(EVP_MD_CTX *ctx);
174 int (*update)(EVP_MD_CTX *ctx, const void *data, size_t count);
175 int (*final)(EVP_MD_CTX *ctx, unsigned char *md);
176 int (*copy)(EVP_MD_CTX *to, const EVP_MD_CTX *from);
177 int (*cleanup)(EVP_MD_CTX *ctx);
178
179 evp_sign_method *sign;
180 evp_verify_method *verify;
181 int required_pkey_type[5]; /*EVP_PKEY_xxx */
182 int block_size;
183 int ctx_size; /* how big does the ctx->md_data need to be */
184 /* control function */
185 int (*md_ctrl)(EVP_MD_CTX *ctx, int cmd, int p1, void *p2);
186} /* EVP_MD */;
187
188#define EVP_MD_FLAG_ONESHOT 0x0001 /* digest can only handle a single 128#define EVP_MD_FLAG_ONESHOT 0x0001 /* digest can only handle a single
189 * block */ 129 * block */
190 130
@@ -260,18 +200,6 @@ struct env_md_st {
260 200
261#endif /* !EVP_MD */ 201#endif /* !EVP_MD */
262 202
263/* Move to evp_locl.h. */
264struct env_md_ctx_st {
265 const EVP_MD *digest;
266 ENGINE *engine; /* functional reference if 'digest' is ENGINE-provided */
267 unsigned long flags;
268 void *md_data;
269 /* Public key context for sign/verify */
270 EVP_PKEY_CTX *pctx;
271 /* Update function: usually copied from EVP_MD */
272 int (*update)(EVP_MD_CTX *ctx, const void *data, size_t count);
273} /* EVP_MD_CTX */;
274
275/* values for EVP_MD_CTX flags */ 203/* values for EVP_MD_CTX flags */
276 204
277#define EVP_MD_CTX_FLAG_ONESHOT 0x0001 /* digest update will be called 205#define EVP_MD_CTX_FLAG_ONESHOT 0x0001 /* digest update will be called
@@ -298,25 +226,6 @@ struct env_md_ctx_st {
298 226
299#define EVP_MD_CTX_FLAG_NO_INIT 0x0100 /* Don't initialize md_data */ 227#define EVP_MD_CTX_FLAG_NO_INIT 0x0100 /* Don't initialize md_data */
300 228
301/* Move to evp_locl.h */
302struct evp_cipher_st {
303 int nid;
304 int block_size;
305 int key_len; /* Default value for variable length ciphers */
306 int iv_len;
307 unsigned long flags; /* Various flags */
308 int (*init)(EVP_CIPHER_CTX *ctx, const unsigned char *key,
309 const unsigned char *iv, int enc); /* init key */
310 int (*do_cipher)(EVP_CIPHER_CTX *ctx, unsigned char *out,
311 const unsigned char *in, size_t inl);/* encrypt/decrypt data */
312 int (*cleanup)(EVP_CIPHER_CTX *); /* cleanup ctx */
313 int ctx_size; /* how big ctx->cipher_data needs to be */
314 int (*set_asn1_parameters)(EVP_CIPHER_CTX *, ASN1_TYPE *); /* Populate a ASN1_TYPE with parameters */
315 int (*get_asn1_parameters)(EVP_CIPHER_CTX *, ASN1_TYPE *); /* Get parameters from a ASN1_TYPE */
316 int (*ctrl)(EVP_CIPHER_CTX *, int type, int arg, void *ptr); /* Miscellaneous operations */
317 void *app_data; /* Application data */
318} /* EVP_CIPHER */;
319
320/* Values for cipher flags */ 229/* Values for cipher flags */
321 230
322/* Modes for ciphers */ 231/* Modes for ciphers */
@@ -417,41 +326,6 @@ typedef struct evp_cipher_info_st {
417 unsigned char iv[EVP_MAX_IV_LENGTH]; 326 unsigned char iv[EVP_MAX_IV_LENGTH];
418} EVP_CIPHER_INFO; 327} EVP_CIPHER_INFO;
419 328
420/* Move to evp_locl.h */
421struct evp_cipher_ctx_st {
422 const EVP_CIPHER *cipher;
423 ENGINE *engine; /* functional reference if 'cipher' is ENGINE-provided */
424 int encrypt; /* encrypt or decrypt */
425 int buf_len; /* number we have left */
426
427 unsigned char oiv[EVP_MAX_IV_LENGTH]; /* original iv */
428 unsigned char iv[EVP_MAX_IV_LENGTH]; /* working iv */
429 unsigned char buf[EVP_MAX_BLOCK_LENGTH];/* saved partial block */
430 int num; /* used by cfb/ofb/ctr mode */
431
432 void *app_data; /* application stuff */
433 int key_len; /* May change for variable length cipher */
434 unsigned long flags; /* Various flags */
435 void *cipher_data; /* per EVP data */
436 int final_used;
437 int block_mask;
438 unsigned char final[EVP_MAX_BLOCK_LENGTH];/* possible final block */
439} /* EVP_CIPHER_CTX */;
440
441/* Move to evp_locl.h */
442struct evp_Encode_Ctx_st {
443
444 int num; /* number saved in a partial encode/decode */
445 int length; /* The length is either the output line length
446 * (in input bytes) or the shortest input line
447 * length that is ok. Once decoding begins,
448 * the length is adjusted up each time a longer
449 * line is decoded */
450 unsigned char enc_data[80]; /* data to encode */
451 int line_num; /* number read on current line */
452 int expect_nl;
453} /* EVP_ENCODE_CTX */;
454
455/* Password based encryption function */ 329/* Password based encryption function */
456typedef int (EVP_PBE_KEYGEN)(EVP_CIPHER_CTX *ctx, const char *pass, int passlen, 330typedef int (EVP_PBE_KEYGEN)(EVP_CIPHER_CTX *ctx, const char *pass, int passlen,
457 ASN1_TYPE *param, const EVP_CIPHER *cipher, const EVP_MD *md, int en_de); 331 ASN1_TYPE *param, const EVP_CIPHER *cipher, const EVP_MD *md, int en_de);
@@ -1317,7 +1191,6 @@ void EVP_PKEY_meth_set_param_check(EVP_PKEY_METHOD *pmeth,
1317 * message has a unique, per-message nonce and, optionally, additional data 1191 * message has a unique, per-message nonce and, optionally, additional data
1318 * which is authenticated but not included in the output. */ 1192 * which is authenticated but not included in the output. */
1319 1193
1320struct evp_aead_st;
1321typedef struct evp_aead_st EVP_AEAD; 1194typedef struct evp_aead_st EVP_AEAD;
1322 1195
1323#ifndef OPENSSL_NO_AES 1196#ifndef OPENSSL_NO_AES
@@ -1351,11 +1224,7 @@ size_t EVP_AEAD_max_tag_len(const EVP_AEAD *aead);
1351 1224
1352/* An EVP_AEAD_CTX represents an AEAD algorithm configured with a specific key 1225/* An EVP_AEAD_CTX represents an AEAD algorithm configured with a specific key
1353 * and message-independent IV. */ 1226 * and message-independent IV. */
1354typedef struct evp_aead_ctx_st { 1227typedef struct evp_aead_ctx_st EVP_AEAD_CTX;
1355 const EVP_AEAD *aead;
1356 /* aead_state is an opaque pointer to the AEAD specific state. */
1357 void *aead_state;
1358} EVP_AEAD_CTX;
1359 1228
1360/* EVP_AEAD_MAX_TAG_LENGTH is the maximum tag length used by any AEAD 1229/* EVP_AEAD_MAX_TAG_LENGTH is the maximum tag length used by any AEAD
1361 * defined in this header. */ 1230 * defined in this header. */
diff --git a/src/lib/libcrypto/evp/evp_locl.h b/src/lib/libcrypto/evp/evp_locl.h
index 44e2d5cadb..f0b47a497c 100644
--- a/src/lib/libcrypto/evp/evp_locl.h
+++ b/src/lib/libcrypto/evp/evp_locl.h
@@ -1,4 +1,4 @@
1/* $OpenBSD: evp_locl.h,v 1.20 2022/01/10 12:10:26 tb Exp $ */ 1/* $OpenBSD: evp_locl.h,v 1.21 2022/01/14 08:04:14 tb 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 2000. 3 * project 2000.
4 */ 4 */
@@ -67,6 +67,126 @@ __BEGIN_HIDDEN_DECLS
67 */ 67 */
68#define EVP_MD_CTX_FLAG_KEEP_PKEY_CTX 0x0400 68#define EVP_MD_CTX_FLAG_KEEP_PKEY_CTX 0x0400
69 69
70typedef int evp_sign_method(int type, const unsigned char *m,
71 unsigned int m_length, unsigned char *sigret, unsigned int *siglen,
72 void *key);
73typedef int evp_verify_method(int type, const unsigned char *m,
74 unsigned int m_length, const unsigned char *sigbuf, unsigned int siglen,
75 void *key);
76
77/* Type needs to be a bit field
78 * Sub-type needs to be for variations on the method, as in, can it do
79 * arbitrary encryption.... */
80struct evp_pkey_st {
81 int type;
82 int save_type;
83 int references;
84 const EVP_PKEY_ASN1_METHOD *ameth;
85 ENGINE *engine;
86 union {
87 char *ptr;
88#ifndef OPENSSL_NO_RSA
89 struct rsa_st *rsa; /* RSA */
90#endif
91#ifndef OPENSSL_NO_DSA
92 struct dsa_st *dsa; /* DSA */
93#endif
94#ifndef OPENSSL_NO_DH
95 struct dh_st *dh; /* DH */
96#endif
97#ifndef OPENSSL_NO_EC
98 struct ec_key_st *ec; /* ECC */
99#endif
100#ifndef OPENSSL_NO_GOST
101 struct gost_key_st *gost; /* GOST */
102#endif
103 } pkey;
104 int save_parameters;
105 STACK_OF(X509_ATTRIBUTE) *attributes; /* [ 0 ] */
106} /* EVP_PKEY */;
107
108struct env_md_st {
109 int type;
110 int pkey_type;
111 int md_size;
112 unsigned long flags;
113 int (*init)(EVP_MD_CTX *ctx);
114 int (*update)(EVP_MD_CTX *ctx, const void *data, size_t count);
115 int (*final)(EVP_MD_CTX *ctx, unsigned char *md);
116 int (*copy)(EVP_MD_CTX *to, const EVP_MD_CTX *from);
117 int (*cleanup)(EVP_MD_CTX *ctx);
118
119 evp_sign_method *sign;
120 evp_verify_method *verify;
121 int required_pkey_type[5]; /*EVP_PKEY_xxx */
122 int block_size;
123 int ctx_size; /* how big does the ctx->md_data need to be */
124 /* control function */
125 int (*md_ctrl)(EVP_MD_CTX *ctx, int cmd, int p1, void *p2);
126} /* EVP_MD */;
127
128struct env_md_ctx_st {
129 const EVP_MD *digest;
130 ENGINE *engine; /* functional reference if 'digest' is ENGINE-provided */
131 unsigned long flags;
132 void *md_data;
133 /* Public key context for sign/verify */
134 EVP_PKEY_CTX *pctx;
135 /* Update function: usually copied from EVP_MD */
136 int (*update)(EVP_MD_CTX *ctx, const void *data, size_t count);
137} /* EVP_MD_CTX */;
138
139struct evp_cipher_st {
140 int nid;
141 int block_size;
142 int key_len; /* Default value for variable length ciphers */
143 int iv_len;
144 unsigned long flags; /* Various flags */
145 int (*init)(EVP_CIPHER_CTX *ctx, const unsigned char *key,
146 const unsigned char *iv, int enc); /* init key */
147 int (*do_cipher)(EVP_CIPHER_CTX *ctx, unsigned char *out,
148 const unsigned char *in, size_t inl);/* encrypt/decrypt data */
149 int (*cleanup)(EVP_CIPHER_CTX *); /* cleanup ctx */
150 int ctx_size; /* how big ctx->cipher_data needs to be */
151 int (*set_asn1_parameters)(EVP_CIPHER_CTX *, ASN1_TYPE *); /* Populate a ASN1_TYPE with parameters */
152 int (*get_asn1_parameters)(EVP_CIPHER_CTX *, ASN1_TYPE *); /* Get parameters from a ASN1_TYPE */
153 int (*ctrl)(EVP_CIPHER_CTX *, int type, int arg, void *ptr); /* Miscellaneous operations */
154 void *app_data; /* Application data */
155} /* EVP_CIPHER */;
156
157struct evp_cipher_ctx_st {
158 const EVP_CIPHER *cipher;
159 ENGINE *engine; /* functional reference if 'cipher' is ENGINE-provided */
160 int encrypt; /* encrypt or decrypt */
161 int buf_len; /* number we have left */
162
163 unsigned char oiv[EVP_MAX_IV_LENGTH]; /* original iv */
164 unsigned char iv[EVP_MAX_IV_LENGTH]; /* working iv */
165 unsigned char buf[EVP_MAX_BLOCK_LENGTH];/* saved partial block */
166 int num; /* used by cfb/ofb/ctr mode */
167
168 void *app_data; /* application stuff */
169 int key_len; /* May change for variable length cipher */
170 unsigned long flags; /* Various flags */
171 void *cipher_data; /* per EVP data */
172 int final_used;
173 int block_mask;
174 unsigned char final[EVP_MAX_BLOCK_LENGTH];/* possible final block */
175} /* EVP_CIPHER_CTX */;
176
177struct evp_Encode_Ctx_st {
178
179 int num; /* number saved in a partial encode/decode */
180 int length; /* The length is either the output line length
181 * (in input bytes) or the shortest input line
182 * length that is ok. Once decoding begins,
183 * the length is adjusted up each time a longer
184 * line is decoded */
185 unsigned char enc_data[80]; /* data to encode */
186 int line_num; /* number read on current line */
187 int expect_nl;
188} /* EVP_ENCODE_CTX */;
189
70/* Macros to code block cipher wrappers */ 190/* Macros to code block cipher wrappers */
71 191
72/* Wrapper functions for each cipher mode */ 192/* Wrapper functions for each cipher mode */
@@ -380,6 +500,14 @@ struct evp_aead_st {
380 const unsigned char *ad, size_t ad_len); 500 const unsigned char *ad, size_t ad_len);
381}; 501};
382 502
503/* An EVP_AEAD_CTX represents an AEAD algorithm configured with a specific key
504 * and message-independent IV. */
505struct evp_aead_ctx_st {
506 const EVP_AEAD *aead;
507 /* aead_state is an opaque pointer to the AEAD specific state. */
508 void *aead_state;
509};
510
383int EVP_PKEY_CTX_md(EVP_PKEY_CTX *ctx, int optype, int cmd, const char *md_name); 511int EVP_PKEY_CTX_md(EVP_PKEY_CTX *ctx, int optype, int cmd, const char *md_name);
384 512
385__END_HIDDEN_DECLS 513__END_HIDDEN_DECLS
diff --git a/src/lib/libcrypto/hmac/hmac.h b/src/lib/libcrypto/hmac/hmac.h
index 2f91f55f9b..0fe894e7b1 100644
--- a/src/lib/libcrypto/hmac/hmac.h
+++ b/src/lib/libcrypto/hmac/hmac.h
@@ -1,4 +1,4 @@
1/* $OpenBSD: hmac.h,v 1.14 2021/12/12 21:35:47 tb Exp $ */ 1/* $OpenBSD: hmac.h,v 1.15 2022/01/14 08:04:14 tb 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 *
@@ -72,16 +72,6 @@
72extern "C" { 72extern "C" {
73#endif 73#endif
74 74
75/* Move to hmac_local.h */
76struct hmac_ctx_st {
77 const EVP_MD *md;
78 EVP_MD_CTX md_ctx;
79 EVP_MD_CTX i_ctx;
80 EVP_MD_CTX o_ctx;
81 unsigned int key_length;
82 unsigned char key[HMAC_MAX_MD_CBLOCK];
83} /* HMAC_CTX */;
84
85#define HMAC_size(e) (EVP_MD_size(HMAC_CTX_get_md((e)))) 75#define HMAC_size(e) (EVP_MD_size(HMAC_CTX_get_md((e))))
86 76
87HMAC_CTX *HMAC_CTX_new(void); 77HMAC_CTX *HMAC_CTX_new(void);
diff --git a/src/lib/libcrypto/hmac/hmac_local.h b/src/lib/libcrypto/hmac/hmac_local.h
index 46f1a013cb..8358d9fa8b 100644
--- a/src/lib/libcrypto/hmac/hmac_local.h
+++ b/src/lib/libcrypto/hmac/hmac_local.h
@@ -1,4 +1,4 @@
1/* $OpenBSD: hmac_local.h,v 1.1 2021/12/12 21:27:38 tb Exp $ */ 1/* $OpenBSD: hmac_local.h,v 1.2 2022/01/14 08:04:14 tb 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 *
@@ -66,6 +66,15 @@
66 66
67__BEGIN_HIDDEN_DECLS 67__BEGIN_HIDDEN_DECLS
68 68
69struct hmac_ctx_st {
70 const EVP_MD *md;
71 EVP_MD_CTX md_ctx;
72 EVP_MD_CTX i_ctx;
73 EVP_MD_CTX o_ctx;
74 unsigned int key_length;
75 unsigned char key[HMAC_MAX_MD_CBLOCK];
76} /* HMAC_CTX */;
77
69__END_HIDDEN_DECLS 78__END_HIDDEN_DECLS
70 79
71#endif /* !HEADER_HMAC_LOCAL_H */ 80#endif /* !HEADER_HMAC_LOCAL_H */