iPXE
crypto.h File Reference

Cryptographic API. More...

#include <stdint.h>
#include <stddef.h>
#include <assert.h>
#include <ipxe/asn1.h>

Go to the source code of this file.

Data Structures

struct  digest_algorithm
 A message digest algorithm. More...
struct  cipher_algorithm
 A cipher algorithm. More...
struct  pubkey_algorithm
 A public key algorithm. More...
struct  elliptic_curve
 An elliptic curve. More...

Macros

#define cipher_encrypt(cipher, ctx, src, dst, len)
#define cipher_decrypt(cipher, ctx, src, dst, len)

Functions

 FILE_LICENCE (GPL2_OR_LATER_OR_UBDL)
 FILE_SECBOOT (PERMITTED)
static void digest_init (struct digest_algorithm *digest, void *ctx)
static void digest_update (struct digest_algorithm *digest, void *ctx, const void *data, size_t len)
static void digest_final (struct digest_algorithm *digest, void *ctx, void *out)
static int cipher_setkey (struct cipher_algorithm *cipher, void *ctx, const void *key, size_t keylen)
static void cipher_setiv (struct cipher_algorithm *cipher, void *ctx, const void *iv, size_t ivlen)
static void cipher_encrypt (struct cipher_algorithm *cipher, void *ctx, const void *src, void *dst, size_t len)
static void cipher_decrypt (struct cipher_algorithm *cipher, void *ctx, const void *src, void *dst, size_t len)
static void cipher_auth (struct cipher_algorithm *cipher, void *ctx, void *auth)
static int is_stream_cipher (struct cipher_algorithm *cipher)
static int is_block_cipher (struct cipher_algorithm *cipher)
static int is_auth_cipher (struct cipher_algorithm *cipher)
static int pubkey_encrypt (struct pubkey_algorithm *pubkey, const struct asn1_cursor *key, const struct asn1_cursor *plaintext, struct asn1_builder *ciphertext)
static int pubkey_decrypt (struct pubkey_algorithm *pubkey, const struct asn1_cursor *key, const struct asn1_cursor *ciphertext, struct asn1_builder *plaintext)
static int pubkey_sign (struct pubkey_algorithm *pubkey, const struct asn1_cursor *key, struct digest_algorithm *digest, const void *value, struct asn1_builder *signature)
static int pubkey_verify (struct pubkey_algorithm *pubkey, const struct asn1_cursor *key, struct digest_algorithm *digest, const void *value, const struct asn1_cursor *signature)
static int pubkey_match (struct pubkey_algorithm *pubkey, const struct asn1_cursor *private_key, const struct asn1_cursor *public_key)
static int elliptic_is_infinity (struct elliptic_curve *curve, const void *point)
static int elliptic_multiply (struct elliptic_curve *curve, const void *base, const void *scalar, void *result)
static int elliptic_add (struct elliptic_curve *curve, const void *addend, const void *augend, void *result)
void digest_null_init (void *ctx)
void digest_null_update (void *ctx, const void *src, size_t len)
void digest_null_final (void *ctx, void *out)
int cipher_null_setkey (void *ctx, const void *key, size_t keylen)
void cipher_null_setiv (void *ctx, const void *iv, size_t ivlen)
void cipher_null_encrypt (void *ctx, const void *src, void *dst, size_t len)
void cipher_null_decrypt (void *ctx, const void *src, void *dst, size_t len)
void cipher_null_auth (void *ctx, void *auth)
int pubkey_null_encrypt (const struct asn1_cursor *key, const struct asn1_cursor *plaintext, struct asn1_builder *ciphertext)
int pubkey_null_decrypt (const struct asn1_cursor *key, const struct asn1_cursor *ciphertext, struct asn1_builder *plaintext)
int pubkey_null_sign (const struct asn1_cursor *key, struct digest_algorithm *digest, const void *value, struct asn1_builder *signature)
int pubkey_null_verify (const struct asn1_cursor *key, struct digest_algorithm *digest, const void *value, const struct asn1_cursor *signature)

Variables

struct digest_algorithm digest_null
struct cipher_algorithm cipher_null
struct pubkey_algorithm pubkey_null

Detailed Description

Cryptographic API.

Definition in file crypto.h.

Macro Definition Documentation

◆ cipher_encrypt

