Skip to content

Commit 411a806

Browse files
authored
Merge pull request #6 from IBM/ICC_merge
Update with some ICC 8.9.6 updates
2 parents e20ab36 + f6a460c commit 411a806

19 files changed

+208
-217
lines changed

.github/workflows/.workflowTest.yml

+12-18
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,9 @@ name: CI
66
on:
77
# Triggers the workflow on push or pull request events but only for the "main" branch
88
push:
9-
branches: [ "main" ]
9+
branches: [ "*" ]
1010
pull_request:
11-
branches: [ "main" ]
11+
branches: [ "*" ]
1212

1313
# Allows you to run this workflow manually from the Actions tab
1414
workflow_dispatch:
@@ -25,14 +25,12 @@ jobs:
2525
- uses: actions/checkout@v3
2626

2727
- name: 64-bit Linux debug compile
28+
# export LD_LIBRARY_PATH=/home/runner/work/OpenCryptographyKitC/OpenCryptographyKitC/openssl-1.1.1/
2829
run: |
29-
cd icc
30-
make OPSYS=AMD64_LINUX CONFIG=debug create_all
31-
export LD_LIBRARY_PATH=/home/runner/work/OpenCryptographyKitC/OpenCryptographyKitC/openssl-1.1.1/
32-
make -k OPSYS=AMD64_LINUX CONFIG=debug all
33-
make -k OPSYS=AMD64_LINUX CONFIG=debug tests
34-
make -k OPSYS=AMD64_LINUX CONFIG=debug show_config
35-
cd ..
30+
make -C icc -k OPSYS=AMD64_LINUX CONFIG=debug create_all
31+
make -C icc -k OPSYS=AMD64_LINUX CONFIG=debug all
32+
make -C icc -k OPSYS=AMD64_LINUX CONFIG=debug tests
33+
make -C icc -k OPSYS=AMD64_LINUX CONFIG=debug show_config
3634
3735
ICC-Compile:
3836
# a compile only -no test -quick check
@@ -42,14 +40,10 @@ jobs:
4240

4341
- name: 64-bit Linux release compile
4442
run: |
45-
cd icc
46-
make -k OPSYS=AMD64_LINUX CONFIG=release create_all
47-
make -k OPSYS=AMD64_LINUX CONFIG=release all
48-
make -k OPSYS=AMD64_LINUX CONFIG=release iccpkg
49-
make -k OPSYS=AMD64_LINUX CONFIG=release show_config
50-
cd ..
51-
cd iccpkg
52-
make -k OPSYS=AMD64_LINUX CONFIG=release all
53-
cd ..
43+
make -C icc -k OPSYS=AMD64_LINUX CONFIG=release create_all
44+
make -C icc -k OPSYS=AMD64_LINUX CONFIG=release all
45+
make -C icc -k OPSYS=AMD64_LINUX CONFIG=release iccpkg
46+
make -C icc -k OPSYS=AMD64_LINUX CONFIG=release show_config
47+
make -C iccpkg -k OPSYS=AMD64_LINUX CONFIG=release all
5448
5549

README.md

