iPXE
Macros | Functions
pubkey_test.h File Reference
#include <stdint.h>
#include <ipxe/crypto.h>
#include <ipxe/test.h>

Go to the source code of this file.

Macros

#define pubkey_decrypt_ok(pubkey, key, key_len, ciphertext, ciphertext_len, expected, expected_len)
 Report public key decryption test result. More...
 
#define pubkey_encrypt_ok(pubkey, encrypt_key, encrypt_key_len, decrypt_key, decrypt_key_len, plaintext, plaintext_len)
 Report public key encryption and decryption test result. More...
 
#define pubkey_sign_ok(pubkey, key, key_len, digest, plaintext, plaintext_len, expected, expected_len)
 Report public key signature test result. More...
 
#define pubkey_verify_ok(pubkey, key, key_len, digest, plaintext, plaintext_len, signature, signature_len)
 Report public key verification test result. More...
 
#define pubkey_verify_fail_ok(pubkey, key, key_len, digest, plaintext, plaintext_len, signature, signature_len)
 Report public key verification test result. More...
 

Functions

 FILE_LICENCE (GPL2_OR_LATER_OR_UBDL)
 

Macro Definition Documentation

◆ pubkey_decrypt_ok

#define pubkey_decrypt_ok (   pubkey,
  key,
  key_len,
  ciphertext,
  ciphertext_len,
  expected,
  expected_len 
)
Value:
do {\
uint8_t ctx[ (pubkey)->ctxsize ]; \
ok ( pubkey_init ( (pubkey), ctx, (key), (key_len) ) == 0 ); \
{ \
size_t max_len = pubkey_max_len ( (pubkey), ctx ); \
uint8_t decrypted[ max_len ]; \
int decrypted_len; \
\
decrypted_len = pubkey_decrypt ( (pubkey), ctx, \
(ciphertext), \
(ciphertext_len), \
decrypted ); \
ok ( decrypted_len == ( ( int ) (expected_len) ) ); \
ok ( memcmp ( decrypted, (expected), \
(expected_len) ) == 0 ); \
} \
pubkey_final ( (pubkey), ctx ); \
} while ( 0 )
static int pubkey_decrypt(struct pubkey_algorithm *pubkey, void *ctx, const void *data, size_t len, void *out)
Definition: crypto.h:236
static void size_t size_t max_len
Definition: entropy.h:153
struct golan_eq_context ctx
Definition: CIB_PRM.h:28
static size_t pubkey_max_len(struct pubkey_algorithm *pubkey, void *ctx)
Definition: crypto.h:226
#define ok(success)
Definition: test.h:46
int memcmp(const void *first, const void *second, size_t len)
Compare memory regions.
Definition: string.c:113
union @376 key
Sense key.
Definition: scsi.h:18
static int pubkey_init(struct pubkey_algorithm *pubkey, void *ctx, const void *key, size_t key_len)
Definition: crypto.h:221

Report public key decryption test result.

Parameters
pubkeyPublic key algorithm
keyKey
key_lenKey length
ciphertextCiphertext
ciphertext_lenCiphertext length
expectedExpected plaintext
expected_lenExpected plaintext length

Definition at line 21 of file pubkey_test.h.

◆ pubkey_encrypt_ok

