VirtualBox

source: vbox/trunk/src/libs/openssl-3.0.7/include/internal/ffc.h@ 99507

最後變更 在這個檔案從99507是 97984,由 vboxsync 提交於 2 年 前

libs/openssl-3.0.7: Shut up pragma once warnings for internal headers. Added sed script for doing that. bugref:10317

檔案大小: 9.4 KB
 
1/*
2 * Copyright 2019-2022 The OpenSSL Project Authors. All Rights Reserved.
3 *
4 * Licensed under the Apache License 2.0 (the "License"). You may not use
5 * this file except in compliance with the License. You can obtain a copy
6 * in the file LICENSE in the source distribution or at
7 * https://www.openssl.org/source/license.html
8 */
9
10#ifndef OSSL_INTERNAL_FFC_H
11# define OSSL_INTERNAL_FFC_H
12# ifndef RT_WITHOUT_PRAGMA_ONCE /* VBOX */
13# pragma once
14# endif /* VBOX */
15
16# include <openssl/core.h>
17# include <openssl/bn.h>
18# include <openssl/evp.h>
19# include <openssl/dh.h> /* Uses Error codes from DH */
20# include <openssl/params.h>
21# include <openssl/param_build.h>
22# include "internal/sizes.h"
23
24/* Default value for gindex when canonical generation of g is not used */
25# define FFC_UNVERIFIABLE_GINDEX -1
26
27/* The different types of FFC keys */
28# define FFC_PARAM_TYPE_DSA 0
29# define FFC_PARAM_TYPE_DH 1
30
31/*
32 * The mode used by functions that share code for both generation and
33 * verification. See ossl_ffc_params_FIPS186_4_gen_verify().
34 */
35#define FFC_PARAM_MODE_VERIFY 0
36#define FFC_PARAM_MODE_GENERATE 1
37
38/* Return codes for generation and validation of FFC parameters */
39#define FFC_PARAM_RET_STATUS_FAILED 0
40#define FFC_PARAM_RET_STATUS_SUCCESS 1
41/* Returned if validating and g is only partially verifiable */
42#define FFC_PARAM_RET_STATUS_UNVERIFIABLE_G 2
43
44/* Validation flags */
45# define FFC_PARAM_FLAG_VALIDATE_PQ 0x01
46# define FFC_PARAM_FLAG_VALIDATE_G 0x02
47# define FFC_PARAM_FLAG_VALIDATE_PQG \
48 (FFC_PARAM_FLAG_VALIDATE_PQ | FFC_PARAM_FLAG_VALIDATE_G)
49#define FFC_PARAM_FLAG_VALIDATE_LEGACY 0x04
50
51/*
52 * NB: These values must align with the equivalently named macros in
53 * openssl/dh.h. We cannot use those macros here in case DH has been disabled.
54 */
55# define FFC_CHECK_P_NOT_PRIME 0x00001
56# define FFC_CHECK_P_NOT_SAFE_PRIME 0x00002
57# define FFC_CHECK_UNKNOWN_GENERATOR 0x00004
58# define FFC_CHECK_NOT_SUITABLE_GENERATOR 0x00008
59# define FFC_CHECK_Q_NOT_PRIME 0x00010
60# define FFC_CHECK_INVALID_Q_VALUE 0x00020
61# define FFC_CHECK_INVALID_J_VALUE 0x00040
62
63# define FFC_CHECK_BAD_LN_PAIR 0x00080
64# define FFC_CHECK_INVALID_SEED_SIZE 0x00100
65# define FFC_CHECK_MISSING_SEED_OR_COUNTER 0x00200
66# define FFC_CHECK_INVALID_G 0x00400
67# define FFC_CHECK_INVALID_PQ 0x00800
68# define FFC_CHECK_INVALID_COUNTER 0x01000
69# define FFC_CHECK_P_MISMATCH 0x02000
70# define FFC_CHECK_Q_MISMATCH 0x04000
71# define FFC_CHECK_G_MISMATCH 0x08000
72# define FFC_CHECK_COUNTER_MISMATCH 0x10000
73
74/* Validation Return codes */
75# define FFC_ERROR_PUBKEY_TOO_SMALL 0x01
76# define FFC_ERROR_PUBKEY_TOO_LARGE 0x02
77# define FFC_ERROR_PUBKEY_INVALID 0x04
78# define FFC_ERROR_NOT_SUITABLE_GENERATOR 0x08
79# define FFC_ERROR_PRIVKEY_TOO_SMALL 0x10
80# define FFC_ERROR_PRIVKEY_TOO_LARGE 0x20
81
82/*
83 * Finite field cryptography (FFC) domain parameters are used by DH and DSA.
84 * Refer to FIPS186_4 Appendix A & B.
85 */
86typedef struct ffc_params_st {
87 /* Primes */
88 BIGNUM *p;
89 BIGNUM *q;
90 /* Generator */
91 BIGNUM *g;
92 /* DH X9.42 Optional Subgroup factor j >= 2 where p = j * q + 1 */
93 BIGNUM *j;
94
95 /* Required for FIPS186_4 validation of p, q and optionally canonical g */
96 unsigned char *seed;
97 /* If this value is zero the hash size is used as the seed length */
98 size_t seedlen;
99 /* Required for FIPS186_4 validation of p and q */
100 int pcounter;
101 int nid; /* The identity of a named group */
102
103 /*
104 * Required for FIPS186_4 generation & validation of canonical g.
105 * It uses unverifiable g if this value is -1.
106 */
107 int gindex;
108 int h; /* loop counter for unverifiable g */
109
110 unsigned int flags;
111 /*
112 * The digest to use for generation or validation. If this value is NULL,
113 * then the digest is chosen using the value of N.
114 */
115 const char *mdname;
116 const char *mdprops;
117 /* Default key length for known named groups according to RFC7919 */
118 int keylength;
119} FFC_PARAMS;
120
121void ossl_ffc_params_init(FFC_PARAMS *params);
122void ossl_ffc_params_cleanup(FFC_PARAMS *params);
123void ossl_ffc_params_set0_pqg(FFC_PARAMS *params, BIGNUM *p, BIGNUM *q,
124 BIGNUM *g);
125void ossl_ffc_params_get0_pqg(const FFC_PARAMS *params, const BIGNUM **p,
126 const BIGNUM **q, const BIGNUM **g);
127void ossl_ffc_params_set0_j(FFC_PARAMS *d, BIGNUM *j);
128int ossl_ffc_params_set_seed(FFC_PARAMS *params,
129 const unsigned char *seed, size_t seedlen);
130void ossl_ffc_params_set_gindex(FFC_PARAMS *params, int index);
131void ossl_ffc_params_set_pcounter(FFC_PARAMS *params, int index);
132void ossl_ffc_params_set_h(FFC_PARAMS *params, int index);
133void ossl_ffc_params_set_flags(FFC_PARAMS *params, unsigned int flags);
134void ossl_ffc_params_enable_flags(FFC_PARAMS *params, unsigned int flags,
135 int enable);
136int ossl_ffc_set_digest(FFC_PARAMS *params, const char *alg, const char *props);
137
138int ossl_ffc_params_set_validate_params(FFC_PARAMS *params,
139 const unsigned char *seed,
140 size_t seedlen, int counter);
141void ossl_ffc_params_get_validate_params(const FFC_PARAMS *params,
142 unsigned char **seed, size_t *seedlen,
143 int *pcounter);
144
145int ossl_ffc_params_copy(FFC_PARAMS *dst, const FFC_PARAMS *src);
146int ossl_ffc_params_cmp(const FFC_PARAMS *a, const FFC_PARAMS *b, int ignore_q);
147
148#ifndef FIPS_MODULE
149int ossl_ffc_params_print(BIO *bp, const FFC_PARAMS *ffc, int indent);
150#endif /* FIPS_MODULE */
151
152
153int ossl_ffc_params_FIPS186_4_generate(OSSL_LIB_CTX *libctx, FFC_PARAMS *params,
154 int type, size_t L, size_t N,
155 int *res, BN_GENCB *cb);
156int ossl_ffc_params_FIPS186_2_generate(OSSL_LIB_CTX *libctx, FFC_PARAMS *params,
157 int type, size_t L, size_t N,
158 int *res, BN_GENCB *cb);
159
160int ossl_ffc_params_FIPS186_4_gen_verify(OSSL_LIB_CTX *libctx,
161 FFC_PARAMS *params, int mode, int type,
162 size_t L, size_t N, int *res,
163 BN_GENCB *cb);
164int ossl_ffc_params_FIPS186_2_gen_verify(OSSL_LIB_CTX *libctx,
165 FFC_PARAMS *params, int mode, int type,
166 size_t L, size_t N, int *res,
167 BN_GENCB *cb);
168
169int ossl_ffc_params_simple_validate(OSSL_LIB_CTX *libctx,
170 const FFC_PARAMS *params,
171 int paramstype, int *res);
172int ossl_ffc_params_full_validate(OSSL_LIB_CTX *libctx,
173 const FFC_PARAMS *params,
174 int paramstype, int *res);
175int ossl_ffc_params_FIPS186_4_validate(OSSL_LIB_CTX *libctx,
176 const FFC_PARAMS *params,
177 int type, int *res, BN_GENCB *cb);
178int ossl_ffc_params_FIPS186_2_validate(OSSL_LIB_CTX *libctx,
179 const FFC_PARAMS *params,
180 int type, int *res, BN_GENCB *cb);
181
182int ossl_ffc_generate_private_key(BN_CTX *ctx, const FFC_PARAMS *params,
183 int N, int s, BIGNUM *priv);
184
185int ossl_ffc_params_validate_unverifiable_g(BN_CTX *ctx, BN_MONT_CTX *mont,
186 const BIGNUM *p, const BIGNUM *q,
187 const BIGNUM *g, BIGNUM *tmp,
188 int *ret);
189
190int ossl_ffc_validate_public_key(const FFC_PARAMS *params,
191 const BIGNUM *pub_key, int *ret);
192int ossl_ffc_validate_public_key_partial(const FFC_PARAMS *params,
193 const BIGNUM *pub_key, int *ret);
194int ossl_ffc_validate_private_key(const BIGNUM *upper, const BIGNUM *priv_key,
195 int *ret);
196
197int ossl_ffc_params_todata(const FFC_PARAMS *ffc, OSSL_PARAM_BLD *tmpl,
198 OSSL_PARAM params[]);
199int ossl_ffc_params_fromdata(FFC_PARAMS *ffc, const OSSL_PARAM params[]);
200
201typedef struct dh_named_group_st DH_NAMED_GROUP;
202const DH_NAMED_GROUP *ossl_ffc_name_to_dh_named_group(const char *name);
203const DH_NAMED_GROUP *ossl_ffc_uid_to_dh_named_group(int uid);
204#ifndef OPENSSL_NO_DH
205const DH_NAMED_GROUP *ossl_ffc_numbers_to_dh_named_group(const BIGNUM *p,
206 const BIGNUM *q,
207 const BIGNUM *g);
208#endif
209int ossl_ffc_named_group_get_uid(const DH_NAMED_GROUP *group);
210const char *ossl_ffc_named_group_get_name(const DH_NAMED_GROUP *);
211#ifndef OPENSSL_NO_DH
212int ossl_ffc_named_group_get_keylength(const DH_NAMED_GROUP *group);
213const BIGNUM *ossl_ffc_named_group_get_q(const DH_NAMED_GROUP *group);
214int ossl_ffc_named_group_set(FFC_PARAMS *ffc, const DH_NAMED_GROUP *group);
215#endif
216
217#endif /* OSSL_INTERNAL_FFC_H */
注意: 瀏覽 TracBrowser 來幫助您使用儲存庫瀏覽器

© 2025 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette