add wrappers to enable/disable Padding for encryption contexts

This commit is contained in:
Ramesh Rayaprolu (rarayapr) 2018-08-16 10:04:05 -07:00 committed by Jeff Wendling
parent 5da517866c
commit 33d609e316
4 changed files with 17 additions and 2 deletions

View File

@ -19,4 +19,5 @@ Scott Kidder <skidder@brightcove.com>
Space Monkey, Inc <hello@spacemonkey.com>
Stephen Gallagher <sgallagh@redhat.com>
Viacheslav Biriukov <v.v.biriukov@gmail.com>
Zack Owens <zowens2009@gmail.com>
Zack Owens <zowens2009@gmail.com>
Ramesh Rayaprolu <rarayapr@cisco.com>

View File

@ -148,6 +148,13 @@ func (ctx *cipherCtx) IVSize() int {
return int(C.X_EVP_CIPHER_CTX_iv_length(ctx.ctx))
}
func (ctx *cipherCtx) SetPadding(pad bool) {
if pad {
C.X_EVP_CIPHER_CTX_set_padding(ctx.ctx, 1)
}
C.X_EVP_CIPHER_CTX_set_padding(ctx.ctx, 0)
}
func (ctx *cipherCtx) setCtrl(code, arg int) error {
res := C.EVP_CIPHER_CTX_ctrl(ctx.ctx, C.int(code), C.int(arg), nil)
if res != 1 {

6
shim.c
View File

@ -664,6 +664,12 @@ int X_EVP_CIPHER_CTX_iv_length(EVP_CIPHER_CTX *ctx) {
return EVP_CIPHER_CTX_iv_length(ctx);
}
void X_EVP_CIPHER_CTX_set_padding(EVP_CIPHER_CTX *ctx, int padding) {
//openssl always returns 1 for set_padding
//hence return value is not checked
EVP_CIPHER_CTX_set_padding(ctx, padding);
}
const EVP_CIPHER *X_EVP_CIPHER_CTX_cipher(EVP_CIPHER_CTX *ctx) {
return EVP_CIPHER_CTX_cipher(ctx);
}

3
shim.h
View File

@ -139,6 +139,7 @@ extern int X_EVP_CIPHER_nid(EVP_CIPHER *c);
extern int X_EVP_CIPHER_CTX_block_size(EVP_CIPHER_CTX *ctx);
extern int X_EVP_CIPHER_CTX_key_length(EVP_CIPHER_CTX *ctx);
extern int X_EVP_CIPHER_CTX_iv_length(EVP_CIPHER_CTX *ctx);
extern void X_EVP_CIPHER_CTX_set_padding(EVP_CIPHER_CTX *ctx, int padding);
extern const EVP_CIPHER *X_EVP_CIPHER_CTX_cipher(EVP_CIPHER_CTX *ctx);
extern int X_EVP_CIPHER_CTX_encrypting(const EVP_CIPHER_CTX *ctx);
extern int X_EVP_PKEY_CTX_set_ec_paramgen_curve_nid(EVP_PKEY_CTX *ctx, int nid);
@ -159,4 +160,4 @@ extern int X_sk_X509_num(STACK_OF(X509) *sk);
extern X509 *X_sk_X509_value(STACK_OF(X509)* sk, int i);
/* PEM methods */
extern int X_PEM_write_bio_PrivateKey_traditional(BIO *bio, EVP_PKEY *key, const EVP_CIPHER *enc, unsigned char *kstr, int klen, pem_password_cb *cb, void *u);
extern int X_PEM_write_bio_PrivateKey_traditional(BIO *bio, EVP_PKEY *key, const EVP_CIPHER *enc, unsigned char *kstr, int klen, pem_password_cb *cb, void *u);