#define pubkey_encrypt_ok (   pubkey,
  encrypt_key,
  encrypt_key_len,
  decrypt_key,
  decrypt_key_len,
  plaintext,
  plaintext_len 
)
Value:
do { \
uint8_t ctx[ (pubkey)->ctxsize ]; \
ok ( pubkey_init ( (pubkey), ctx, (encrypt_key), \
(encrypt_key_len) ) == 0 ); \
{ \
size_t max_len = pubkey_max_len ( (pubkey), ctx ); \
uint8_t encrypted[ max_len ]; \
int encrypted_len; \
\
encrypted_len = pubkey_encrypt ( (pubkey), ctx, \
(plaintext), \
(plaintext_len), \
encrypted ); \
ok ( encrypted_len >= 0 ); \
pubkey_decrypt_ok ( (pubkey), (decrypt_key), \
(decrypt_key_len), encrypted, \
encrypted_len, (plaintext), \
(plaintext_len) ); \
} \
pubkey_final ( (pubkey), ctx ); \
} while ( 0 )
static void size_t size_t max_len
Definition: entropy.h:153
struct golan_eq_context ctx
Definition: CIB_PRM.h:28
static size_t pubkey_max_len(struct pubkey_algorithm *pubkey, void *ctx)
Definition: crypto.h:226
static int pubkey_encrypt(struct pubkey_algorithm *pubkey, void *ctx, const void *data, size_t len, void *out)
Definition: crypto.h:231
#define ok(success)
Definition: test.h:46
static int pubkey_init(struct pubkey_algorithm *pubkey, void *ctx, const void *key, size_t key_len)
Definition: crypto.h:221

Report public key encryption and decryption test result.

Parameters
pubkeyPublic key algorithm
encrypt_keyEncryption key
encrypt_key_lenEncryption key length
decrypt_keyDecryption key
decrypt_key_lenDecryption key length
plaintextPlaintext
plaintext_lenPlaintext length

Definition at line 53 of file pubkey_test.h.

◆ pubkey_sign_ok

