Skip to content

Commit

Permalink
Import code and tests from pkcs7-ruby branch
Browse files Browse the repository at this point in the history
  • Loading branch information
WillChilds-Klein committed Nov 8, 2024
1 parent fa1c6c0 commit e943a3a
Show file tree
Hide file tree
Showing 6 changed files with 844 additions and 6 deletions.
11 changes: 10 additions & 1 deletion crypto/pkcs7/bio/cipher.c
Original file line number Diff line number Diff line change
Expand Up @@ -192,6 +192,7 @@ static int enc_write(BIO *b, const char *in, int inl) {

static long enc_ctrl(BIO *b, int cmd, long num, void *ptr) {
GUARD_PTR(b);
EVP_CIPHER_CTX **cipher_ctx;
long ret = 1;

BIO_ENC_CTX *ctx = BIO_get_data(b);
Expand Down Expand Up @@ -241,6 +242,15 @@ static long enc_ctrl(BIO *b, int cmd, long num, void *ptr) {
case BIO_C_GET_CIPHER_STATUS:
ret = (long)ctx->ok;
break;
case BIO_C_GET_CIPHER_CTX:
cipher_ctx = (EVP_CIPHER_CTX **)ptr;
if (!cipher_ctx) {
ret = 0;
break;
}
*cipher_ctx = ctx->cipher;
BIO_set_init(b, 1);
break;
// OpenSSL implements these, but because we don't need them and cipher BIO
// is internal, we can fail loudly if they're called. If this case is hit,
// it likely means you're making a change that will require implementing
Expand All @@ -249,7 +259,6 @@ static long enc_ctrl(BIO *b, int cmd, long num, void *ptr) {
case BIO_CTRL_GET_CALLBACK:
case BIO_CTRL_SET_CALLBACK:
case BIO_C_DO_STATE_MACHINE:
case BIO_C_GET_CIPHER_CTX:
OPENSSL_PUT_ERROR(PKCS7, ERR_R_BIO_LIB);
return 0;
default:
Expand Down
3 changes: 3 additions & 0 deletions crypto/pkcs7/internal.h
Original file line number Diff line number Diff line change
Expand Up @@ -220,6 +220,9 @@ OPENSSL_EXPORT int BIO_set_cipher(BIO *b, const EVP_CIPHER *cipher,
const unsigned char *key,
const unsigned char *iv, int enc);

#define BIO_get_cipher_ctx(bio, contents) BIO_ctrl(bio, BIO_C_GET_CIPHER_CTX, 0, \
(char *)(contents))


#if defined(__cplusplus)
} // extern C
Expand Down
Loading

0 comments on commit e943a3a

Please sign in to comment.