10 FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL );
13 #include <ipxe/crypto.h>
14 #include <ipxe/test.h>
18 /** Cipher algorithm */
19 struct cipher_algorithm *cipher;
24 /** Initialisation vector */
26 /** Length of initialisation vector */
29 const void *plaintext;
31 const void *ciphertext;
36 /** Define inline key */
37 #define KEY(...) { __VA_ARGS__ }
39 /** Define inline initialisation vector */
40 #define IV(...) { __VA_ARGS__ }
42 /** Define inline plaintext data */
43 #define PLAINTEXT(...) { __VA_ARGS__ }
45 /** Define inline ciphertext data */
46 #define CIPHERTEXT(...) { __VA_ARGS__ }
49 * Define a cipher test
52 * @v CIPHER Cipher algorithm
54 * @v IV Initialisation vector
55 * @v PLAINTEXT Plaintext
56 * @v CIPHERTEXT Ciphertext
57 * @ret test Cipher test
59 #define CIPHER_TEST( name, CIPHER, KEY, IV, PLAINTEXT, CIPHERTEXT ) \
60 static const uint8_t name ## _key [] = KEY; \
61 static const uint8_t name ## _iv [] = IV; \
62 static const uint8_t name ## _plaintext [] = PLAINTEXT; \
63 static const uint8_t name ## _ciphertext \
64 [ sizeof ( name ## _plaintext ) ] = CIPHERTEXT; \
65 static struct cipher_test name = { \
67 .key = name ## _key, \
68 .key_len = sizeof ( name ## _key ), \
70 .iv_len = sizeof ( name ## _iv ), \
71 .plaintext = name ## _plaintext, \
72 .ciphertext = name ## _ciphertext, \
73 .len = sizeof ( name ## _plaintext ), \
76 extern void cipher_encrypt_okx ( struct cipher_test *test, const char *file,
78 extern void cipher_decrypt_okx ( struct cipher_test *test, const char *file,
80 extern void cipher_okx ( struct cipher_test *test, const char *file,
82 extern unsigned long cipher_cost_encrypt ( struct cipher_algorithm *cipher,
84 extern unsigned long cipher_cost_decrypt ( struct cipher_algorithm *cipher,
88 * Report a cipher encryption test result
92 #define cipher_encrypt_ok( test ) \
93 cipher_encrypt_okx ( test, __FILE__, __LINE__ )
96 * Report a cipher decryption test result
100 #define cipher_decrypt_ok( test ) \
101 cipher_decrypt_okx ( test, __FILE__, __LINE__ )
104 * Report a cipher encryption and decryption test result
106 * @v test Cipher test
108 #define cipher_ok( test ) \
109 cipher_okx ( test, __FILE__, __LINE__ )
111 #endif /* _CIPHER_TEST_H */