@@ -1919,6 +1919,24 @@ typedef struct {
1919
1919
#endif
1920
1920
} br_aes_pwr8_ctr_keys ;
1921
1921
1922
+ /**
1923
+ * \brief Context for AES subkeys (`aes_pwr8` implementation, CTR encryption
1924
+ * and decryption + CBC-MAC).
1925
+ *
1926
+ * First field is a pointer to the vtable; it is set by the initialisation
1927
+ * function. Other fields are not supposed to be accessed by user code.
1928
+ */
1929
+ typedef struct {
1930
+ /** \brief Pointer to vtable for this context. */
1931
+ const br_block_ctrcbc_class * vtable ;
1932
+ #ifndef BR_DOXYGEN_IGNORE
1933
+ union {
1934
+ unsigned char skni [16 * 15 ];
1935
+ } skey ;
1936
+ unsigned num_rounds ;
1937
+ #endif
1938
+ } br_aes_pwr8_ctrcbc_keys ;
1939
+
1922
1940
/**
1923
1941
* \brief Class instance for AES CBC encryption (`aes_pwr8` implementation).
1924
1942
*
@@ -1947,6 +1965,16 @@ extern const br_block_cbcdec_class br_aes_pwr8_cbcdec_vtable;
1947
1965
*/
1948
1966
extern const br_block_ctr_class br_aes_pwr8_ctr_vtable ;
1949
1967
1968
+ /**
1969
+ * \brief Class instance for AES CTR encryption/decryption + CBC-MAC
1970
+ * (`aes_pwr8` implementation).
1971
+ *
1972
+ * Since this implementation might be omitted from the library, or the
1973
+ * AES opcode unavailable on the current CPU, a pointer to this class
1974
+ * instance should be obtained through `br_aes_pwr8_ctrcbc_get_vtable()`.
1975
+ */
1976
+ extern const br_block_ctrcbc_class br_aes_pwr8_ctrcbc_vtable ;
1977
+
1950
1978
/**
1951
1979
* \brief Context initialisation (key schedule) for AES CBC encryption
1952
1980
* (`aes_pwr8` implementation).
@@ -1980,6 +2008,17 @@ void br_aes_pwr8_cbcdec_init(br_aes_pwr8_cbcdec_keys *ctx,
1980
2008
void br_aes_pwr8_ctr_init (br_aes_pwr8_ctr_keys * ctx ,
1981
2009
const void * key , size_t len );
1982
2010
2011
+ /**
2012
+ * \brief Context initialisation (key schedule) for AES CTR + CBC-MAC
2013
+ * (`aes_pwr8` implementation).
2014
+ *
2015
+ * \param ctx context to initialise.
2016
+ * \param key secret key.
2017
+ * \param len secret key length (in bytes).
2018
+ */
2019
+ void br_aes_pwr8_ctrcbc_init (br_aes_pwr8_ctrcbc_keys * ctx ,
2020
+ const void * key , size_t len );
2021
+
1983
2022
/**
1984
2023
* \brief CBC encryption with AES (`aes_pwr8` implementation).
1985
2024
*
@@ -2015,6 +2054,52 @@ void br_aes_pwr8_cbcdec_run(const br_aes_pwr8_cbcdec_keys *ctx, void *iv,
2015
2054
uint32_t br_aes_pwr8_ctr_run (const br_aes_pwr8_ctr_keys * ctx ,
2016
2055
const void * iv , uint32_t cc , void * data , size_t len );
2017
2056
2057
+ /**
2058
+ * \brief CTR encryption + CBC-MAC with AES (`aes_pwr8` implementation).
2059
+ *
2060
+ * \param ctx context (already initialised).
2061
+ * \param ctr counter for CTR (16 bytes, updated).
2062
+ * \param cbcmac IV for CBC-MAC (updated).
2063
+ * \param data data to encrypt (updated).
2064
+ * \param len data length (in bytes, MUST be a multiple of 16).
2065
+ */
2066
+ void br_aes_pwr8_ctrcbc_encrypt (const br_aes_pwr8_ctrcbc_keys * ctx ,
2067
+ void * ctr , void * cbcmac , void * data , size_t len );
2068
+
2069
+ /**
2070
+ * \brief CTR decryption + CBC-MAC with AES (`aes_pwr8` implementation).
2071
+ *
2072
+ * \param ctx context (already initialised).
2073
+ * \param ctr counter for CTR (16 bytes, updated).
2074
+ * \param cbcmac IV for CBC-MAC (updated).
2075
+ * \param data data to decrypt (updated).
2076
+ * \param len data length (in bytes, MUST be a multiple of 16).
2077
+ */
2078
+ void br_aes_pwr8_ctrcbc_decrypt (const br_aes_pwr8_ctrcbc_keys * ctx ,
2079
+ void * ctr , void * cbcmac , void * data , size_t len );
2080
+
2081
+ /**
2082
+ * \brief CTR encryption/decryption with AES (`aes_pwr8` implementation).
2083
+ *
2084
+ * \param ctx context (already initialised).
2085
+ * \param ctr counter for CTR (16 bytes, updated).
2086
+ * \param data data to MAC (updated).
2087
+ * \param len data length (in bytes, MUST be a multiple of 16).
2088
+ */
2089
+ void br_aes_pwr8_ctrcbc_ctr (const br_aes_pwr8_ctrcbc_keys * ctx ,
2090
+ void * ctr , void * data , size_t len );
2091
+
2092
+ /**
2093
+ * \brief CBC-MAC with AES (`aes_pwr8` implementation).
2094
+ *
2095
+ * \param ctx context (already initialised).
2096
+ * \param cbcmac IV for CBC-MAC (updated).
2097
+ * \param data data to MAC (unmodified).
2098
+ * \param len data length (in bytes, MUST be a multiple of 16).
2099
+ */
2100
+ void br_aes_pwr8_ctrcbc_mac (const br_aes_pwr8_ctrcbc_keys * ctx ,
2101
+ void * cbcmac , const void * data , size_t len );
2102
+
2018
2103
/**
2019
2104
* \brief Obtain the `aes_pwr8` AES-CBC (encryption) implementation, if
2020
2105
* available.
@@ -2053,6 +2138,19 @@ const br_block_cbcdec_class *br_aes_pwr8_cbcdec_get_vtable(void);
2053
2138
*/
2054
2139
const br_block_ctr_class * br_aes_pwr8_ctr_get_vtable (void );
2055
2140
2141
+ /**
2142
+ * \brief Obtain the `aes_pwr8` AES-CTR + CBC-MAC implementation, if
2143
+ * available.
2144
+ *
2145
+ * This function returns a pointer to `br_aes_pwr8_ctrcbc_vtable`, if
2146
+ * that implementation was compiled in the library _and_ the POWER8 AES
2147
+ * opcodes are available on the currently running CPU. If either of
2148
+ * these conditions is not met, then this function returns `NULL`.
2149
+ *
2150
+ * \return the `aes_pwr8` AES-CTR implementation, or `NULL`.
2151
+ */
2152
+ const br_block_ctrcbc_class * br_aes_pwr8_ctrcbc_get_vtable (void );
2153
+
2056
2154
/**
2057
2155
* \brief Aggregate structure large enough to be used as context for
2058
2156
* subkeys (CBC encryption) for all AES implementations.
@@ -2105,10 +2203,8 @@ typedef union {
2105
2203
br_aes_small_ctrcbc_keys c_small ;
2106
2204
br_aes_ct_ctrcbc_keys c_ct ;
2107
2205
br_aes_ct64_ctrcbc_keys c_ct64 ;
2108
- /* FIXME
2109
2206
br_aes_x86ni_ctrcbc_keys c_x86ni ;
2110
2207
br_aes_pwr8_ctrcbc_keys c_pwr8 ;
2111
- */
2112
2208
} br_aes_gen_ctrcbc_keys ;
2113
2209
2114
2210
/*
0 commit comments