Skip to content

Commit b0de0a1

Browse files
authored
Merge pull request #7143 from julek-wolfssl/zd/17303
EVP_Cipher: correct parameter checking
2 parents eb1fff3 + fc7143a commit b0de0a1

3 files changed

Lines changed: 91 additions & 24 deletions

File tree

.github/workflows/libssh2.yml

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
name: libssh2 Tests
2+
3+
on:
4+
workflow_call:
5+
6+
jobs:
7+
build_wolfssl:
8+
name: Build wolfSSL
9+
# Just to keep it the same as the testing target
10+
runs-on: ubuntu-latest
11+
# This should be a safe limit for the tests to run.
12+
timeout-minutes: 4
13+
steps:
14+
- name: Build wolfSSL
15+
uses: wolfSSL/actions-build-autotools-project@v1
16+
with:
17+
path: wolfssl
18+
configure: --enable-all
19+
check: false # config is already tested in many other PRB's
20+
install: true
21+
22+
- name: Upload built lib
23+
uses: actions/upload-artifact@v3
24+
with:
25+
name: wolf-install-libssh2
26+
path: build-dir
27+
retention-days: 1
28+
29+
libssh2_check:
30+
strategy:
31+
fail-fast: false
32+
matrix:
33+
# List of releases to test
34+
ref: [ 1.11.0 ]
35+
name: ${{ matrix.ref }}
36+
runs-on: ubuntu-latest
37+
# This should be a safe limit for the tests to run.
38+
timeout-minutes: 8
39+
needs: build_wolfssl
40+
steps:
41+
- name: Download lib
42+
uses: actions/download-artifact@v3
43+
with:
44+
name: wolf-install-libssh2
45+
path: build-dir
46+
47+
- name: Build and test libssh2
48+
uses: wolfSSL/actions-build-autotools-project@v1
49+
with:
50+
repository: libssh2/libssh2
51+
ref: libssh2-${{ matrix.ref }}
52+
path: libssh2
53+
configure: --with-crypto=wolfssl --with-libwolfssl-prefix=$GITHUB_WORKSPACE/build-dir
54+
check: true
55+
56+
- name: Confirm libssh2 built with wolfSSL
57+
working-directory: ./libssh2
58+
run: ldd src/.libs/libssh2.so | grep wolfssl

.github/workflows/main.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,8 @@ jobs:
4242
uses: ./.github/workflows/packaging.yml
4343
memcached:
4444
uses: ./.github/workflows/memcached.yml
45+
libssh2:
46+
uses: ./.github/workflows/libssh2.yml
4547
# TODO: Currently this test fails. Enable it once it becomes passing.
4648
# haproxy:
4749
# uses: ./.github/workflows/haproxy.yml

wolfcrypt/src/evp.c

Lines changed: 31 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -8110,6 +8110,26 @@ void wolfSSL_EVP_init(void)
81108110
}
81118111
#endif /* !NO_AES || !NO_DES3 */
81128112

8113+
static int IsCipherTypeAEAD(unsigned char cipherType)
8114+
{
8115+
switch (cipherType) {
8116+
case AES_128_GCM_TYPE:
8117+
case AES_192_GCM_TYPE:
8118+
case AES_256_GCM_TYPE:
8119+
case AES_128_CCM_TYPE:
8120+
case AES_192_CCM_TYPE:
8121+
case AES_256_CCM_TYPE:
8122+
case ARIA_128_GCM_TYPE:
8123+
case ARIA_192_GCM_TYPE:
8124+
case ARIA_256_GCM_TYPE:
8125+
case SM4_GCM_TYPE:
8126+
case SM4_CCM_TYPE:
8127+
return 1;
8128+
default:
8129+
return 0;
8130+
}
8131+
}
8132+
81138133
/* Return length on ok */
81148134
int wolfSSL_EVP_Cipher(WOLFSSL_EVP_CIPHER_CTX* ctx, byte* dst, byte* src,
81158135
word32 len)
@@ -8118,34 +8138,21 @@ void wolfSSL_EVP_init(void)
81188138

81198139
WOLFSSL_ENTER("wolfSSL_EVP_Cipher");
81208140

8121-
if (ctx == NULL || ((src == NULL || dst == NULL) &&
8122-
(TRUE
8123-
#ifdef HAVE_AESGCM
8124-
&& ctx->cipherType != AES_128_GCM_TYPE &&
8125-
ctx->cipherType != AES_192_GCM_TYPE &&
8126-
ctx->cipherType != AES_256_GCM_TYPE
8127-
#endif
8128-
#ifdef HAVE_AESCCM
8129-
&& ctx->cipherType != AES_128_CCM_TYPE &&
8130-
ctx->cipherType != AES_192_CCM_TYPE &&
8131-
ctx->cipherType != AES_256_CCM_TYPE
8132-
#endif
8133-
#ifdef HAVE_ARIA
8134-
&& ctx->cipherType != ARIA_128_GCM_TYPE &&
8135-
ctx->cipherType != ARIA_192_GCM_TYPE &&
8136-
ctx->cipherType != ARIA_256_GCM_TYPE
8137-
#endif
8138-
#ifdef WOLFSSL_SM4_GCM
8139-
&& ctx->cipherType != SM4_GCM_TYPE
8140-
#endif
8141-
#ifdef WOLFSSL_SM4_CCM
8142-
&& ctx->cipherType != SM4_CCM_TYPE
8143-
#endif
8144-
))) {
8141+
if (ctx == NULL) {
81458142
WOLFSSL_MSG("Bad argument.");
81468143
return WOLFSSL_FATAL_ERROR;
81478144
}
81488145

8146+
if (!IsCipherTypeAEAD(ctx->cipherType)) {
8147+
/* No-op for non-AEAD ciphers */
8148+
if (src == NULL && dst == NULL && len == 0)
8149+
return 0;
8150+
if (src == NULL || dst == NULL) {
8151+
WOLFSSL_MSG("Bad argument.");
8152+
return WOLFSSL_FATAL_ERROR;
8153+
}
8154+
}
8155+
81498156
if (ctx->cipherType == WOLFSSL_EVP_CIPH_TYPE_INIT) {
81508157
WOLFSSL_MSG("Cipher operation not initialized. Call "
81518158
"wolfSSL_EVP_CipherInit.");

0 commit comments

Comments
 (0)