You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

cbc_test.h 1.7KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. #ifndef _CBC_TEST_H
  2. #define _CBC_TEST_H
  3. FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL );
  4. #include <stdint.h>
  5. #include <ipxe/crypto.h>
  6. #include <ipxe/test.h>
  7. extern int cbc_test_encrypt ( struct cipher_algorithm *cipher, const void *key,
  8. size_t key_len, const void *iv,
  9. const void *plaintext,
  10. const void *expected_ciphertext, size_t len );
  11. extern int cbc_test_decrypt ( struct cipher_algorithm *cipher, const void *key,
  12. size_t key_len, const void *iv,
  13. const void *ciphertext,
  14. const void *expected_plaintext, size_t len );
  15. extern unsigned long cbc_cost_encrypt ( struct cipher_algorithm *cipher,
  16. size_t key_len );
  17. extern unsigned long cbc_cost_decrypt ( struct cipher_algorithm *cipher,
  18. size_t key_len );
  19. /**
  20. * Report CBC encryption test result
  21. *
  22. * @v cipher Cipher algorithm
  23. * @v key Key
  24. * @v key_len Length of key
  25. * @v iv Initialisation vector
  26. * @v plaintext Plaintext data
  27. * @v expected_ciphertext Expected ciphertext data
  28. * @v len Length of data
  29. */
  30. #define cbc_encrypt_ok( cipher, key, key_len, iv, plaintext, \
  31. expected_ciphertext, len ) do { \
  32. ok ( cbc_test_encrypt ( cipher, key, key_len, iv, plaintext, \
  33. expected_ciphertext, len ) ); \
  34. } while ( 0 )
  35. /**
  36. * Report CBC decryption test result
  37. *
  38. * @v cipher Cipher algorithm
  39. * @v key Key
  40. * @v key_len Length of key
  41. * @v iv Initialisation vector
  42. * @v ciphertext Ciphertext data
  43. * @v expected_plaintext Expected plaintext data
  44. * @v len Length of data
  45. */
  46. #define cbc_decrypt_ok( cipher, key, key_len, iv, ciphertext, \
  47. expected_plaintext, len ) do { \
  48. ok ( cbc_test_decrypt ( cipher, key, key_len, iv, ciphertext, \
  49. expected_plaintext, len ) ); \
  50. } while ( 0 )
  51. #endif /* _CBC_TEST_H */