File indexing completed on 2025-01-18 10:05:44
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011 #ifndef OSSL_HPKE_H
0012 # define OSSL_HPKE_H
0013 # pragma once
0014
0015 # include <openssl/types.h>
0016
0017
0018 # define OSSL_HPKE_MODE_BASE 0
0019 # define OSSL_HPKE_MODE_PSK 1
0020 # define OSSL_HPKE_MODE_AUTH 2
0021 # define OSSL_HPKE_MODE_PSKAUTH 3
0022
0023
0024
0025
0026
0027
0028 # define OSSL_HPKE_MAX_PARMLEN 66
0029 # define OSSL_HPKE_MIN_PSKLEN 32
0030 # define OSSL_HPKE_MAX_INFOLEN 1024
0031
0032
0033
0034
0035
0036
0037 # define OSSL_HPKE_KEM_ID_RESERVED 0x0000
0038 # define OSSL_HPKE_KEM_ID_P256 0x0010
0039 # define OSSL_HPKE_KEM_ID_P384 0x0011
0040 # define OSSL_HPKE_KEM_ID_P521 0x0012
0041 # define OSSL_HPKE_KEM_ID_X25519 0x0020
0042 # define OSSL_HPKE_KEM_ID_X448 0x0021
0043
0044 # define OSSL_HPKE_KDF_ID_RESERVED 0x0000
0045 # define OSSL_HPKE_KDF_ID_HKDF_SHA256 0x0001
0046 # define OSSL_HPKE_KDF_ID_HKDF_SHA384 0x0002
0047 # define OSSL_HPKE_KDF_ID_HKDF_SHA512 0x0003
0048
0049 # define OSSL_HPKE_AEAD_ID_RESERVED 0x0000
0050 # define OSSL_HPKE_AEAD_ID_AES_GCM_128 0x0001
0051 # define OSSL_HPKE_AEAD_ID_AES_GCM_256 0x0002
0052 # define OSSL_HPKE_AEAD_ID_CHACHA_POLY1305 0x0003
0053 # define OSSL_HPKE_AEAD_ID_EXPORTONLY 0xFFFF
0054
0055
0056 # define OSSL_HPKE_KEMSTR_P256 "P-256"
0057 # define OSSL_HPKE_KEMSTR_P384 "P-384"
0058 # define OSSL_HPKE_KEMSTR_P521 "P-521"
0059 # define OSSL_HPKE_KEMSTR_X25519 "X25519"
0060 # define OSSL_HPKE_KEMSTR_X448 "X448"
0061 # define OSSL_HPKE_KDFSTR_256 "hkdf-sha256"
0062 # define OSSL_HPKE_KDFSTR_384 "hkdf-sha384"
0063 # define OSSL_HPKE_KDFSTR_512 "hkdf-sha512"
0064 # define OSSL_HPKE_AEADSTR_AES128GCM "aes-128-gcm"
0065 # define OSSL_HPKE_AEADSTR_AES256GCM "aes-256-gcm"
0066 # define OSSL_HPKE_AEADSTR_CP "chacha20-poly1305"
0067 # define OSSL_HPKE_AEADSTR_EXP "exporter"
0068
0069
0070
0071
0072
0073 # define OSSL_HPKE_ROLE_SENDER 0
0074 # define OSSL_HPKE_ROLE_RECEIVER 1
0075
0076 # ifdef __cplusplus
0077 extern "C" {
0078 # endif
0079
0080 typedef struct {
0081 uint16_t kem_id;
0082 uint16_t kdf_id;
0083 uint16_t aead_id;
0084 } OSSL_HPKE_SUITE;
0085
0086
0087
0088
0089
0090 # ifndef OPENSSL_NO_ECX
0091 # define OSSL_HPKE_SUITE_DEFAULT \
0092 {\
0093 OSSL_HPKE_KEM_ID_X25519, \
0094 OSSL_HPKE_KDF_ID_HKDF_SHA256, \
0095 OSSL_HPKE_AEAD_ID_AES_GCM_128 \
0096 }
0097 # else
0098 # define OSSL_HPKE_SUITE_DEFAULT \
0099 {\
0100 OSSL_HPKE_KEM_ID_P256, \
0101 OSSL_HPKE_KDF_ID_HKDF_SHA256, \
0102 OSSL_HPKE_AEAD_ID_AES_GCM_128 \
0103 }
0104 #endif
0105
0106 typedef struct ossl_hpke_ctx_st OSSL_HPKE_CTX;
0107
0108 OSSL_HPKE_CTX *OSSL_HPKE_CTX_new(int mode, OSSL_HPKE_SUITE suite, int role,
0109 OSSL_LIB_CTX *libctx, const char *propq);
0110 void OSSL_HPKE_CTX_free(OSSL_HPKE_CTX *ctx);
0111
0112 int OSSL_HPKE_encap(OSSL_HPKE_CTX *ctx,
0113 unsigned char *enc, size_t *enclen,
0114 const unsigned char *pub, size_t publen,
0115 const unsigned char *info, size_t infolen);
0116 int OSSL_HPKE_seal(OSSL_HPKE_CTX *ctx,
0117 unsigned char *ct, size_t *ctlen,
0118 const unsigned char *aad, size_t aadlen,
0119 const unsigned char *pt, size_t ptlen);
0120
0121 int OSSL_HPKE_keygen(OSSL_HPKE_SUITE suite,
0122 unsigned char *pub, size_t *publen, EVP_PKEY **priv,
0123 const unsigned char *ikm, size_t ikmlen,
0124 OSSL_LIB_CTX *libctx, const char *propq);
0125 int OSSL_HPKE_decap(OSSL_HPKE_CTX *ctx,
0126 const unsigned char *enc, size_t enclen,
0127 EVP_PKEY *recippriv,
0128 const unsigned char *info, size_t infolen);
0129 int OSSL_HPKE_open(OSSL_HPKE_CTX *ctx,
0130 unsigned char *pt, size_t *ptlen,
0131 const unsigned char *aad, size_t aadlen,
0132 const unsigned char *ct, size_t ctlen);
0133
0134 int OSSL_HPKE_export(OSSL_HPKE_CTX *ctx,
0135 unsigned char *secret,
0136 size_t secretlen,
0137 const unsigned char *label,
0138 size_t labellen);
0139
0140 int OSSL_HPKE_CTX_set1_authpriv(OSSL_HPKE_CTX *ctx, EVP_PKEY *priv);
0141 int OSSL_HPKE_CTX_set1_authpub(OSSL_HPKE_CTX *ctx,
0142 const unsigned char *pub,
0143 size_t publen);
0144 int OSSL_HPKE_CTX_set1_psk(OSSL_HPKE_CTX *ctx,
0145 const char *pskid,
0146 const unsigned char *psk, size_t psklen);
0147
0148 int OSSL_HPKE_CTX_set1_ikme(OSSL_HPKE_CTX *ctx,
0149 const unsigned char *ikme, size_t ikmelen);
0150
0151 int OSSL_HPKE_CTX_set_seq(OSSL_HPKE_CTX *ctx, uint64_t seq);
0152 int OSSL_HPKE_CTX_get_seq(OSSL_HPKE_CTX *ctx, uint64_t *seq);
0153
0154 int OSSL_HPKE_suite_check(OSSL_HPKE_SUITE suite);
0155 int OSSL_HPKE_get_grease_value(const OSSL_HPKE_SUITE *suite_in,
0156 OSSL_HPKE_SUITE *suite,
0157 unsigned char *enc, size_t *enclen,
0158 unsigned char *ct, size_t ctlen,
0159 OSSL_LIB_CTX *libctx, const char *propq);
0160 int OSSL_HPKE_str2suite(const char *str, OSSL_HPKE_SUITE *suite);
0161 size_t OSSL_HPKE_get_ciphertext_size(OSSL_HPKE_SUITE suite, size_t clearlen);
0162 size_t OSSL_HPKE_get_public_encap_size(OSSL_HPKE_SUITE suite);
0163 size_t OSSL_HPKE_get_recommended_ikmelen(OSSL_HPKE_SUITE suite);
0164
0165 # ifdef __cplusplus
0166 }
0167 # endif
0168
0169 #endif