iPXE
Data Structures | Macros | Functions | Variables
crypto.h File Reference

Cryptographic API. More...

#include <stdint.h>
#include <stddef.h>
#include <assert.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...
 

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 int pubkey_init (struct pubkey_algorithm *pubkey, void *ctx, const void *key, size_t key_len)
 
static size_t pubkey_max_len (struct pubkey_algorithm *pubkey, void *ctx)
 
static int pubkey_encrypt (struct pubkey_algorithm *pubkey, void *ctx, const void *data, size_t len, void *out)
 
static int pubkey_decrypt (struct pubkey_algorithm *pubkey, void *ctx, const void *data, size_t len, void *out)
 
static int pubkey_sign (struct pubkey_algorithm *pubkey, void *ctx, struct digest_algorithm *digest, const void *value, void *signature)
 
static int pubkey_verify (struct pubkey_algorithm *pubkey, void *ctx, struct digest_algorithm *digest, const void *value, const void *signature, size_t signature_len)
 
static void pubkey_final (struct pubkey_algorithm *pubkey, void *ctx)
 
static int pubkey_match (struct pubkey_algorithm *pubkey, const void *private_key, size_t private_key_len, const void *public_key, size_t public_key_len)
 
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_init (void *ctx, const void *key, size_t key_len)
 
size_t pubkey_null_max_len (void *ctx)
 
int pubkey_null_encrypt (void *ctx, const void *plaintext, size_t plaintext_len, void *ciphertext)
 
int pubkey_null_decrypt (void *ctx, const void *ciphertext, size_t ciphertext_len, void *plaintext)
 
int pubkey_null_sign (void *ctx, struct digest_algorithm *digest, const void *value, void *signature)
 
int pubkey_null_verify (void *ctx, 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 )
struct golan_eq_context ctx
Definition: CIB_PRM.h:28
static __always_inline void off_t userptr_t src
Definition: efi_uaccess.h:66
uint32_t len
Length.
Definition: ena.h:14

Definition at line 228 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 )
struct golan_eq_context ctx
Definition: CIB_PRM.h:28
static __always_inline void off_t userptr_t src
Definition: efi_uaccess.h:66
uint32_t len
Length.
Definition: ena.h:14

Definition at line 238 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

Definition at line 203 of file crypto.h.

204  {
205  digest->update ( ctx, data, len );
206 }
struct golan_eq_context ctx
Definition: CIB_PRM.h:28
struct md4_digest digest
Digest of data already processed.
Definition: md4.h:12
uint32_t len
Length.
Definition: ena.h:14
struct arbelprm_port_state_change_st data
Message.
Definition: arbel.h:12

References ctx, data, digest, and len.

Referenced by asn1_okx(), chap_update(), cms_digest(), dbg_md5_da(), digest_cost(), digest_exec(), digest_frag_okx(), hash_df(), hmac_final(), hmac_init(), hmac_update(), http_digest_update(), icert_cert(), md5_sha1_update(), ntlm_key(), ocsp_check_signature(), ocsp_compare_responder_key_hash(), ocsp_request(), peerblk_decrypt(), peerblk_raw_rx(), peerdist_info_passphrase_okx(), tls_add_handshake(), tls_send_client_key_exchange_dhe(), x509_check_signature(), and x509_fingerprint().

◆ 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 213 of file crypto.h.

214  {
215  return cipher->setkey ( ctx, key, keylen );
216 }
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:81
union @382 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(), gcm_setkey(), 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 218 of file crypto.h.

219  {
220  cipher->setiv ( ctx, iv, ivlen );
221 }
struct golan_eq_context ctx
Definition: CIB_PRM.h:28
void(* setiv)(void *ctx, const void *iv, size_t ivlen)
Set initialisation vector.
Definition: crypto.h:88
uint8_t iv[12]
Initialisation vector.
Definition: gcm.h:12

References ctx, iv, and cipher_algorithm::setiv.

Referenced by cipher_cost(), cipher_decrypt_okx(), cipher_encrypt_okx(), 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 223 of file crypto.h.

