iPXE
Data Structures | Macros | Functions | Variables
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)
 
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 size_t pubkey_max_len (struct pubkey_algorithm *pubkey, const struct asn1_cursor *key)
 
static int pubkey_encrypt (struct pubkey_algorithm *pubkey, const struct asn1_cursor *key, const void *data, size_t len, void *out)
 
static int pubkey_decrypt (struct pubkey_algorithm *pubkey, const struct asn1_cursor *key, const void *data, size_t len, void *out)
 
static int pubkey_sign (struct pubkey_algorithm *pubkey, const struct asn1_cursor *key, struct digest_algorithm *digest, const void *value, void *signature)
 
static int pubkey_verify (struct pubkey_algorithm *pubkey, const struct asn1_cursor *key, struct digest_algorithm *digest, const void *value, const void *signature, size_t signature_len)
 
static int pubkey_match (struct pubkey_algorithm *pubkey, const struct asn1_cursor *private_key, const struct asn1_cursor *public_key)
 
static int elliptic_multiply (struct elliptic_curve *curve, const void *base, const void *scalar, 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)
 
size_t pubkey_null_max_len (const struct asn1_cursor *key)
 
int pubkey_null_encrypt (const struct asn1_cursor *key, const void *plaintext, size_t plaintext_len, void *ciphertext)
 
int pubkey_null_decrypt (const struct asn1_cursor *key, const void *ciphertext, size_t ciphertext_len, void *plaintext)
 
int pubkey_null_sign (const struct asn1_cursor *key, struct digest_algorithm *digest, const void *value, void *signature)
 
int pubkey_null_verify (const struct asn1_cursor *key, struct digest_algorithm *digest, const void *value, const void *signature, size_t signature_len)
 

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 )
static const void * src
Definition: string.h:47
struct golan_eq_context ctx
Definition: CIB_PRM.h:28
uint32_t len
Length.
Definition: ena.h:14

Definition at line 233 of file crypto.h.

◆ 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 )
static const void * src
Definition: string.h:47
struct golan_eq_context ctx
Definition: CIB_PRM.h:28
uint32_t len
Length.
Definition: ena.h:14

Definition at line 243 of file crypto.h.

Function Documentation

◆ FILE_LICENCE()

FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL  )

◆ digest_init()

static void digest_init ( struct digest_algorithm digest,
void *  ctx 
)
inlinestatic

◆ digest_update()

static void digest_update ( struct digest_algorithm digest,
void *  ctx,
const void *  data,
size_t  len 
)
inlinestatic

◆ digest_final()

static void digest_final ( struct digest_algorithm digest,
void *  ctx,
void *  out 
)
inlinestatic

◆ cipher_setkey()

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

Definition at line 217 of file crypto.h.

218  {
219  return cipher->setkey ( ctx, key, keylen );
220 }
struct golan_eq_context ctx
Definition: CIB_PRM.h:28
int(* setkey)(void *ctx, const void *key, size_t keylen)
Set key.
Definition: crypto.h:82
union @383 key
Sense key.
Definition: scsi.h:18

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()

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

Definition at line 223 of file crypto.h.

224  {
225  cipher->setiv ( ctx, iv, ivlen );
226 }
struct golan_eq_context ctx
Definition: CIB_PRM.h:28
u8 iv[16]
Initialization vector.
Definition: wpa.h:60
void(* setiv)(void *ctx, const void *iv, size_t ivlen)
Set initialisation vector.
Definition: crypto.h:89

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_plaintext().

◆ cipher_encrypt()

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

Definition at line 229 of file crypto.h.

230  {
231  cipher->encrypt ( ctx, src, dst, len );
232 }
static const void * src
Definition: string.h:47
struct golan_eq_context ctx
Definition: CIB_PRM.h:28
void(* encrypt)(void *ctx, const void *src, void *dst, size_t len)
Encrypt data.
Definition: crypto.h:99
uint32_t len
Length.
Definition: ena.h:14

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

