Path: blob/main/crypto/openssl/include/internal/hpke_util.h
34879 views
/*1* Copyright 2022 The OpenSSL Project Authors. All Rights Reserved.2*3* Licensed under the Apache License 2.0 (the "License"). You may not use4* this file except in compliance with the License. You can obtain a copy5* in the file LICENSE in the source distribution or at6* https://www.openssl.org/source/license.html7*/89#ifndef OSSL_INTERNAL_HPKE_UTIL_H10# define OSSL_INTERNAL_HPKE_UTIL_H11# pragma once1213/* Constants from RFC 9180 Section 7.1 and 7.3 */14# define OSSL_HPKE_MAX_SECRET 6415# define OSSL_HPKE_MAX_PUBLIC 13316# define OSSL_HPKE_MAX_PRIVATE 6617# define OSSL_HPKE_MAX_KDF_INPUTLEN 641819/*20* max length of a base-nonce (the Nn field from OSSL_HPKE_AEAD_INFO), this21* is used for a local stack array size22*/23# define OSSL_HPKE_MAX_NONCELEN 122425/*26* @brief info about a KEM27* Used to store constants from Section 7.1 "Table 2 KEM IDs"28* and the bitmask for EC curves described in Section 7.1.3 DeriveKeyPair29*/30typedef struct {31uint16_t kem_id; /* code point for key encipherment method */32const char *keytype; /* string form of algtype "EC"/"X25519"/"X448" */33const char *groupname; /* string form of EC group for NIST curves */34const char *mdname; /* hash alg name for the HKDF */35size_t Nsecret; /* size of secrets */36size_t Nenc; /* length of encapsulated key */37size_t Npk; /* length of public key */38size_t Nsk; /* length of raw private key */39uint8_t bitmask;40} OSSL_HPKE_KEM_INFO;4142/*43* @brief info about a KDF44*/45typedef struct {46uint16_t kdf_id; /* code point for KDF */47const char *mdname; /* hash alg name for the HKDF */48size_t Nh; /* length of hash/extract output */49} OSSL_HPKE_KDF_INFO;5051/*52* @brief info about an AEAD53*/54typedef struct {55uint16_t aead_id; /* code point for aead alg */56const char *name; /* alg name */57size_t taglen; /* aead tag len */58size_t Nk; /* size of a key for this aead */59size_t Nn; /* length of a nonce for this aead */60} OSSL_HPKE_AEAD_INFO;6162const OSSL_HPKE_KEM_INFO *ossl_HPKE_KEM_INFO_find_curve(const char *curve);63const OSSL_HPKE_KEM_INFO *ossl_HPKE_KEM_INFO_find_id(uint16_t kemid);64const OSSL_HPKE_KEM_INFO *ossl_HPKE_KEM_INFO_find_random(OSSL_LIB_CTX *ctx);65const OSSL_HPKE_KDF_INFO *ossl_HPKE_KDF_INFO_find_id(uint16_t kdfid);66const OSSL_HPKE_KDF_INFO *ossl_HPKE_KDF_INFO_find_random(OSSL_LIB_CTX *ctx);67const OSSL_HPKE_AEAD_INFO *ossl_HPKE_AEAD_INFO_find_id(uint16_t aeadid);68const OSSL_HPKE_AEAD_INFO *ossl_HPKE_AEAD_INFO_find_random(OSSL_LIB_CTX *ctx);6970int ossl_hpke_kdf_extract(EVP_KDF_CTX *kctx,71unsigned char *prk, size_t prklen,72const unsigned char *salt, size_t saltlen,73const unsigned char *ikm, size_t ikmlen);7475int ossl_hpke_kdf_expand(EVP_KDF_CTX *kctx,76unsigned char *okm, size_t okmlen,77const unsigned char *prk, size_t prklen,78const unsigned char *info, size_t infolen);7980int ossl_hpke_labeled_extract(EVP_KDF_CTX *kctx,81unsigned char *prk, size_t prklen,82const unsigned char *salt, size_t saltlen,83const char *protocol_label,84const unsigned char *suiteid, size_t suiteidlen,85const char *label,86const unsigned char *ikm, size_t ikmlen);87int ossl_hpke_labeled_expand(EVP_KDF_CTX *kctx,88unsigned char *okm, size_t okmlen,89const unsigned char *prk, size_t prklen,90const char *protocol_label,91const unsigned char *suiteid, size_t suiteidlen,92const char *label,93const unsigned char *info, size_t infolen);9495EVP_KDF_CTX *ossl_kdf_ctx_create(const char *kdfname, const char *mdname,96OSSL_LIB_CTX *libctx, const char *propq);9798int ossl_hpke_str2suite(const char *suitestr, OSSL_HPKE_SUITE *suite);99#endif100101102