Skip to content

Commit 38e80d1

Browse files
committed
Allow the X9.146 examples to build against fips-ready.
1 parent f707ad8 commit 38e80d1

6 files changed

Lines changed: 141 additions & 1 deletion

X9.146/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ the call to `DoTls13Certificate()`, please search for the following messages to
6565
confirm that the alternative signature was verified:
6666

6767
```
68-
Alternative signature has been verified!
68+
Alt signature has been verified!
6969
Verified Peer's cert
7070
```
7171

X9.146/gen_dual_keysig_cert.c

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,22 @@
5050
#define SUBJECT_EMAIL "server@YourDomain.com"
5151
#endif
5252

53+
#ifdef HAVE_FIPS
54+
#include <wolfssl/wolfcrypt/fips_test.h>
55+
56+
static void myFipsCb(int ok, int err, const char* hash)
57+
{
58+
printf("in my Fips callback, ok = %d, err = %d\n", ok, err);
59+
printf("message = %s\n", wc_GetErrorString(err));
60+
printf("hash = %s\n", hash);
61+
62+
if (err == IN_CORE_FIPS_E) {
63+
printf("In core integrity hash check failure, copy above hash\n");
64+
printf("into verifyCore[] in fips_test.c and rebuild\n");
65+
}
66+
}
67+
#endif
68+
5369
static int do_certgen(int argc, char** argv)
5470
{
5571
int ret = 0;
@@ -111,6 +127,18 @@ static int do_certgen(int argc, char** argv)
111127
wolfSSL_Debugging_ON();
112128
#endif
113129

130+
#ifdef WC_RNG_SEED_CB
131+
wc_SetSeed_Cb(wc_GenerateSeed);
132+
#endif
133+
134+
#if defined(HAVE_FIPS)
135+
wolfCrypt_SetCb_fips(myFipsCb);
136+
#if FIPS_VERSION3_GE(6,0,0)
137+
printf("FIPS module version in use: %s\n",
138+
wolfCrypt_GetVersion_fips());
139+
#endif
140+
#endif
141+
114142
ret = wc_InitRng(&rng);
115143
if (ret != 0) goto exit;
116144
initRng = 1;

X9.146/gen_ecdsa_falcon_dual_keysig_cert.c

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,22 @@ int readFileIntoBuffer(char *fname, byte *buf, int *sz)
7474
return ret;
7575
}
7676

77+
#ifdef HAVE_FIPS
78+
#include <wolfssl/wolfcrypt/fips_test.h>
79+
80+
static void myFipsCb(int ok, int err, const char* hash)
81+
{
82+
printf("in my Fips callback, ok = %d, err = %d\n", ok, err);
83+
printf("message = %s\n", wc_GetErrorString(err));
84+
printf("hash = %s\n", hash);
85+
86+
if (err == IN_CORE_FIPS_E) {
87+
printf("In core integrity hash check failure, copy above hash\n");
88+
printf("into verifyCore[] in fips_test.c and rebuild\n");
89+
}
90+
}
91+
#endif
92+
7793
static int do_certgen(int argc, char** argv)
7894
{
7995
int ret = 0;
@@ -141,6 +157,18 @@ static int do_certgen(int argc, char** argv)
141157
wolfSSL_Debugging_ON();
142158
#endif
143159

160+
#ifdef WC_RNG_SEED_CB
161+
wc_SetSeed_Cb(wc_GenerateSeed);
162+
#endif
163+
164+
#if defined(HAVE_FIPS)
165+
wolfCrypt_SetCb_fips(myFipsCb);
166+
#if FIPS_VERSION3_GE(6,0,0)
167+
printf("FIPS module version in use: %s\n",
168+
wolfCrypt_GetVersion_fips());
169+
#endif
170+
#endif
171+
144172
if (argc != 2)
145173
usage(argv[0]);
146174

X9.146/gen_ecdsa_mldsa_dual_keysig_cert.c

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,22 @@ int readFileIntoBuffer(char *fname, byte *buf, int *sz)
7474
return ret;
7575
}
7676