#define cipher_encrypt ( cipher,
ctx,
src,
dst,
len )
Value:
do { \
assert ( ( (len) & ( (cipher)->blocksize - 1 ) ) == 0 ); \
cipher_encrypt ( (cipher), (ctx), (src), (dst), (len) ); \
} while ( 0 )
struct golan_eq_context ctx
Definition CIB_PRM.h:0
static const void * src
Definition string.h:48
ring len
Length.
Definition dwmac.h:226

Definition at line 251 of file crypto.h.

251#define cipher_encrypt( cipher, ctx, src, dst, len ) do { \
252 assert ( ( (len) & ( (cipher)->blocksize - 1 ) ) == 0 ); \
253 cipher_encrypt ( (cipher), (ctx), (src), (dst), (len) ); \
254 } while ( 0 )

Referenced by aes_wrap(), cbc_encrypt(), ccmp_cbc_mac(), ccmp_ctr_xor(), ccmp_feed_cbc_mac(), cipher_cost_encrypt(), cipher_encrypt_okx(), cms_decrypt(), ecb_encrypt(), gcm_process(), gcm_setkey(), gcm_tag(), mschapv2_challenge_response(), tkip_encrypt(), tls_send_record(), and wep_encrypt().

◆ cipher_decrypt

#define cipher_decrypt ( cipher,
ctx,
src,
dst,
len )
Value:
do { \
assert ( ( (len) & ( (cipher)->blocksize - 1 ) ) == 0 ); \
cipher_decrypt ( (cipher), (ctx), (src), (dst), (len) ); \
} while ( 0 )

Definition at line 261 of file crypto.h.

261#define cipher_decrypt( cipher, ctx, src, dst, len ) do { \
262 assert ( ( (len) & ( (cipher)->blocksize - 1 ) ) == 0 ); \
263 cipher_decrypt ( (cipher), (ctx), (src), (dst), (len) ); \
264 } while ( 0 )

Referenced by aes_unwrap(), cbc_decrypt(), cipher_cost_decrypt(), cipher_decrypt_okx(), cms_decrypt(), ecb_decrypt(), peerblk_decrypt(), tkip_decrypt(), tls_new_ciphertext(), and wep_decrypt().

Function Documentation

◆ FILE_LICENCE()

FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL )

◆ FILE_SECBOOT()

FILE_SECBOOT ( PERMITTED )

◆ digest_init()

◆ digest_update()

◆ digest_final()

◆ cipher_setkey()

int cipher_setkey ( struct cipher_algorithm * cipher,
void * ctx,
const void * key,
size_t keylen )
inlinestatic

Definition at line 235 of file crypto.h.

236 {
237 return cipher->setkey ( ctx, key, keylen );
238}
union @162305117151260234136356364136041353210355154177 key
Sense key.
Definition scsi.h:3
int(* setkey)(void *ctx, const void *key, size_t keylen)
Set key.
Definition crypto.h:83

References ctx, key, and cipher_algorithm::setkey.

Referenced by aes_unwrap(), aes_wrap(), cbc_setkey(), ccmp_init(), cipher_cost(), cipher_decrypt_okx(), cipher_encrypt_okx(), cms_cipher_key(), gcm_setkey(), mschapv2_challenge_response(), peerblk_parse_header(), tkip_decrypt(), tkip_encrypt(), tls_generate_keys(), wep_decrypt(), and wep_encrypt().

◆ cipher_setiv()

void cipher_setiv ( struct cipher_algorithm * cipher,
void * ctx,
const void * iv,
size_t ivlen )
inlinestatic

Definition at line 241 of file crypto.h.

242 {
243 cipher->setiv ( ctx, iv, ivlen );
244}
void(* setiv)(void *ctx, const void *iv, size_t ivlen)
Set initialisation vector.
Definition crypto.h:90
u8 iv[16]
Initialization vector.
Definition wpa.h:33

References ctx, iv, and cipher_algorithm::setiv.

Referenced by cipher_cost(), cipher_decrypt_okx(), cipher_encrypt_okx(), cms_cipher_key(), peerblk_parse_iv(), tls_new_ciphertext(), and tls_send_record().

◆ cipher_encrypt()

void cipher_encrypt ( struct cipher_algorithm * cipher,
void * ctx,
const void * src,
void * dst,
size_t len )
inlinestatic

