|
| 1 | +/* test_pwdbased.c |
| 2 | + * |
| 3 | + * Copyright (C) 2006-2026 wolfSSL Inc. |
| 4 | + * |
| 5 | + * This file is part of wolfSSL. |
| 6 | + * |
| 7 | + * wolfSSL is free software; you can redistribute it and/or modify |
| 8 | + * it under the terms of the GNU General Public License as published by |
| 9 | + * the Free Software Foundation; either version 3 of the License, or |
| 10 | + * (at your option) any later version. |
| 11 | + * |
| 12 | + * wolfSSL is distributed in the hope that it will be useful, |
| 13 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 14 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 15 | + * GNU General Public License for more details. |
| 16 | + * |
| 17 | + * You should have received a copy of the GNU General Public License |
| 18 | + * along with this program; if not, write to the Free Software |
| 19 | + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1335, USA |
| 20 | + */ |
| 21 | + |
| 22 | +#include <tests/unit.h> |
| 23 | +#include <wolfssl/wolfcrypt/pwdbased.h> |
| 24 | +#include <tests/api/api.h> |
| 25 | +#include <tests/api/test_pwdbased.h> |
| 26 | + |
| 27 | +/* test that wc_PBKDF1_ex rejects iterations <= 0 */ |
| 28 | +int test_wc_PBKDF1_ex_iterations(void) |
| 29 | +{ |
| 30 | + EXPECT_DECLS; |
| 31 | +#if defined(HAVE_PBKDF1) && !defined(NO_PWDBASED) && !defined(NO_SHA) && \ |
| 32 | + !defined(HAVE_SELFTEST) |
| 33 | + static const byte passwd[] = { 'p', 'a', 's', 's' }; |
| 34 | + static const byte salt[] = { 0x78, 0x57, 0x8E, 0x5a, |
| 35 | + 0x5d, 0x63, 0xcb, 0x06 }; |
| 36 | + byte derived[16]; |
| 37 | + |
| 38 | + ExpectIntEQ(wc_PBKDF1_ex(derived, (int)sizeof(derived), NULL, 0, |
| 39 | + passwd, (int)sizeof(passwd), |
| 40 | + salt, (int)sizeof(salt), 0, WC_SHA, HEAP_HINT), |
| 41 | + BAD_FUNC_ARG); |
| 42 | + ExpectIntEQ(wc_PBKDF1_ex(derived, (int)sizeof(derived), NULL, 0, |
| 43 | + passwd, (int)sizeof(passwd), |
| 44 | + salt, (int)sizeof(salt), -1, WC_SHA, HEAP_HINT), |
| 45 | + BAD_FUNC_ARG); |
| 46 | +#endif |
| 47 | + return EXPECT_RESULT(); |
| 48 | +} |
| 49 | + |
| 50 | +/* test that wc_PBKDF2_ex rejects iterations <= 0 */ |
| 51 | +int test_wc_PBKDF2_ex_iterations(void) |
| 52 | +{ |
| 53 | + EXPECT_DECLS; |
| 54 | +#if defined(HAVE_PBKDF2) && !defined(NO_PWDBASED) && !defined(NO_HMAC) && \ |
| 55 | + !defined(NO_SHA256) && !defined(HAVE_SELFTEST) && \ |
| 56 | + (!defined(HAVE_FIPS) || FIPS_VERSION3_GE(7,0,0)) |
| 57 | + static const byte passwd[] = { 'p', 'a', 's', 's' }; |
| 58 | + static const byte salt[] = { 0x78, 0x57, 0x8E, 0x5a, |
| 59 | + 0x5d, 0x63, 0xcb, 0x06 }; |
| 60 | + byte derived[24]; |
| 61 | + |
| 62 | + ExpectIntEQ(wc_PBKDF2_ex(derived, passwd, (int)sizeof(passwd), |
| 63 | + salt, (int)sizeof(salt), 0, |
| 64 | + (int)sizeof(derived), WC_SHA256, HEAP_HINT, INVALID_DEVID), |
| 65 | + BAD_FUNC_ARG); |
| 66 | + ExpectIntEQ(wc_PBKDF2_ex(derived, passwd, (int)sizeof(passwd), |
| 67 | + salt, (int)sizeof(salt), -1, |
| 68 | + (int)sizeof(derived), WC_SHA256, HEAP_HINT, INVALID_DEVID), |
| 69 | + BAD_FUNC_ARG); |
| 70 | +#endif |
| 71 | + return EXPECT_RESULT(); |
| 72 | +} |
0 commit comments