225  {
226  cipher->encrypt ( ctx, src, dst, len );
227 }
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:98
static __always_inline void off_t userptr_t src
Definition: efi_uaccess.h:66
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 233 of file crypto.h.

235  {
236  cipher->decrypt ( ctx, src, dst, len );
237 }
void(* decrypt)(void *ctx, const void *src, void *dst, size_t len)
Decrypt data.
Definition: crypto.h:109
struct golan_eq_context ctx
Definition: CIB_PRM.h:28
static __always_inline void off_t userptr_t src
Definition: efi_uaccess.h:66
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 243 of file crypto.h.

244  {
245  cipher->auth ( ctx, auth );
246 }
struct golan_eq_context ctx
Definition: CIB_PRM.h:28
void(* auth)(void *ctx, void *auth)
Generate authentication tag.
Definition: crypto.h:116

References cipher_algorithm::auth, and ctx.

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

◆ is_stream_cipher()

static int is_stream_cipher ( struct cipher_algorithm cipher)
inlinestatic

Definition at line 248 of file crypto.h.

248  {
249  return ( cipher->blocksize == 1 );
250 }
size_t blocksize
Block size.
Definition: crypto.h:59

References cipher_algorithm::blocksize.

◆ is_block_cipher()

static int is_block_cipher ( struct cipher_algorithm cipher)
inlinestatic

Definition at line 252 of file crypto.h.

252  {
253  return ( cipher->blocksize > 1 );
254 }
size_t blocksize
Block size.
Definition: crypto.h:59

References cipher_algorithm::blocksize.

Referenced by tls_new_ciphertext(), and tls_send_plaintext().

◆ is_auth_cipher()

static int is_auth_cipher ( struct cipher_algorithm cipher)
inlinestatic

Definition at line 256 of file crypto.h.

256  {
257  return cipher->authsize;
258 }
size_t authsize
Authentication tag size.
Definition: crypto.h:73

References cipher_algorithm::authsize.

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

◆ pubkey_init()

static int pubkey_init ( struct pubkey_algorithm pubkey,
void *  ctx,
const void *  key,
size_t  key_len 
)
inlinestatic

Definition at line 260 of file crypto.h.

261  {
262  return pubkey->init ( ctx, key, key_len );
263 }
struct golan_eq_context ctx
Definition: CIB_PRM.h:28
int(* init)(void *ctx, const void *key, size_t key_len)
Initialise algorithm.
Definition: crypto.h:132
union @382 key
Sense key.
Definition: scsi.h:18

References ctx, pubkey_algorithm::init, and key.

Referenced by cms_verify_digest(), icert_cert(), ocsp_check_signature(), tls_send_certificate_verify(), tls_validator_done(), and x509_check_signature().

◆ pubkey_max_len()

static size_t pubkey_max_len ( struct pubkey_algorithm pubkey,
void *  ctx 
)
inlinestatic

Definition at line 265 of file crypto.h.

266  {
267  return pubkey->max_len ( ctx );
268 }
struct golan_eq_context ctx
Definition: CIB_PRM.h:28
size_t(* max_len)(void *ctx)
Calculate maximum output length.
Definition: crypto.h:138

References ctx, and pubkey_algorithm::max_len.

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

◆ pubkey_encrypt()

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

Definition at line 270 of file crypto.h.

271  {
272  return pubkey->encrypt ( ctx, data, len, out );
273 }
struct golan_eq_context ctx
Definition: CIB_PRM.h:28
__be32 out[4]
Definition: CIB_PRM.h:36
int(* encrypt)(void *ctx, const void *data, size_t len, void *out)
Encrypt.
Definition: crypto.h:147
uint32_t len
Length.
Definition: ena.h:14
struct arbelprm_port_state_change_st data
Message.
Definition: arbel.h:12

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

Referenced by tls_send_client_key_exchange_pubkey().

◆ pubkey_decrypt()

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

Definition at line 275 of file crypto.h.