77+
#ifdef HAVE_FIPS
78+
#include <wolfssl/wolfcrypt/fips_test.h>
79+
80+
static void myFipsCb(int ok, int err, const char* hash)
81+
{
82+
printf("in my Fips callback, ok = %d, err = %d\n", ok, err);
83+
printf("message = %s\n", wc_GetErrorString(err));
84+
printf("hash = %s\n", hash);
85+
86+
if (err == IN_CORE_FIPS_E) {
87+
printf("In core integrity hash check failure, copy above hash\n");
88+
printf("into verifyCore[] in fips_test.c and rebuild\n");
89+
}
90+
}
91+
#endif
92+
7793
static int do_certgen(int argc, char** argv)
7894
{
7995
int ret = 0;
@@ -144,6 +160,18 @@ static int do_certgen(int argc, char** argv)
144160
wolfSSL_Debugging_ON();
145161
#endif
146162

163+
#ifdef WC_RNG_SEED_CB
164+
wc_SetSeed_Cb(wc_GenerateSeed);
165+
#endif
166+
167+
#if defined(HAVE_FIPS)
168+
wolfCrypt_SetCb_fips(myFipsCb);
169+
#if FIPS_VERSION3_GE(6,0,0)
170+
printf("FIPS module version in use: %s\n",
171+
wolfCrypt_GetVersion_fips());
172+
#endif
173+
#endif
174+
147175
if (argc != 2)
148176
usage(argv[0]);
149177

X9.146/gen_rsa_falcon_dual_keysig_cert.c

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,22 @@ int readFileIntoBuffer(char *fname, byte *buf, int *sz)
6767
return ret;
6868
}
6969

70+
#ifdef HAVE_FIPS
71+
#include <wolfssl/wolfcrypt/fips_test.h>
72+
73+
static void myFipsCb(int ok, int err, const char* hash)
74+
{
75+
printf("in my Fips callback, ok = %d, err = %d\n", ok, err);
76+
printf("message = %s\n", wc_GetErrorString(err));
77+
printf("hash = %s\n", hash);
78+
79+
if (err == IN_CORE_FIPS_E) {
80+
printf("In core integrity hash check failure, copy above hash\n");
81+
printf("into verifyCore[] in fips_test.c and rebuild\n");
82+
}
83+
}
84+
#endif
85+
7086
static int do_certgen(int argc, char** argv)
7187
{
7288
int ret = 0;
@@ -128,6 +144,18 @@ static int do_certgen(int argc, char** argv)
128144
wolfSSL_Debugging_ON();
129145
#endif
130146

147+
#ifdef WC_RNG_SEED_CB
148+
wc_SetSeed_Cb(wc_GenerateSeed);
149+
#endif
150+
151+
#if defined(HAVE_FIPS)
152+
wolfCrypt_SetCb_fips(myFipsCb);
153+
#if FIPS_VERSION3_GE(6,0,0)
154+
printf("FIPS module version in use: %s\n",
155+
wolfCrypt_GetVersion_fips());
156+
#endif
157+
#endif
158+
131159
ret = wc_InitRng(&rng);
132160
if (ret != 0) goto exit;
133161
initRng = 1;

X9.146/gen_rsa_mldsa_dual_keysig_cert.c

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,22 @@ int readFileIntoBuffer(char *fname, byte *buf, int *sz)
6767
return ret;
6868
}
6969

70+
#ifdef HAVE_FIPS
71+
#include <wolfssl/wolfcrypt/fips_test.h>
72+
73+
static void myFipsCb(int ok, int err, const char* hash)
74+
{
75+
printf("in my Fips callback, ok = %d, err = %d\n", ok, err);
76+
printf("message = %s\n", wc_GetErrorString(err));
77+
printf("hash = %s\n", hash);
78+
79+
if (err == IN_CORE_FIPS_E) {
80+
printf("In core integrity hash check failure, copy above hash\n");
81+
printf("into verifyCore[] in fips_test.c and rebuild\n");
82+
}
83+
}
84+
#endif
85+
7086
static int do_certgen(int argc, char** argv)
7187
{
7288
int ret = 0;
@@ -128,6 +144,18 @@ static int do_certgen(int argc, char** argv)
128144
wolfSSL_Debugging_ON();
129145
#endif
130146

147+
#ifdef WC_RNG_SEED_CB
148+
wc_SetSeed_Cb(wc_GenerateSeed);
149+
#endif
150+
151+
#if defined(HAVE_FIPS)
152+
wolfCrypt_SetCb_fips(myFipsCb);
153+
#if FIPS_VERSION3_GE(6,0,0)
154+
printf("FIPS module version in use: %s\n",
155+
wolfCrypt_GetVersion_fips());
156+
#endif
157+
#endif
158+
131159
ret = wc_InitRng(&rng);
132160
if (ret != 0) goto exit;
133161
initRng = 1;

0 commit comments

Comments
 (0)