#define pubkey_sign_ok (   pubkey,
  key,
  key_len,
  digest,
  plaintext,
  plaintext_len,
  expected,
  expected_len 
)
Value:
do { \
uint8_t ctx[ (pubkey)->ctxsize ]; \
uint8_t digestctx[ (digest)->ctxsize ]; \
uint8_t digestout[ (digest)->digestsize ]; \
digest_init ( (digest), digestctx ); \
digest_update ( (digest), digestctx, (plaintext), \
(plaintext_len) ); \
digest_final ( (digest), digestctx, digestout ); \
ok ( pubkey_init ( (pubkey), ctx, (key), (key_len) ) == 0 ); \
{ \
size_t max_len = pubkey_max_len ( (pubkey), ctx ); \
uint8_t signature[ max_len ]; \
int signature_len; \
\
signature_len = pubkey_sign ( (pubkey), ctx, (digest), \
digestout, signature ); \
ok ( signature_len == ( ( int ) (expected_len) ) ); \
ok ( memcmp ( signature, (expected), \
(expected_len) ) == 0 ); \
} \
pubkey_final ( (pubkey), ctx ); \
} while ( 0 )
static void size_t size_t max_len
Definition: entropy.h:153
struct golan_eq_context ctx
Definition: CIB_PRM.h:28
struct md4_digest digest
Digest of data already processed.
Definition: md4.h:12
static size_t pubkey_max_len(struct pubkey_algorithm *pubkey, void *ctx)
Definition: crypto.h:226
u8 signature
Definition: CIB_PRM.h:35
static void digest_init(struct digest_algorithm *digest, void *ctx)
Definition: crypto.h:172
static int pubkey_sign(struct pubkey_algorithm *pubkey, void *ctx, struct digest_algorithm *digest, const void *value, void *signature)
Definition: crypto.h:241
uint32_t digestsize
Digest size (i.e.
Definition: pccrr.h:14
#define ok(success)
Definition: test.h:46
int memcmp(const void *first, const void *second, size_t len)
Compare memory regions.
Definition: string.c:113
union @376 key
Sense key.
Definition: scsi.h:18
static int pubkey_init(struct pubkey_algorithm *pubkey, void *ctx, const void *key, size_t key_len)
Definition: crypto.h:221

Report public key signature test result.

Parameters
pubkeyPublic key algorithm
keyKey
key_lenKey length
digestDigest algorithm
plaintextPlaintext
plaintext_lenPlaintext length
expectedExpected signature
expected_lenExpected signature length

Definition at line 90 of file pubkey_test.h.

◆ pubkey_verify_ok

#define pubkey_verify_ok (   pubkey,
  key,
  key_len,
  digest,
  plaintext,
  plaintext_len,
  signature,
  signature_len 
)
Value:
do {\
uint8_t ctx[ (pubkey)->ctxsize ]; \
uint8_t digestctx[ (digest)->ctxsize ]; \
uint8_t digestout[ (digest)->digestsize ]; \
digest_init ( (digest), digestctx ); \
digest_update ( (digest), digestctx, (plaintext), \
(plaintext_len) ); \
digest_final ( (digest), digestctx, digestout ); \
ok ( pubkey_init ( (pubkey), ctx, (key), (key_len) ) == 0 ); \
ok ( pubkey_verify ( (pubkey), ctx, (digest), digestout, \
(signature), (signature_len) ) == 0 ); \
pubkey_final ( (pubkey), ctx ); \
} while ( 0 )
struct golan_eq_context ctx
Definition: CIB_PRM.h:28
struct md4_digest digest
Digest of data already processed.
Definition: md4.h:12
u8 signature
Definition: CIB_PRM.h:35
static int pubkey_verify(struct pubkey_algorithm *pubkey, void *ctx, struct digest_algorithm *digest, const void *value, const void *signature, size_t signature_len)
Definition: crypto.h:247
static void digest_init(struct digest_algorithm *digest, void *ctx)
Definition: crypto.h:172
uint32_t digestsize
Digest size (i.e.
Definition: pccrr.h:14
#define ok(success)
Definition: test.h:46
union @376 key
Sense key.
Definition: scsi.h:18
static int pubkey_init(struct pubkey_algorithm *pubkey, void *ctx, const void *key, size_t key_len)
Definition: crypto.h:221

Report public key verification test result.

Parameters
pubkeyPublic key algorithm
keyKey
key_lenKey length
digestDigest algorithm
plaintextPlaintext
plaintext_lenPlaintext length
signatureSignature
signature_lenSignature length

Definition at line 128 of file pubkey_test.h.

◆ pubkey_verify_fail_ok

#define pubkey_verify_fail_ok (   pubkey,
  key,
  key_len,
  digest,
  plaintext,
  plaintext_len,
  signature,
  signature_len 
)
Value:
do { \
uint8_t ctx[ (pubkey)->ctxsize ]; \
uint8_t digestctx[ (digest)->ctxsize ]; \
uint8_t digestout[ (digest)->digestsize ]; \
digest_init ( (digest), digestctx ); \
digest_update ( (digest), digestctx, (plaintext), \
(plaintext_len) ); \
digest_final ( (digest), digestctx, digestout ); \
ok ( pubkey_init ( (pubkey), ctx, (key), (key_len) ) == 0 ); \
ok ( pubkey_verify ( (pubkey), ctx, (digest), digestout, \
(signature), (signature_len) ) != 0 ); \
pubkey_final ( (pubkey), ctx ); \
} while ( 0 )
struct golan_eq_context ctx
Definition: CIB_PRM.h:28
struct md4_digest digest
Digest of data already processed.
Definition: md4.h:12
u8 signature
Definition: CIB_PRM.h:35
static int pubkey_verify(struct pubkey_algorithm *pubkey, void *ctx, struct digest_algorithm *digest, const void *value, const void *signature, size_t signature_len)
Definition: crypto.h:247
static void digest_init(struct digest_algorithm *digest, void *ctx)
Definition: crypto.h:172
uint32_t digestsize
Digest size (i.e.
Definition: pccrr.h:14
#define ok(success)
Definition: test.h:46
union @376 key
Sense key.
Definition: scsi.h:18
static int pubkey_init(struct pubkey_algorithm *pubkey, void *ctx, const void *key, size_t key_len)
Definition: crypto.h:221

Report public key verification test result.

Parameters
pubkeyPublic key algorithm
keyKey
key_lenKey length
digestDigest algorithm
plaintextPlaintext
plaintext_lenPlaintext length
signatureSignature
signature_lenSignature length

Definition at line 157 of file pubkey_test.h.

Function Documentation

◆ FILE_LICENCE()

FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL  )