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 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_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)
 
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:28
static const void * src
Definition: string.h:47
ring len
Length.
Definition: dwmac.h:231

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 const void * src
Definition: string.h:47
ring len
Length.
Definition: dwmac.h:231

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

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

213  {
214  return cipher->setkey ( ctx, key, keylen );
215 }
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 @391 key
Sense key.
Definition: scsi.h:17

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

219  {
220  cipher->setiv ( ctx, iv, ivlen );
221 }
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_record().

◆ cipher_encrypt()

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

Definition at line 224 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:99
static const void * src
Definition: string.h:47
ring len
Length.
Definition: dwmac.h:231

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 234 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:110
struct golan_eq_context ctx
Definition: CIB_PRM.h:28
static const void * src
Definition: string.h:47
ring len
Length.
Definition: dwmac.h:231

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 244 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:117

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

static int is_stream_cipher ( struct cipher_algorithm cipher)
inlinestatic

Definition at line 249 of file crypto.h.

249  {
250  return ( cipher->blocksize == 1 );
251 }
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 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.

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

◆ is_auth_cipher()

static int is_auth_cipher ( struct cipher_algorithm cipher)
inlinestatic

Definition at line 259 of file crypto.h.

259  {
260  return cipher->authsize;
261 }
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_record().

◆ pubkey_encrypt()

static 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 264 of file crypto.h.

266  {
267  return pubkey->encrypt ( key, plaintext, ciphertext );
268 }
int(* encrypt)(const struct asn1_cursor *key, const struct asn1_cursor *plaintext, struct asn1_builder *ciphertext)
Encrypt.
Definition: crypto.h:131
union @391 key
Sense key.
Definition: scsi.h:17

References pubkey_algorithm::encrypt, and key.

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 struct asn1_cursor ciphertext,
struct asn1_builder plaintext 
)
inlinestatic

Definition at line 271 of file crypto.h.

273  {
274  return pubkey->decrypt ( key, ciphertext, plaintext );
275 }
int(* decrypt)(const struct asn1_cursor *key, const struct asn1_cursor *ciphertext, struct asn1_builder *plaintext)
Decrypt.
Definition: crypto.h:141
union @391 key
Sense key.
Definition: scsi.h:17

References pubkey_algorithm::decrypt, and key.

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,
struct asn1_builder signature 
)
inlinestatic

Definition at line 278 of file crypto.h.

280  {
281  return pubkey->sign ( key, digest, value, signature );
282 }
pseudo_bit_t value[0x00020]
Definition: arbel.h:13
u8 signature
CPU signature.
Definition: CIB_PRM.h:35
int(* sign)(const struct asn1_cursor *key, struct digest_algorithm *digest, const void *value, struct asn1_builder *builder)
Sign digest value.
Definition: crypto.h:152
union @391 key
Sense key.
Definition: scsi.h:17

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 struct asn1_cursor signature 
)
inlinestatic

Definition at line 285 of file crypto.h.

287  {
288  return pubkey->verify ( key, digest, value, signature );
289 }
pseudo_bit_t value[0x00020]
Definition: arbel.h:13
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:163
u8 signature
CPU signature.
Definition: CIB_PRM.h:35
union @391 key
Sense key.
Definition: scsi.h:17

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

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

References pubkey_algorithm::match.

Referenced by pubkey_okx(), pubkey_sign_okx(), and 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 299 of file crypto.h.

300  {
301  return curve->multiply ( base, scalar, result );
302 }
int(* multiply)(const void *base, const void *scalar, void *result)
Multiply scalar by curve point.
Definition: crypto.h:191
uint32_t base
Base.
Definition: librm.h:138
uint16_t result
Definition: hyperv.h:33

References base, elliptic_curve::multiply, and result.

Referenced by ecdhe_key(), and elliptic_okx().

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

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

◆ pubkey_null_decrypt()

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

◆ pubkey_null_sign()

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

◆ pubkey_null_verify()

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

Variable Documentation

◆ digest_null

struct digest_algorithm digest_null

Definition at line 48 of file crypto_null.c.

Referenced by cms_parse_participants(), and 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 122 of file crypto_null.c.

Referenced by cms_parse_participants().