Skip to content

Commit e34e063

Browse files
committed
test/gensalt-bcrypt_x: Add testcase for bcrypt "$2x$" variant.
Simple testcase to ensure crypt_gensalt(3) always returns "NULL", and sets the error number to "EINVAL" for the bcrypt "$2x" variant.
1 parent 5cb5c8d commit e34e063

File tree

3 files changed

+57
-0
lines changed

3 files changed

+57
-0
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,7 @@ test/des-obsolete_r
8585
test/explicit-bzero
8686
test/fcrypt-enosys
8787
test/gensalt
88+
test/gensalt-bcrypt_x
8889
test/gensalt-nthash
8990
test/gensalt-extradata
9091
test/getrandom-fallbacks

Makefile.am

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -388,6 +388,7 @@ check_PROGRAMS = \
388388
test/crypt-sm3-yescrypt \
389389
test/explicit-bzero \
390390
test/gensalt \
391+
test/gensalt-bcrypt_x \
391392
test/gensalt-extradata \
392393
test/gensalt-nthash \
393394
test/getrandom-fallbacks \
@@ -497,6 +498,7 @@ COMMON_TEST_OBJECTS = libcrypt.la
497498

498499
test_badsalt_LDADD = $(COMMON_TEST_OBJECTS)
499500
test_badsetting_LDADD = $(COMMON_TEST_OBJECTS)
501+
test_gensalt_bcrypt_x_LDADD = $(COMMON_TEST_OBJECTS)
500502
test_gensalt_nthash_LDADD = $(COMMON_TEST_OBJECTS)
501503
test_gensalt_extradata_LDADD = $(COMMON_TEST_OBJECTS)
502504
test_checksalt_LDADD = $(COMMON_TEST_OBJECTS)

test/gensalt-bcrypt_x.c

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
/* Copyright (C) 2025 Björn Esser <[email protected]>
2+
*
3+
* Redistribution and use in source and binary forms, with or without
4+
* modification, are permitted.
5+
*
6+
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
7+
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
8+
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
9+
* ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
10+
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
11+
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
12+
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
13+
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
14+
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
15+
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
16+
* SUCH DAMAGE.
17+
*/
18+
19+
#include "crypt-port.h"
20+
21+
#if INCLUDE_bcrypt_x
22+
23+
#include <errno.h>
24+
#include <stdio.h>
25+
26+
int
27+
main (void)
28+
{
29+
char *retval;
30+
31+
errno = 0;
32+
retval = crypt_gensalt ("$2x$", 0, NULL, 0);
33+
34+
if (retval || errno != EINVAL)
35+
{
36+
fprintf (stderr, "gensalt: expected \"NULL\", got \"%s\" "
37+
"with errno == %i, instead of %i.\n",
38+
retval ? retval : "NULL", errno, EINVAL);
39+
40+
return 1;
41+
}
42+
43+
return 0;
44+
}
45+
46+
#else
47+
48+
int
49+
main (void)
50+
{
51+
return 77; /* UNSUPPORTED */
52+
}
53+
54+
#endif /* INCLUDE_bcrypt_x */

0 commit comments

Comments
 (0)