Definition at line 247 of file crypto.h.

248 {
249 cipher->encrypt ( ctx, src, dst, len );
250}
void(* encrypt)(void *ctx, const void *src, void *dst, size_t len)
Encrypt data.
Definition crypto.h:100

References ctx, cipher_algorithm::encrypt, len, and src.

◆ cipher_decrypt()

void cipher_decrypt ( struct cipher_algorithm * cipher,
void * ctx,
const void * src,
void * dst,
size_t len )
inlinestatic

Definition at line 257 of file crypto.h.

258 {
259 cipher->decrypt ( ctx, src, dst, len );
260}
void(* decrypt)(void *ctx, const void *src, void *dst, size_t len)
Decrypt data.
Definition crypto.h:111

References ctx, cipher_algorithm::decrypt, len, and src.

◆ cipher_auth()

void cipher_auth ( struct cipher_algorithm * cipher,
void * ctx,
void * auth )
inlinestatic

Definition at line 267 of file crypto.h.

267 {
268 cipher->auth ( ctx, auth );
269}
void(* auth)(void *ctx, void *auth)
Generate authentication tag.
Definition crypto.h:118

References cipher_algorithm::auth, and ctx.

Referenced by cipher_decrypt_okx(), cipher_encrypt_okx(), cms_decrypt(), tls_new_ciphertext(), and tls_send_record().

◆ is_stream_cipher()

int is_stream_cipher ( struct cipher_algorithm * cipher)
inlinestatic

Definition at line 272 of file crypto.h.

272 {
273 return ( cipher->blocksize == 1 );
274}
size_t blocksize
Block size.
Definition crypto.h:61

References cipher_algorithm::blocksize.

◆ is_block_cipher()

int is_block_cipher ( struct cipher_algorithm * cipher)
inlinestatic

Definition at line 277 of file crypto.h.

277 {
278 return ( cipher->blocksize > 1 );
279}

References cipher_algorithm::blocksize.

Referenced by cms_decrypt(), cms_verify_padding(), tls_iob_reserved(), tls_new_ciphertext(), and tls_send_record().

◆ is_auth_cipher()

int is_auth_cipher ( struct cipher_algorithm * cipher)
inlinestatic

Definition at line 282 of file crypto.h.

282 {
283 return cipher->authsize;
284}
size_t authsize
Authentication tag size.
Definition crypto.h:75

References cipher_algorithm::authsize.

Referenced by cipher_decrypt_okx(), cipher_encrypt_okx(), tls_new_ciphertext(), and tls_send_record().

◆ pubkey_encrypt()

int pubkey_encrypt ( struct pubkey_algorithm * pubkey,
const struct asn1_cursor * key,
const struct asn1_cursor * plaintext,
struct asn1_builder * ciphertext )
inlinestatic

Definition at line 287 of file crypto.h.

289 {
290 return pubkey->encrypt ( key, plaintext, ciphertext );
291}
int(* encrypt)(const struct asn1_cursor *key, const struct asn1_cursor *plaintext, struct asn1_builder *ciphertext)
Encrypt.
Definition crypto.h:132

References pubkey_algorithm::encrypt, and key.

Referenced by pubkey_okx(), and tls_send_client_key_exchange_pubkey().

◆ pubkey_decrypt()

int pubkey_decrypt ( struct pubkey_algorithm * pubkey,
const struct asn1_cursor * key,
const struct asn1_cursor * ciphertext,
struct asn1_builder * plaintext )
inlinestatic

Definition at line 294 of file crypto.h.

296 {
297 return pubkey->decrypt ( key, ciphertext, plaintext );
298}
int(* decrypt)(const struct asn1_cursor *key, const struct asn1_cursor *ciphertext, struct asn1_builder *plaintext)
Decrypt.
Definition crypto.h:142

References pubkey_algorithm::decrypt, and key.

Referenced by cms_cipher_key(), and pubkey_okx().

◆ pubkey_sign()

int pubkey_sign ( struct pubkey_algorithm * pubkey,
const struct asn1_cursor * key,
struct digest_algorithm * digest,
const void * value,
struct asn1_builder * signature )
inlinestatic

Definition at line 301 of file crypto.h.