◆ cipher_decrypt()

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

Definition at line 239 of file crypto.h.

240  {
241  cipher->decrypt ( ctx, src, dst, len );
242 }
static const void * src
Definition: string.h:47
void(* decrypt)(void *ctx, const void *src, void *dst, size_t len)
Decrypt data.
Definition: crypto.h:110
struct golan_eq_context ctx
Definition: CIB_PRM.h:28
uint32_t len
Length.
Definition: ena.h:14

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

◆ cipher_auth()

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

Definition at line 249 of file crypto.h.

249  {
250  cipher->auth ( ctx, auth );
251 }
struct golan_eq_context ctx
Definition: CIB_PRM.h:28
void(* auth)(void *ctx, void *auth)
Generate authentication tag.
Definition: crypto.h:117

References cipher_algorithm::auth, and ctx.

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

◆ is_stream_cipher()

static int is_stream_cipher ( struct cipher_algorithm cipher)
inlinestatic

Definition at line 254 of file crypto.h.

254  {
255  return ( cipher->blocksize == 1 );
256 }
size_t blocksize
Block size.
Definition: crypto.h:60

References cipher_algorithm::blocksize.

◆ is_block_cipher()

static int is_block_cipher ( struct cipher_algorithm cipher)
inlinestatic

Definition at line 259 of file crypto.h.

259  {
260  return ( cipher->blocksize > 1 );
261 }
size_t blocksize
Block size.
Definition: crypto.h:60

References cipher_algorithm::blocksize.

Referenced by cms_verify_padding(), tls_new_ciphertext(), and tls_send_plaintext().

◆ is_auth_cipher()

static int is_auth_cipher ( struct cipher_algorithm cipher)
inlinestatic

Definition at line 264 of file crypto.h.

264  {
265  return cipher->authsize;
266 }
size_t authsize
Authentication tag size.
Definition: crypto.h:74

References cipher_algorithm::authsize.

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

◆ pubkey_max_len()

static size_t pubkey_max_len ( struct pubkey_algorithm pubkey,
const struct asn1_cursor key 
)
inlinestatic

Definition at line 269 of file crypto.h.

270  {
271  return pubkey->max_len ( key );
272 }
size_t(* max_len)(const struct asn1_cursor *key)
Calculate maximum output length.
Definition: crypto.h:129
union @383 key
Sense key.
Definition: scsi.h:18

References key, and pubkey_algorithm::max_len.

Referenced by cms_cipher_key(), icert_cert(), pubkey_okx(), pubkey_sign_okx(), tls_send_certificate_verify(), and tls_send_client_key_exchange_pubkey().

◆ pubkey_encrypt()

static int pubkey_encrypt ( struct pubkey_algorithm pubkey,
const struct asn1_cursor key,
const void *  data,
size_t  len,
void *  out 
)
inlinestatic

Definition at line 275 of file crypto.h.

276  {
277  return pubkey->encrypt ( key, data, len, out );
278 }
int(* encrypt)(const struct asn1_cursor *key, const void *data, size_t len, void *out)
Encrypt.
Definition: crypto.h:138
__be32 out[4]
Definition: CIB_PRM.h:36
uint8_t data[48]
Additional event data.
Definition: ena.h:22
uint32_t len
Length.
Definition: ena.h:14
union @383 key
Sense key.
Definition: scsi.h:18

References data, pubkey_algorithm::encrypt, key, len, and out.

Referenced by pubkey_okx(), and tls_send_client_key_exchange_pubkey().

◆ pubkey_decrypt()

static int pubkey_decrypt ( struct pubkey_algorithm pubkey,
const struct asn1_cursor key,
const void *  data,
size_t  len,
void *  out 
)
inlinestatic

Definition at line 281 of file crypto.h.

