VirtualBox

source: vbox/trunk/src/libs/openssl-3.4.1/include/crypto/ecx.h

Last change on this file was 109052, checked in by vboxsync, 3 weeks ago

openssl-3.4.1: Applied our changes, regenerated files, added missing files and functions. This time with a three way merge. ​bugref:10890

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 5.9 KB
Line 
1/*
2 * Copyright 2020-2024 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/* Internal EC functions for other submodules: not for application use */
11
12#ifndef OSSL_CRYPTO_ECX_H
13# define OSSL_CRYPTO_ECX_H
14# ifndef RT_WITHOUT_PRAGMA_ONCE /* VBOX */
15# pragma once
16# endif /* VBOX */
17
18# include <openssl/opensslconf.h>
19
20# ifndef OPENSSL_NO_ECX
21
22# include <openssl/core.h>
23# include <openssl/e_os2.h>
24# include <openssl/crypto.h>
25# include "internal/refcount.h"
26# include "crypto/types.h"
27
28# define X25519_KEYLEN 32
29# define X448_KEYLEN 56
30# define ED25519_KEYLEN 32
31# define ED448_KEYLEN 57
32
33# define MAX_KEYLEN ED448_KEYLEN
34
35# define X25519_BITS 253
36# define X25519_SECURITY_BITS 128
37
38# define X448_BITS 448
39# define X448_SECURITY_BITS 224
40
41# define ED25519_BITS 256
42/* RFC8032 Section 8.5 */
43# define ED25519_SECURITY_BITS 128
44# define ED25519_SIGSIZE 64
45
46# define ED448_BITS 456
47/* RFC8032 Section 8.5 */
48# define ED448_SECURITY_BITS 224
49# define ED448_SIGSIZE 114
50
51
52typedef enum {
53 ECX_KEY_TYPE_X25519,
54 ECX_KEY_TYPE_X448,
55 ECX_KEY_TYPE_ED25519,
56 ECX_KEY_TYPE_ED448
57} ECX_KEY_TYPE;
58
59#define KEYTYPE2NID(type) \
60 ((type) == ECX_KEY_TYPE_X25519 \
61 ? EVP_PKEY_X25519 \
62 : ((type) == ECX_KEY_TYPE_X448 \
63 ? EVP_PKEY_X448 \
64 : ((type) == ECX_KEY_TYPE_ED25519 \
65 ? EVP_PKEY_ED25519 \
66 : EVP_PKEY_ED448)))
67
68struct ecx_key_st {
69 OSSL_LIB_CTX *libctx;
70 char *propq;
71 unsigned int haspubkey:1;
72 unsigned char pubkey[MAX_KEYLEN];
73 unsigned char *privkey;
74 size_t keylen;
75 ECX_KEY_TYPE type;
76 CRYPTO_REF_COUNT references;
77};
78
79size_t ossl_ecx_key_length(ECX_KEY_TYPE type);
80ECX_KEY *ossl_ecx_key_new(OSSL_LIB_CTX *libctx, ECX_KEY_TYPE type,
81 int haspubkey, const char *propq);
82void ossl_ecx_key_set0_libctx(ECX_KEY *key, OSSL_LIB_CTX *libctx);
83unsigned char *ossl_ecx_key_allocate_privkey(ECX_KEY *key);
84void ossl_ecx_key_free(ECX_KEY *key);
85int ossl_ecx_key_up_ref(ECX_KEY *key);
86ECX_KEY *ossl_ecx_key_dup(const ECX_KEY *key, int selection);
87int ossl_ecx_compute_key(ECX_KEY *peer, ECX_KEY *priv, size_t keylen,
88 unsigned char *secret, size_t *secretlen,
89 size_t outlen);
90
91int ossl_x25519(uint8_t out_shared_key[32], const uint8_t private_key[32],
92 const uint8_t peer_public_value[32]);
93void ossl_x25519_public_from_private(uint8_t out_public_value[32],
94 const uint8_t private_key[32]);
95
96int
97ossl_ed25519_public_from_private(OSSL_LIB_CTX *ctx, uint8_t out_public_key[32],
98 const uint8_t private_key[32],
99 const char *propq);
100int
101ossl_ed25519_sign(uint8_t *out_sig, const uint8_t *tbs, size_t tbs_len,
102 const uint8_t public_key[32], const uint8_t private_key[32],
103 const uint8_t dom2flag, const uint8_t phflag, const uint8_t csflag,
104 const uint8_t *context, size_t context_len,
105 OSSL_LIB_CTX *libctx, const char *propq);
106int
107ossl_ed25519_verify(const uint8_t *tbs, size_t tbs_len,
108 const uint8_t signature[64], const uint8_t public_key[32],
109 const uint8_t dom2flag, const uint8_t phflag, const uint8_t csflag,
110 const uint8_t *context, size_t context_len,
111 OSSL_LIB_CTX *libctx, const char *propq);
112int
113ossl_ed25519_pubkey_verify(const uint8_t *pub, size_t pub_len);
114int
115ossl_ed448_public_from_private(OSSL_LIB_CTX *ctx, uint8_t out_public_key[57],
116 const uint8_t private_key[57], const char *propq);
117int
118ossl_ed448_sign(OSSL_LIB_CTX *ctx, uint8_t *out_sig,
119 const uint8_t *message, size_t message_len,
120 const uint8_t public_key[57], const uint8_t private_key[57],
121 const uint8_t *context, size_t context_len,
122 const uint8_t phflag, const char *propq);
123
124int
125ossl_ed448_verify(OSSL_LIB_CTX *ctx,
126 const uint8_t *message, size_t message_len,
127 const uint8_t signature[114], const uint8_t public_key[57],
128 const uint8_t *context, size_t context_len,
129 const uint8_t phflag, const char *propq);
130
131int
132ossl_ed448_pubkey_verify(const uint8_t *pub, size_t pub_len);
133
134int
135ossl_x448(uint8_t out_shared_key[56], const uint8_t private_key[56],
136 const uint8_t peer_public_value[56]);
137void
138ossl_x448_public_from_private(uint8_t out_public_value[56],
139 const uint8_t private_key[56]);
140
141
142/* Backend support */
143typedef enum {
144 KEY_OP_PUBLIC,
145 KEY_OP_PRIVATE,
146 KEY_OP_KEYGEN
147} ecx_key_op_t;
148
149ECX_KEY *ossl_ecx_key_op(const X509_ALGOR *palg,
150 const unsigned char *p, int plen,
151 int pkey_id, ecx_key_op_t op,
152 OSSL_LIB_CTX *libctx, const char *propq);
153
154int ossl_ecx_public_from_private(ECX_KEY *key);
155int ossl_ecx_key_fromdata(ECX_KEY *ecx, const OSSL_PARAM params[],
156 int include_private);
157ECX_KEY *ossl_ecx_key_from_pkcs8(const PKCS8_PRIV_KEY_INFO *p8inf,
158 OSSL_LIB_CTX *libctx, const char *propq);
159
160ECX_KEY *ossl_evp_pkey_get1_X25519(EVP_PKEY *pkey);
161ECX_KEY *ossl_evp_pkey_get1_X448(EVP_PKEY *pkey);
162ECX_KEY *ossl_evp_pkey_get1_ED25519(EVP_PKEY *pkey);
163ECX_KEY *ossl_evp_pkey_get1_ED448(EVP_PKEY *pkey);
164# endif /* OPENSSL_NO_ECX */
165#endif
Note: See TracBrowser for help on using the repository browser.

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