Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement PKCS7_encrypt and PKC7_decrypt #1996

Merged
merged 13 commits into from
Nov 25, 2024
Merged
3 changes: 0 additions & 3 deletions crypto/pkcs7/bio/bio_cipher_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,6 @@
// NOTE: need to keep this in sync with sizeof(ctx->buf) cipher.c
#define ENC_BLOCK_SIZE 1024 * 4

#define BIO_get_cipher_status(bio) \
BIO_ctrl(bio, BIO_C_GET_CIPHER_STATUS, 0, NULL)

struct CipherParams {
const char name[40];
const EVP_CIPHER *(*cipher)(void);
Expand Down
5 changes: 4 additions & 1 deletion crypto/pkcs7/bio/cipher.c
Original file line number Diff line number Diff line change
Expand Up @@ -193,7 +193,6 @@ 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);
long ret = 1;

BIO_ENC_CTX *ctx = BIO_get_data(b);
EVP_CIPHER_CTX **cipher_ctx;
BIO *next = BIO_next(b);
Expand Down Expand Up @@ -326,3 +325,7 @@ const BIO_METHOD *BIO_f_cipher(void) { return &methods_enc; }
int BIO_get_cipher_ctx(BIO *b, EVP_CIPHER_CTX **ctx) {
return BIO_ctrl(b, BIO_C_GET_CIPHER_CTX, 0, ctx);
}

int BIO_get_cipher_status(BIO *b) {
return BIO_ctrl(b, BIO_C_GET_CIPHER_STATUS, 0, NULL);
}
6 changes: 6 additions & 0 deletions crypto/pkcs7/internal.h
Original file line number Diff line number Diff line change
Expand Up @@ -223,6 +223,12 @@ OPENSSL_EXPORT int BIO_set_cipher(BIO *b, const EVP_CIPHER *cipher,
const unsigned char *key,
const unsigned char *iv, int enc);

// BIO_get_cipher_status returns 1 if the cipher is in a healthy state or 0
// otherwise. Unhealthy state could indicate decryption failure or other
// abnormalities. Data read from an unhealthy cipher should not be considered
// authentic.
Comment on lines +226 to +229
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit just in case we misuse this in the future, but we can include this in the next PR.

Suggested change
// BIO_get_cipher_status returns 1 if the cipher is in a healthy state or 0
// otherwise. Unhealthy state could indicate decryption failure or other
// abnormalities. Data read from an unhealthy cipher should not be considered
// authentic.
// BIO_get_cipher_status returns 1 if the cipher is in a healthy state or 0
// otherwise. A negative value could be returned if |b| is in an uninitialized
// state. Unhealthy state could indicate decryption failure or other
// abnormalities. Data read from an unhealthy cipher should not be considered
// authentic.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thanks. will incorporate in next PR.

OPENSSL_EXPORT int BIO_get_cipher_status(BIO *b);

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