/* Dispatch functions for chacha20 cipher */
+#include <openssl/proverr.h>
#include "cipher_chacha20.h"
#include "prov/implementations.h"
#include "prov/providercommon.h"
-#include "prov/providercommonerr.h"
#define CHACHA20_KEYLEN (CHACHA_KEY_SIZE)
#define CHACHA20_BLKLEN (1)
#define CHACHA20_IVLEN (CHACHA_CTR_SIZE)
-/* TODO(3.0) Figure out what flags are required */
-#define CHACHA20_FLAGS (EVP_CIPH_CUSTOM_IV | EVP_CIPH_ALWAYS_CALL_INIT)
+#define CHACHA20_FLAGS (PROV_CIPHER_FLAG_CUSTOM_IV)
static OSSL_FUNC_cipher_newctx_fn chacha20_newctx;
static OSSL_FUNC_cipher_freectx_fn chacha20_freectx;
static OSSL_FUNC_cipher_set_ctx_params_fn chacha20_set_ctx_params;
static OSSL_FUNC_cipher_gettable_ctx_params_fn chacha20_gettable_ctx_params;
static OSSL_FUNC_cipher_settable_ctx_params_fn chacha20_settable_ctx_params;
-#define chacha20_cipher cipher_generic_cipher
-#define chacha20_update cipher_generic_stream_update
-#define chacha20_final cipher_generic_stream_final
-#define chacha20_gettable_params cipher_generic_gettable_params
+#define chacha20_cipher ossl_cipher_generic_cipher
+#define chacha20_update ossl_cipher_generic_stream_update
+#define chacha20_final ossl_cipher_generic_stream_final
+#define chacha20_gettable_params ossl_cipher_generic_gettable_params
void chacha20_initctx(PROV_CHACHA20_CTX *ctx)
{
- cipher_generic_initkey(ctx, CHACHA20_KEYLEN * 8,
- CHACHA20_BLKLEN * 8,
- CHACHA20_IVLEN * 8,
- 0, CHACHA20_FLAGS,
- PROV_CIPHER_HW_chacha20(CHACHA20_KEYLEN * 8),
- NULL);
+ ossl_cipher_generic_initkey(ctx, CHACHA20_KEYLEN * 8,
+ CHACHA20_BLKLEN * 8,
+ CHACHA20_IVLEN * 8,
+ 0, CHACHA20_FLAGS,
+ ossl_prov_cipher_hw_chacha20(CHACHA20_KEYLEN * 8),
+ NULL);
}
static void *chacha20_newctx(void *provctx)
PROV_CHACHA20_CTX *ctx = (PROV_CHACHA20_CTX *)vctx;
if (ctx != NULL) {
- cipher_generic_reset_ctx((PROV_CIPHER_CTX *)vctx);
+ ossl_cipher_generic_reset_ctx((PROV_CIPHER_CTX *)vctx);
OPENSSL_clear_free(ctx, sizeof(*ctx));
}
}
static int chacha20_get_params(OSSL_PARAM params[])
{
- return cipher_generic_get_params(params, 0, CHACHA20_FLAGS,
- CHACHA20_KEYLEN * 8,
- CHACHA20_BLKLEN * 8,
- CHACHA20_IVLEN * 8);
+ return ossl_cipher_generic_get_params(params, 0, CHACHA20_FLAGS,
+ CHACHA20_KEYLEN * 8,
+ CHACHA20_BLKLEN * 8,
+ CHACHA20_IVLEN * 8);
}
static int chacha20_get_ctx_params(void *vctx, OSSL_PARAM params[])
int ret;
/* The generic function checks for ossl_prov_is_running() */
- ret= cipher_generic_einit(vctx, key, keylen, iv, ivlen);
+ ret= ossl_cipher_generic_einit(vctx, key, keylen, iv, ivlen);
if (ret && iv != NULL) {
PROV_CIPHER_CTX *ctx = (PROV_CIPHER_CTX *)vctx;
PROV_CIPHER_HW_CHACHA20 *hw = (PROV_CIPHER_HW_CHACHA20 *)ctx->hw;
int ret;
/* The generic function checks for ossl_prov_is_running() */
- ret= cipher_generic_dinit(vctx, key, keylen, iv, ivlen);
+ ret= ossl_cipher_generic_dinit(vctx, key, keylen, iv, ivlen);
if (ret && iv != NULL) {
PROV_CIPHER_CTX *ctx = (PROV_CIPHER_CTX *)vctx;
PROV_CIPHER_HW_CHACHA20 *hw = (PROV_CIPHER_HW_CHACHA20 *)ctx->hw;
return ret;
}
-/* chacha20_functions */
-const OSSL_DISPATCH chacha20_functions[] = {
+/* ossl_chacha20_functions */
+const OSSL_DISPATCH ossl_chacha20_functions[] = {
{ OSSL_FUNC_CIPHER_NEWCTX, (void (*)(void))chacha20_newctx },
{ OSSL_FUNC_CIPHER_FREECTX, (void (*)(void))chacha20_freectx },
{ OSSL_FUNC_CIPHER_ENCRYPT_INIT, (void (*)(void))chacha20_einit },