303 {
304 return pubkey->sign ( key, digest, value, signature );
305}
u8 signature
CPU signature.
Definition CIB_PRM.h:7
pseudo_bit_t value[0x00020]
Definition arbel.h:2
int(* sign)(const struct asn1_cursor *key, struct digest_algorithm *digest, const void *value, struct asn1_builder *builder)
Sign digest value.
Definition crypto.h:153

References key, pubkey_algorithm::sign, signature, and value.

Referenced by icert_cert(), pubkey_sign_okx(), and tls_send_certificate_verify().

◆ pubkey_verify()

int pubkey_verify ( struct pubkey_algorithm * pubkey,
const struct asn1_cursor * key,
struct digest_algorithm * digest,
const void * value,
const struct asn1_cursor * signature )
inlinestatic

Definition at line 308 of file crypto.h.

310 {
311 return pubkey->verify ( key, digest, value, signature );
312}
int(* verify)(const struct asn1_cursor *key, struct digest_algorithm *digest, const void *value, const struct asn1_cursor *signature)
Verify signed digest value.
Definition crypto.h:164

References key, signature, value, and pubkey_algorithm::verify.

Referenced by cms_verify_digest(), ocsp_check_signature(), pubkey_sign_okx(), tls_verify_dh_params(), and x509_check_signature().

◆ pubkey_match()

int pubkey_match ( struct pubkey_algorithm * pubkey,
const struct asn1_cursor * private_key,
const struct asn1_cursor * public_key )
inlinestatic

Definition at line 315 of file crypto.h.

317 {
318 return pubkey->match ( private_key, public_key );
319}
A private key.
Definition privkey.h:17
int(* match)(const struct asn1_cursor *private_key, const struct asn1_cursor *public_key)
Check that public key matches private key.
Definition crypto.h:173

References pubkey_algorithm::match.

Referenced by pubkey_okx(), pubkey_sign_okx(), and x509_find_key().

◆ elliptic_is_infinity()

int elliptic_is_infinity ( struct elliptic_curve * curve,
const void * point )
inlinestatic

Definition at line 322 of file crypto.h.

322 {
323 return curve->is_infinity ( point );
324}
int(* is_infinity)(const void *point)
Check if this is the point at infinity.
Definition crypto.h:198

References elliptic_curve::is_infinity.

Referenced by ecdhe_key(), ecdsa_parse_key(), ecdsa_verify_rs(), and elliptic_curve_okx().

◆ elliptic_multiply()

int elliptic_multiply ( struct elliptic_curve * curve,
const void * base,
const void * scalar,
void * result )
inlinestatic

Definition at line 327 of file crypto.h.

328 {
329 return curve->multiply ( base, scalar, result );
330}
uint16_t result
Definition hyperv.h:33
uint32_t base
Base.
Definition librm.h:3
int(* multiply)(const void *base, const void *scalar, void *result)
Multiply scalar by curve point.
Definition crypto.h:206

References base, elliptic_curve::multiply, and result.

Referenced by ecdhe_key(), ecdsa_sign_rs(), ecdsa_verify_rs(), elliptic_curve_okx(), and elliptic_multiply_okx().

◆ elliptic_add()

int elliptic_add ( struct elliptic_curve * curve,
const void * addend,
const void * augend,
void * result )
inlinestatic

Definition at line 333 of file crypto.h.

334 {
335 return curve->add ( addend, augend, result );
336}
int(* add)(const void *addend, const void *augend, void *result)
Add curve points (as a one-off operation)
Definition crypto.h:215

References elliptic_curve::add, and result.

Referenced by ecdsa_verify_rs(), and elliptic_add_okx().

◆ digest_null_init()

void digest_null_init ( void * ctx)
extern

References ctx.

◆ digest_null_update()

void digest_null_update ( void * ctx,
const void * src,
size_t len )
extern

References ctx, len, and src.

◆ digest_null_final()

void digest_null_final ( void * ctx,
void * out )
extern

References ctx, and out.

◆ cipher_null_setkey()

int cipher_null_setkey ( void * ctx,
const void * key,
size_t keylen )
extern

References ctx, and key.

◆ cipher_null_setiv()

void cipher_null_setiv ( void * ctx,
const void * iv,
size_t ivlen )
extern

References ctx, and iv.

◆ cipher_null_encrypt()