+1
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ make -k -C icc OPSYS=LINUX all
2626
make -k -C icc OPSYS=WIN64_VS2022 create_all
2727
make -k -C icc OPSYS=WIN64_VS2022 all
2828
```
29+
2930
This build is not constrained to MS VS 2022 but is tested on that platform.
3031
#### Requirements
3132
Visual studio build tools are required, including mfc.

icc/Makefile

+6-6
Original file line numberDiff line numberDiff line change
@@ -43,8 +43,6 @@ OSSL_RTE_DIR = $(RTE_DIR)/osslib
4343
ICC_RTE_DIR = $(RTE_DIR)/icclib
4444
NOSHIP_ICC_RTE_DIR = $(NOSHIP_RTE_DIR)/icclib
4545
ICCPKG_DIR = ../iccpkg
46-
# placeholder for a FIPS/non-FIPS hack job where the object name
47-
# needs to be changed for z/OS
4846

4947

5048
#- Default targets, before the makefile stubs below (some of which
@@ -79,7 +77,6 @@ PRNGTST2 = fips-prng-testprg2$(EXESUFX)
7977
ICCSDK = $(PACKAGE_DIR)/iccsdk.tar
8078
ICCRTE = $(PACKAGE_DIR)/iccrte.tar
8179

82-
8380
MYOPENSSL = $(SDK_DIR)/openssl$(EXESUFX)
8481
DOXYFILE = $(SDK_DIR)/ICC_API_htm.tar
8582
ICCREAD = iccread$(EXESUFX)
@@ -116,7 +113,7 @@ include ../iccpkg/muppet.mk
116113
# different object names on this platform
117114
# Since the FIPS ICC was already built, change ONLY the name of the object used in non-FIPS mode
118115

119-
ifeq ($($strip $(IS_FIPS)),)
116+
ifeq ($(strip $(IS_FIPS)),)
120117
MYICC = newicc
121118
else
122119
MYICC = icc
@@ -170,6 +167,7 @@ create_openssl: ../openssl_source/$(OPENSSL_VER)-icc.tar.gz
170167
rm -r $(OPENSSL_VER) openssl ; \
171168
rm -rf x; mkdir x; cd x; \
172169
tar xzf ../openssl_source/$(OPENSSL_VER)-icc.tar.gz ; \
170+
sleep 1; \
173171
mv openssl ../$(OPENSSL_VER) ; \
174172
chmod +x ../$(OPENSSL_VER)/Configure ; \
175173
cd ..; \
@@ -327,7 +325,7 @@ clean_iccpkg:
327325
( if [ -d ../iccpkg/ ] ; then \
328326
cd ../iccpkg; \
329327
unset MAKEOVERRIDES MAKELEVEL MAKEFILES ; \
330-
"$(MAKE)" clean; \
328+
$(MAKE) clean; \
331329
fi; \
332330
)
333331

@@ -600,8 +598,10 @@ privkey.rsa:
600598
pubkey.h: privkey.rsa
601599
$(OPENSSL_PATH_SETUP) $(MYOPENSSL) rsa -in privkey.rsa -outform DER -RSAPublicKey_out > rsa_pub_key.der
602600
echo "/*This is an auto generated code please DO NOT modify*/" > pubkey.h
603-
perl bin2hex.pl rsa_pub_key.der temp.h
601+
perl $(ICC_ROOT)/icc/bin2hex.pl rsa_pub_key.der temp.h
604602
cat temp.h >> pubkey.h
603+
echo pubkey.h
604+
cat pubkey.h
605605
rm temp.h rsa_pub_key.der
606606

607607
signer$(OBJSUFX): extsig.c

icc/TRNG/ICC_NRBG.c

+53-10
Original file line numberDiff line numberDiff line change
@@ -68,23 +68,29 @@ typedef struct NRBG_type_t {
6868
int initialized; /*!< Flag to say it was used */
6969
} NRBG_type;
7070

71+
72+
/* In non-FIPS, all platforms default to TRNG_OS and upgrade to TRNG_HW at runtime if available.
73+
This is done to prioritise compatibility on the unpredictable range and age of the virtualisatised systems we might run on,
74+
while still upgrading and using TRNG_HW in most cases.
75+
*/
76+
7177
#if (NON_FIPS_ICC == 1) /* Built as non-FIPS */
7278

73-
/* These definitions match the availability of OPENSSL_HW_rand */
79+
/* These definitions try mirror the availability of OPENSSL_HW_rand to avoid a mismatch (not relevant when we use TRNG_OS) */
7480
/* X86 Linux and Windows, Solaris x86 */
7581
#if (defined(__i386) || defined(__i386__) || defined(_M_IX86) || \
7682
defined(__INTEL__) || \
7783
defined(__x86_64) || defined(__x86_64__) || defined(_M_AMD64) ) && ( !(defined(__SunOS) && !defined(__amd64)) \
7884
)
79-
80-
static TRNG_TYPE global_trng_type = TRNG_HW;
85+
static int global_trng_type_attempted_upgrade = 0;
86+
static TRNG_TYPE global_trng_type = TRNG_OS;
8187

8288
#elif defined(__s390__) || defined(__MVS__)
89+
static int global_trng_type_attempted_upgrade = 0;
90+
static TRNG_TYPE global_trng_type = TRNG_OS;
8391

84-
static TRNG_TYPE global_trng_type = TRNG_HW;
85-
86-
/* We will do a runtime check for cpu support for darn, present since ISA3.0, and update to TRNG_HW if so */
8792
#elif defined(__ppc__) || defined(__powerpc__) || defined(_AIX)
93+
/* We will do a runtime check for cpu support for darn, present since ISA3.0, and update to TRNG_HW if so */
8894
static int global_trng_type_attempted_upgrade = 0;
8995
static TRNG_TYPE global_trng_type = TRNG_OS;
9096

@@ -97,7 +103,7 @@ typedef struct NRBG_type_t {
97103
static TRNG_TYPE global_trng_type = TRNG_FIPS;
98104
#endif
99105

100-
/* If a user sets TRNG_OS on power, we don't want to upgrade even if HW is available */
106+
/* If a user explicitly sets a TRNG, we don't want to upgrade even if HW is available */
101107
int global_trng_type_user_set = 0;
102108

103109
static void TRNG_LocalCleanup(TRNG *T);
@@ -247,6 +253,7 @@ void checkTRNGAlias(char **trngname) {
247253
*trngname = "TRNG_OS";
248254
}
249255
}
256+
MARK("TRNG aliased to", *trngname);
250257
}
251258
}
252259
}
@@ -258,6 +265,12 @@ void checkTRNGAlias(char **trngname) {
258265
extern unsigned icc_failure; /*!< Trigger for induced failure tests */
259266
int SetTRNGName(char *trngname)
260267
{
268+
if (NULL != trngname) {
269+
MARK("Request to set TRNG to", trngname);
270+
}
271+
else {
272+
MARK("Request to set NULL TRNG", "");
273+
}
261274
int rv = 0;
262275
int i = 0;
263276
checkTRNGAlias(&trngname);
@@ -288,8 +301,11 @@ TRNG_TYPE SetDefaultTrng(TRNG_TYPE trng) {
288301
case TRNG_HW:
289302
case TRNG_FIPS:
290303
if(TRNG_ARRAY[trng].avail()) {
304+
MARK("TRNG set to", TRNG_ARRAY[trng].name);
291305
global_trng_type = trng;
292306
global_trng_type_user_set = 1;
307+
} else {
308+
MARK("TRNG attempted to be set to", TRNG_ARRAY[trng].name);
293309
}
294310
break;
295311
default:
@@ -397,12 +413,39 @@ static void TRNG_ESourceCleanup(E_SOURCE *es)
397413

398414
TRNG_TYPE GetDefaultTrng()
399415
{
400-
#if defined(__ppc__) || defined(__powerpc__) || defined(_AIX)
401-
if(!global_trng_type_attempted_upgrade && 0 == global_trng_type_user_set && 0 == strcasecmp("TRNG_OS", *trngname) && ALT4_Avail()) {
416+
#if (NON_FIPS_ICC == 1)
417+
418+
#if (\
419+
(( defined(__i386) || defined(__i386__) || defined(_M_IX86) || \
420+
defined(__INTEL__) || \
421+
defined(__x86_64) || defined(__x86_64__) || defined(_M_AMD64)) && (!(defined(__SunOS) && !defined(__amd64)))) \
422+
|| \
423+
( defined(__s390__) || defined(__MVS__)) \
424+
|| \
425+
( defined(__ppc__) || defined(__powerpc__) || defined(_AIX)) \
426+
)
427+
if(!global_trng_type_attempted_upgrade) {
428+
MARK("Testing the availability of TRNG_HW", "");
429+
430+
if(0 == global_trng_type_user_set) {
431+
if (TRNG_FIPS != global_trng_type) {
432+
if (ALT4_Avail()) {
433+
MARK("Found, switching to TRNG_HW", "");
402434
global_trng_type = TRNG_HW;
435+
} else {
436+
MARK("TRNG_HW not available, remaining with", TRNG_ARRAY[global_trng_type].name);
437+
}
438+
} else {
439+
MARK("TRNG_FIPS set, remaining with", TRNG_ARRAY[global_trng_type].name);
440+
}
441+
} else {
442+
MARK("User TRNG set, remaining with", TRNG_ARRAY[global_trng_type].name);
403443
}
404444
global_trng_type_attempted_upgrade = 1;
405-
#endif
445+
}
446+
447+
#endif /*x86_64, z/architecture, power */
448+
#endif /*non-FIPS*/
406449
return global_trng_type;
407450
}
408451
/*!

icc/TRNG/TRNG_ALT.c

+19-12
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,9 @@
4040

4141

4242
static int fd_alt = -1;
43-
43+
#if defined(_WIN32)
44+
static BCRYPT_ALG_HANDLE hProvider = NULL;
45+
#endif
4446
/*! Pre-init function for TRNG_ALT
4547
4648
*/
@@ -89,10 +91,12 @@ static int alt_read(unsigned char *buffer,int n)
8991
break;
9092
case -3:
9193
#if defined(_WIN32)
94+
{
9295
NTSTATUS status = 0;
93-
status = BCryptGenRandom(BCRYPT_RNG_ALG_HANDLE, (PUCHAR)buffer, n, 0);
94-
if(status != STATUS_SUCCESS) {
95-
rv = TRNG_REQ_SIZE; /* One of the parameters was likely not correct */
96+
status = BCryptGenRandom(hProvider, (PUCHAR)buffer, n, 0);
97+
if(!BCRYPT_SUCCESS(status)) {
98+
rv = TRNG_REQ_SIZE; /* One of the parameters was likely not correct, or bad provider */
99+
}
96100
}
97101
#endif
98102
break;
@@ -124,18 +128,17 @@ TRNG_ERRORS ALT_Init(E_SOURCE *E, unsigned char *pers, int perl)
124128
/* Else probe for something else */
125129
if(-1 == fd_alt) {
126130
#if defined(_WIN32)
131+
{
127132
#define SIZE 8
128133
/* ON Windows ..... */
129134
/* If no HW RNG, OS RNG source */
130135
NTSTATUS status = 0;
131-
int tmpSize = SIZE; /* 64 bits, small test of availability */
132-
unsigned char tmp[SIZE];
133-
status = BCryptGenRandom(BCRYPT_RNG_ALG_HANDLE, (PUCHAR)&tmp, tmpSize, 0); /* Using a pseudo-handle */
134-
135-
if(status == STATUS_SUCCESS) {
136+
status = BCryptOpenAlgorithmProvider(&hProvider, BCRYPT_RNG_ALGORITHM, NULL, 0);
137+
if(BCRYPT_SUCCESS(status)) {
136138
fd_alt = -3;
137139
} else {
138-
rv = TRNG_INIT;
140+
rv = TRNG_INIT; /*error*/
141+
}
139142
}
140143
#else
141144
/* On Unix .... */
@@ -209,11 +212,15 @@ TRNG_ERRORS ALT_Cleanup(E_SOURCE *E)
209212

210213
void ALT_Final()
211214
{
212-
#if !defined(_WIN32)
215+
#if defined(_WIN32)
216+
if((-3 == fd_alt) && (0 != hProvider)) {
217+
BCryptCloseAlgorithmProvider(hProvider, 0);
218+
hProvider = 0;
219+
}
220+
#else
213221
if(fd_alt >= 0) {
214222
close(fd_alt);
215223
fd_alt = -1;
216224
}
217225
#endif
218-
219226
}

icc/TRNG/entropy_to_NRBG.c

+15-14
Original file line numberDiff line numberDiff line change
@@ -68,16 +68,13 @@ int conditioner(TRNG *T, unsigned char* outbuf, unsigned len)
6868
if( 0 != trng_raw(&(T->econd),tbuf,SHA_DIGEST_SIZE) ) {
6969
rv = SetRNGError("Insufficient entropy",__FILE__,__LINE__);
7070
if(TRNG_OK != rv) {
71-
break;
71+
HMAC_CTX_cleanup(T->cond.hctx);
72+
return rv;
7273
}
7374
}
7475
HMAC_Update(T->cond.hctx,tbuf,sizeof(tbuf));
7576
}
76-
if(TRNG_RESTART == rv) {
77-
TRNG_TRNG_Init(T,-1);
78-
rv = TRNG_OK;
79-
continue;
80-
}
77+
8178
HMAC_Final(T->cond.hctx,tbuf,&mlen);
8279

8380
for(i = 0; (i < mlen) && (n < len); ) {
@@ -120,7 +117,10 @@ TRNG_ERRORS Entropy_to_TRNG(TRNG *T, unsigned char *data, unsigned int len)
120117
{
121118
for (l = 0; l < len; l += SHA_DIGEST_SIZE)
122119
{
123-
conditioner(T, buffer, SHA_DIGEST_SIZE);
120+
rv = conditioner(T, buffer, SHA_DIGEST_SIZE);
121+
if (TRNG_OK != rv) {
122+
return rv;
123+
}
124124
e = pmax4(buffer,SHA_DIGEST_SIZE);
125125
if(e < 50) {
126126
break;
@@ -137,9 +137,8 @@ TRNG_ERRORS Entropy_to_TRNG(TRNG *T, unsigned char *data, unsigned int len)
137137
if (j >= TRNG_RETRIES)
138138
{
139139
rv = SetRNGError("Unable to obtain sufficient entropy", __FILE__, __LINE__);
140-
if(TRNG_OK == rv) {
141-
j = 0;
142-
continue;
140+
if(TRNG_OK != rv) {
141+
return rv;
143142
}
144143
}
145144
/* Final sanity check, we got out, is our overall entropy good with a compression function
@@ -149,7 +148,9 @@ TRNG_ERRORS Entropy_to_TRNG(TRNG *T, unsigned char *data, unsigned int len)
149148
if (!EntropyOK(T))
150149
{
151150
rv = SetRNGError("Long term entropy is below acceptable limits", __FILE__, __LINE__);
152-
if(TRNG_OK == rv) continue;
151+
if (TRNG_OK != rv) {
152+
return rv;
153+
}
153154
}
154155
/*!
155156
\FIPS
@@ -171,10 +172,10 @@ TRNG_ERRORS Entropy_to_TRNG(TRNG *T, unsigned char *data, unsigned int len)
171172
m++;
172173
if(m > 5) {
173174
rv = SetRNGError("Repeated duplicate seeds from TRNG", __FILE__, __LINE__);
174-
if(TRNG_OK == rv) {
175-
continue;
175+
if (TRNG_OK != rv) {
176+
EVP_MD_CTX_reset(T->md_ctx);
177+
return rv;
176178
}
177-
break;
178179
}
179180
continue;
180181
}

icc/TRNG/noise_to_entropy.c

+3
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,9 @@ int trng_raw(E_SOURCE *E,
9090
/* 201 is a transient failure, 202 persistent */
9191
if((icc_failure == 201) || (icc_failure == 202)) {
9292
failcount = MAX_HT_FAIL +1;
93+
/* Pretend to clear the buffer so we goto error */
94+
k = 0;
95+
E->cnt = 0;
9396
}
9497
if(0 == k) {
9598
E->impl.gb(E,&(E->nbuf[0]), E_ESTB_BUFLEN);

icc/TRNG/timer_entropy.c

+2-2
Original file line numberDiff line numberDiff line change
@@ -131,9 +131,9 @@ ICC_UINT64 RdCTR_raw() {
131131
#elif defined(__sun__) && defined(__i386__) && defined(__GNUC__)
132132

133133
ICC_UINT64 RdCTR_raw() {
134-
ICC_UINT64 lo;
134+
ICC_UINT32 lo;
135135
__asm__ __volatile__("rdtsc\n" : "=a" (lo) : : "edx");
136-
return lo;
136+
return (ICC_UINT64)lo;
137137
}
138138

139139
/* End Solaris x86 */

0 commit comments

Comments
 (0)