iPXE
Defines | 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.

Defines

#define pubkey_decrypt_ok(pubkey, key, key_len, ciphertext,ciphertext_len, expected, expected_len)
 Report public key decryption test result.
#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.
#define pubkey_sign_ok(pubkey, key, key_len, digest, plaintext, plaintext_len, expected, expected_len)
 Report public key signature test result.
#define pubkey_verify_ok(pubkey, key, key_len, digest, plaintext, plaintext_len, signature, signature_len)
 Report public key verification test result.
#define pubkey_verify_fail_ok(pubkey, key, key_len, digest, plaintext, plaintext_len, signature,signature_len)
 Report public key verification test result.

Functions

 FILE_LICENCE (GPL2_OR_LATER_OR_UBDL)

Define Documentation

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

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.

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

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.

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

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.

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

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.

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

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