282  {
283  return pubkey->decrypt ( key, data, len, out );
284 }
int(* decrypt)(const struct asn1_cursor *key, const void *data, size_t len, void *out)
Decrypt.
Definition: crypto.h:148
__be32 out[4]
Definition: CIB_PRM.h:36
uint8_t data[48]
Additional event data.
Definition: ena.h:22
uint32_t len
Length.
Definition: ena.h:14
union @383 key
Sense key.
Definition: scsi.h:18

References data, pubkey_algorithm::decrypt, key, len, and out.

Referenced by cms_cipher_key(), and pubkey_okx().

◆ pubkey_sign()

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

Definition at line 287 of file crypto.h.

289  {
290  return pubkey->sign ( key, digest, value, signature );
291 }
int(* sign)(const struct asn1_cursor *key, struct digest_algorithm *digest, const void *value, void *signature)
Sign digest value.
Definition: crypto.h:158
pseudo_bit_t value[0x00020]
Definition: arbel.h:13
u8 signature
CPU signature.
Definition: CIB_PRM.h:35
union @383 key
Sense key.
Definition: scsi.h:18

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

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

◆ pubkey_verify()

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

Definition at line 294 of file crypto.h.

296  {
297  return pubkey->verify ( key, digest, value, signature, signature_len );
298 }
pseudo_bit_t value[0x00020]
Definition: arbel.h:13
int(* verify)(const struct asn1_cursor *key, struct digest_algorithm *digest, const void *value, const void *signature, size_t signature_len)
Verify signed digest value.
Definition: crypto.h:170
u8 signature
CPU signature.
Definition: CIB_PRM.h:35
union @383 key
Sense key.
Definition: scsi.h:18

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()

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

Definition at line 301 of file crypto.h.

303  {
304  return pubkey->match ( private_key, public_key );
305 }
int(* match)(const struct asn1_cursor *private_key, const struct asn1_cursor *public_key)
Check that public key matches private key.
Definition: crypto.h:179
A private key.
Definition: privkey.h:16

References pubkey_algorithm::match.

Referenced by x509_find_key().

◆ elliptic_multiply()

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

Definition at line 308 of file crypto.h.

309  {
310  return curve->multiply ( base, scalar, result );
311 }
int(* multiply)(const void *base, const void *scalar, void *result)
Multiply scalar by curve point.
Definition: crypto.h:196
uint32_t base
Base.
Definition: librm.h:252
uint16_t result
Definition: hyperv.h:33

References base, elliptic_curve::multiply, and result.

Referenced by tls_send_client_key_exchange_ecdhe().

◆ digest_null_init()

void digest_null_init ( void *  ctx)

◆ digest_null_update()

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

◆ digest_null_final()

void digest_null_final ( void *  ctx,
void *  out 
)

◆ cipher_null_setkey()

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

◆ cipher_null_setiv()

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

◆ cipher_null_encrypt()

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

◆ cipher_null_decrypt()

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

◆ cipher_null_auth()

void cipher_null_auth ( void *  ctx,
void *  auth 
)

◆ pubkey_null_max_len()

size_t pubkey_null_max_len ( const struct asn1_cursor key)

◆ pubkey_null_encrypt()

int pubkey_null_encrypt ( const struct asn1_cursor key,
const void *  plaintext,
size_t  plaintext_len,
void *  ciphertext 
)

◆ pubkey_null_decrypt()

int pubkey_null_decrypt ( const struct asn1_cursor key,
const void *  ciphertext,
size_t  ciphertext_len,
void *  plaintext 
)

◆ pubkey_null_sign()

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

◆ pubkey_null_verify()

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

Variable Documentation

◆ digest_null

struct digest_algorithm digest_null

Definition at line 48 of file crypto_null.c.

Referenced by tls_clear_handshake().

◆ cipher_null

struct cipher_algorithm cipher_null

Definition at line 83 of file crypto_null.c.

Referenced by cms_message().

◆ pubkey_null

struct pubkey_algorithm pubkey_null

Definition at line 128 of file crypto_null.c.