2 * Copyright 2020 The OpenSSL Project Authors. All Rights Reserved.
4 * Licensed under the Apache License 2.0 (the "License"). You may not use
5 * this file except in compliance with the License. You can obtain a copy
6 * in the file LICENSE in the source distribution or at
7 * https://www.openssl.org/source/license.html
11 #include <openssl/crypto.h>
12 #include <openssl/core_numbers.h>
13 #include "prov/implementations.h"
14 #include "prov/ciphercommon.h"
15 #include "prov/providercommonerr.h"
17 static OSSL_OP_cipher_newctx_fn null_newctx;
18 static void *null_newctx(void *provctx)
25 static OSSL_OP_cipher_freectx_fn null_freectx;
26 static void null_freectx(void *vctx)
30 static OSSL_OP_cipher_encrypt_init_fn null_init;
31 static int null_init(void *vctx, const unsigned char *key, size_t keylen,
32 const unsigned char *iv, size_t ivlen)
37 static OSSL_OP_cipher_cipher_fn null_cipher;
38 static int null_cipher(void *vctx, unsigned char *out, size_t *outl,
39 size_t outsize, const unsigned char *in, size_t inl)
49 static OSSL_OP_cipher_final_fn null_final;
50 static int null_final(void *vctx, unsigned char *out, size_t *outl,
57 static OSSL_OP_cipher_get_params_fn null_get_params;
58 static int null_get_params(OSSL_PARAM params[])
60 return cipher_generic_get_params(params, 0, 0, 0, 8, 0);
63 static const OSSL_PARAM null_known_gettable_ctx_params[] = {
64 OSSL_PARAM_size_t(OSSL_CIPHER_PARAM_KEYLEN, NULL),
65 OSSL_PARAM_size_t(OSSL_CIPHER_PARAM_IVLEN, NULL),
69 static OSSL_OP_cipher_gettable_ctx_params_fn null_gettable_ctx_params;
70 static const OSSL_PARAM *null_gettable_ctx_params(void)
72 return null_known_gettable_ctx_params;
75 static OSSL_OP_cipher_get_ctx_params_fn null_get_ctx_params;
76 static int null_get_ctx_params(void *vctx, OSSL_PARAM params[])
80 p = OSSL_PARAM_locate(params, OSSL_CIPHER_PARAM_IVLEN);
81 if (p != NULL && !OSSL_PARAM_set_size_t(p, 0)) {
82 ERR_raise(ERR_LIB_PROV, PROV_R_FAILED_TO_SET_PARAMETER);
85 p = OSSL_PARAM_locate(params, OSSL_CIPHER_PARAM_KEYLEN);
86 if (p != NULL && !OSSL_PARAM_set_size_t(p, 0)) {
87 ERR_raise(ERR_LIB_PROV, PROV_R_FAILED_TO_SET_PARAMETER);
93 const OSSL_DISPATCH null_functions[] = {
94 { OSSL_FUNC_CIPHER_NEWCTX,
95 (void (*)(void)) null_newctx },
96 { OSSL_FUNC_CIPHER_FREECTX, (void (*)(void)) null_freectx },
97 { OSSL_FUNC_CIPHER_DUPCTX, (void (*)(void)) null_newctx },
98 { OSSL_FUNC_CIPHER_ENCRYPT_INIT, (void (*)(void))null_init },
99 { OSSL_FUNC_CIPHER_DECRYPT_INIT, (void (*)(void))null_init },
100 { OSSL_FUNC_CIPHER_UPDATE, (void (*)(void))null_cipher },
101 { OSSL_FUNC_CIPHER_FINAL, (void (*)(void))null_final },
102 { OSSL_FUNC_CIPHER_CIPHER, (void (*)(void))null_cipher },
103 { OSSL_FUNC_CIPHER_GET_PARAMS, (void (*)(void)) null_get_params },
104 { OSSL_FUNC_CIPHER_GETTABLE_PARAMS,
105 (void (*)(void))cipher_generic_gettable_params },
106 { OSSL_FUNC_CIPHER_GET_CTX_PARAMS, (void (*)(void))null_get_ctx_params },
107 { OSSL_FUNC_CIPHER_GETTABLE_CTX_PARAMS,
108 (void (*)(void))null_gettable_ctx_params },