void cipher_null_encrypt ( void * ctx,
const void * src,
void * dst,
size_t len )
extern

References ctx, len, and src.

◆ cipher_null_decrypt()

void cipher_null_decrypt ( void * ctx,
const void * src,
void * dst,
size_t len )
extern

References ctx, len, and src.

◆ cipher_null_auth()

void cipher_null_auth ( void * ctx,
void * auth )
extern

References ctx.

◆ pubkey_null_encrypt()

int pubkey_null_encrypt ( const struct asn1_cursor * key,
const struct asn1_cursor * plaintext,
struct asn1_builder * ciphertext )
extern

References key.

◆ pubkey_null_decrypt()

int pubkey_null_decrypt ( const struct asn1_cursor * key,
const struct asn1_cursor * ciphertext,
struct asn1_builder * plaintext )
extern

References key.

◆ pubkey_null_sign()

int pubkey_null_sign ( const struct asn1_cursor * key,
struct digest_algorithm * digest,
const void * value,
struct asn1_builder * signature )
extern

References key, signature, and value.

◆ pubkey_null_verify()

int pubkey_null_verify ( const struct asn1_cursor * key,
struct digest_algorithm * digest,
const void * value,
const struct asn1_cursor * signature )
extern

Variable Documentation

◆ digest_null

struct digest_algorithm digest_null
extern

Definition at line 49 of file crypto_null.c.

49 {
50 .name = "null",
51 .ctxsize = 0,
52 .blocksize = 1,
53 .digestsize = 0,
54 .init = digest_null_init,
55 .update = digest_null_update,
56 .final = digest_null_final,
57};
void digest_null_init(void *ctx __unused)
Definition crypto_null.c:36
void digest_null_final(void *ctx __unused, void *out __unused)
Definition crypto_null.c:45
void digest_null_update(void *ctx __unused, const void *src __unused, size_t len __unused)
Definition crypto_null.c:40

Referenced by cms_parse_participants(), pubkey_null_verify(), and tls_clear_handshake().

◆ cipher_null

struct cipher_algorithm cipher_null
extern

Definition at line 84 of file crypto_null.c.

84 {
85 .name = "null",
86 .ctxsize = 0,
87 .blocksize = 1,
88 .alignsize = 1,
89 .authsize = 0,
90 .setkey = cipher_null_setkey,
91 .setiv = cipher_null_setiv,
92 .encrypt = cipher_null_encrypt,
93 .decrypt = cipher_null_decrypt,
94 .auth = cipher_null_auth,
95};
void cipher_null_setiv(void *ctx __unused, const void *iv __unused, size_t ivlen __unused)
Definition crypto_null.c:65
void cipher_null_encrypt(void *ctx __unused, const void *src, void *dst, size_t len)
Definition crypto_null.c:70
void cipher_null_decrypt(void *ctx __unused, const void *src, void *dst, size_t len)
Definition crypto_null.c:75
void cipher_null_auth(void *ctx __unused, void *auth __unused)
Definition crypto_null.c:80
int cipher_null_setkey(void *ctx __unused, const void *key __unused, size_t keylen __unused)
Definition crypto_null.c:59

Referenced by cms_message(), and pubkey_null_verify().

◆ pubkey_null

struct pubkey_algorithm pubkey_null
extern

Definition at line 123 of file crypto_null.c.

123 {
124 .name = "null",
125 .encrypt = pubkey_null_encrypt,
126 .decrypt = pubkey_null_decrypt,
127 .sign = pubkey_null_sign,
128 .verify = pubkey_null_verify,
129};
int pubkey_null_decrypt(const struct asn1_cursor *key __unused, const struct asn1_cursor *ciphertext __unused, struct asn1_builder *plaintext __unused)
int pubkey_null_sign(const struct asn1_cursor *key __unused, struct digest_algorithm *digest __unused, const void *value __unused, struct asn1_builder *signature __unused)
int pubkey_null_verify(const struct asn1_cursor *key __unused, struct digest_algorithm *digest __unused, const void *value __unused, const struct asn1_cursor *signature __unused)
int pubkey_null_encrypt(const struct asn1_cursor *key __unused, const struct asn1_cursor *plaintext __unused, struct asn1_builder *ciphertext __unused)
Definition crypto_null.c:97

Referenced by cms_parse_participants(), and pubkey_null_verify().