276  {
277  return pubkey->decrypt ( ctx, data, len, out );
278 }
struct golan_eq_context ctx
Definition: CIB_PRM.h:28
__be32 out[4]
Definition: CIB_PRM.h:36
int(* decrypt)(void *ctx, const void *data, size_t len, void *out)
Decrypt.
Definition: crypto.h:157
uint32_t len
Length.
Definition: ena.h:14
struct arbelprm_port_state_change_st data
Message.
Definition: arbel.h:12

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

◆ pubkey_sign()

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

Definition at line 280 of file crypto.h.

282  {
283  return pubkey->sign ( ctx, digest, value, signature );
284 }
struct golan_eq_context ctx
Definition: CIB_PRM.h:28
struct md4_digest digest
Digest of data already processed.
Definition: md4.h:12
pseudo_bit_t value[0x00020]
Definition: arbel.h:13
u8 signature
Signature.
Definition: CIB_PRM.h:35
int(* sign)(void *ctx, struct digest_algorithm *digest, const void *value, void *signature)
Sign digest value.
Definition: crypto.h:167

References ctx, digest, pubkey_algorithm::sign, signature, and value.

Referenced by icert_cert(), and tls_send_certificate_verify().

◆ pubkey_verify()

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

Definition at line 286 of file crypto.h.

289  {
290  return pubkey->verify ( ctx, digest, value, signature, signature_len );
291 }
struct golan_eq_context ctx
Definition: CIB_PRM.h:28
struct md4_digest digest
Digest of data already processed.
Definition: md4.h:12
int(* verify)(void *ctx, struct digest_algorithm *digest, const void *value, const void *signature, size_t signature_len)
Verify signed digest value.
Definition: crypto.h:178
pseudo_bit_t value[0x00020]
Definition: arbel.h:13
u8 signature
Signature.
Definition: CIB_PRM.h:35

References ctx, digest, signature, value, and pubkey_algorithm::verify.

Referenced by cms_verify_digest(), ocsp_check_signature(), tls_send_client_key_exchange_dhe(), and x509_check_signature().

◆ pubkey_final()

static void pubkey_final ( struct pubkey_algorithm pubkey,
void *  ctx 
)
inlinestatic

Definition at line 293 of file crypto.h.

293  {
294  pubkey->final ( ctx );
295 }
struct golan_eq_context ctx
Definition: CIB_PRM.h:28
void(* final)(void *ctx)
Finalise algorithm.
Definition: crypto.h:185

References ctx, and pubkey_algorithm::final.

Referenced by cms_verify_digest(), icert_cert(), ocsp_check_signature(), tls_clear_cipher(), tls_send_certificate_verify(), and x509_check_signature().

◆ pubkey_match()

static int pubkey_match ( struct pubkey_algorithm pubkey,
const void *  private_key,
size_t  private_key_len,
const void *  public_key,
size_t  public_key_len 
)
inlinestatic

Definition at line 297 of file crypto.h.

300  {
301  return pubkey->match ( private_key, private_key_len, public_key,
302  public_key_len );
303 }
int(* match)(const void *private_key, size_t private_key_len, const void *public_key, size_t public_key_len)
Check that public key matches private key.
Definition: crypto.h:194
char private_key_len[]
A private key.
Definition: privkey.h:16

References pubkey_algorithm::match, and private_key_len.

Referenced by certstore_find_key().

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

int pubkey_null_init ( void *  ctx,
const void *  key,
size_t  key_len 
)

◆ pubkey_null_max_len()

size_t pubkey_null_max_len ( void *  ctx)

◆ pubkey_null_encrypt()

int pubkey_null_encrypt ( void *  ctx,
const void *  plaintext,
size_t  plaintext_len,
void *  ciphertext 
)

◆ pubkey_null_decrypt()

int pubkey_null_decrypt ( void *  ctx,
const void *  ciphertext,
size_t  ciphertext_len,
void *  plaintext 
)

◆ pubkey_null_sign()

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

◆ pubkey_null_verify()

int pubkey_null_verify ( void *  ctx,
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.

◆ pubkey_null

struct pubkey_algorithm pubkey_null

Definition at line 135 of file crypto_null.c.