Skip to content

Commit 35ab3ec

Browse files
Populate
1 parent 15f5ece commit 35ab3ec

File tree

256 files changed

+72065
-0
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

256 files changed

+72065
-0
lines changed

README.md

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,26 @@
11
# OpenCryptographyKitC
2+
23
The Open Cryptography Kit for C to which this document refers is based on the C language and is usable by products that are based on C or C++.
4+
5+
# Build for Linux 64
6+
7+
make -k -C icc OPSYS=AMD64_LINUX create_all
8+
make -k -C icc OPSYS=AMD64_LINUX all
9+
10+
Other options include CONFIG=debug
11+
12+
# Build for Linux 32 bit
13+
14+
make -k -C icc OPSYS=LINUX create_all
15+
make -k -C icc OPSYS=LINUX all
16+
17+
Other options as above
18+
19+
# Build for Windows 64
20+
21+
make -k -C icc OPSYS=WIN64_VS2022 create_all
22+
make -k -C icc OPSYS=WIN64_VS2022 all
23+
24+
Other options as above
25+
26+
Note this build is not constrained to MS VS 2022 but is tested on that platform

icc/.DS_Store

6 KB
Binary file not shown.

icc/DELTA/Delta_test.c

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
/*************************************************************************
2+
// Copyright IBM Corp. 2023
3+
//
4+
// Licensed under the Apache License 2.0 (the "License").  You may not use
5+
// this file except in compliance with the License.  You can obtain a copy
6+
// in the file LICENSE in the source distribution.
7+
*************************************************************************/
8+
9+
/*************************************************************************
10+
// Description: High resolution timing code, test case
11+
//
12+
*************************************************************************/
13+
14+
#include <stdio.h>
15+
#include <DELTA/delta_t.h>
16+
17+
int main(int argc, char *argv[])
18+
{
19+
unsigned long delta = 0L;
20+
unsigned long r,et,mt,mn;
21+
unsigned long i;
22+
int k;
23+
volatile unsigned long j;
24+
double c2t = 1.0;
25+
/* Call the calibrartion routine
26+
We use c2t in the print below to convert run counts to run time
27+
*/
28+
c2t = Delta2Time(0);
29+
30+
Delta_T(1,&et); /* Initialize the counter for overall time */
31+
for(i = 0l; i < 28; i++) {
32+
Delta_T(1,&delta); /* Initialize the counter for this run */
33+
for(j = 0; j < (1<<i); j++);
34+
r = Delta_T(0,&delta); /* Get the test run delta counts */
35+
/* Print the output */
36+
fprintf(stderr,"i = %lu, r = %lu t = %e nS\n",i,r,c2t * r );
37+
}
38+
et = Delta_T(0,&et); /* Get the overall run counts */
39+
mn = 999999L;
40+
for(k = 0; k < 1024; k++) {
41+
Delta_T(1,&mt); /* Minimum resolvable count */
42+
mt = Delta_T(0,&mt);
43+
if(mt < mn) mn = mt;
44+
}
45+
46+
/* Print out the timer calibration data */
47+
fprintf(stderr,"\nCalibration:\nConversion factor = %g nS/count\nResolution = %lu count\nSpan = %lu counts, %g nS. Minimum resolvable counts %lu\n\n",c2t,Delta_res(),Delta_spanC(),Delta_spanT(),mn);
48+
49+
/* Print out the elapsed counts/time */
50+
fprintf(stderr,"Elapsed counts = %lu, Elapsed time = %g Seconds\n",et, (et *c2t)*1e-9);
51+
return 0;
52+
53+
}

icc/DELTA/delta.c

Lines changed: 188 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,188 @@
1+
/*************************************************************************
2+
// Copyright IBM Corp. 2023
3+
//
4+
// Licensed under the Apache License 2.0 (the "License").  You may not use
5+
// this file except in compliance with the License.  You can obtain a copy
6+
// in the file LICENSE in the source distribution.
7+
*************************************************************************/
8+
9+
/*************************************************************************
10+
// Description: High resolution timing code
11+
// Leverages the event counter code we use for RNG
12+
// seeding.
13+
//
14+
*************************************************************************/
15+
16+
17+
#if defined(_WIN32)
18+
# include <windows.h>
19+
#else
20+
# include <stdio.h>
21+
# include <sys/time.h>
22+
# include <string.h>
23+
# include <stdlib.h>
24+
#endif
25+
#include "TRNG/timer_entropy.h"
26+
#include "DELTA/delta_t.h"
27+
28+
extern ICC_UINT64 RdCTR_raw();
29+
extern int Shift();
30+
31+
32+
#if defined(_WIN32)
33+
34+
struct timezone {
35+
long tz;
36+
};
37+
/*! @brief Approximate gettimeofday for windows
38+
All this does is grab time and populate values
39+
to generate one-off data
40+
it's NOT accurate
41+
\Platf Windows only
42+
@param tv Pointer to a Unixy "struct timeval"
43+
@param tz Pointer to "Unixy" "struct timezone" (Unused)
44+
@return 0
45+
*/
46+
static int gettimeofday(struct timeval *tv, struct timezone *tz)
47+
{
48+
/* Contains a 64-bit value representing the number of 100-nanosecond intervals since January 1, 1601 (UTC).*/
49+
FILETIME ft;
50+
unsigned long long ull;
51+
52+
if( NULL != tv) {
53+
GetSystemTimeAsFileTime(&ft);
54+
ull = ft.dwHighDateTime;
55+
ull <<= 32;
56+
ull |= ft.dwLowDateTime;
57+
ull /= 10; /* usec */
58+
tv->tv_usec = ull % 1000000;
59+
tv->tv_sec = ull / 1000000;
60+
}
61+
return 0;
62+
}
63+
64+
#endif
65+
66+
67+
68+
69+
static double span = 0.0;
70+
static int done = 0;
71+
72+
73+
/*! @brief return the counter span in counts,
74+
The limit before the counter overflows
75+
@return The counter span in counts
76+
*/
77+
unsigned long Delta_spanC()
78+
{
79+
unsigned long rv = (unsigned int)(-1);
80+
/* !FIXME !, work out what this is on various OS's */
81+
return rv;
82+
83+
}
84+
85+
86+
unsigned long Delta_T(int mode, unsigned long *d)
87+
{
88+
unsigned long rv = 0;
89+
unsigned long t;
90+
if(mode == 1) {
91+
*d = RdCTR_raw();
92+
} else {
93+
t = RdCTR_raw();
94+
if(t > *d) {
95+
rv = t - *d;
96+
} else {
97+
/* We need to know when this rolls over #!#! as this is HW/word size
98+
dependent
99+
This is good for x86_64, fixups are in Delta_spanC()
100+
*/
101+
rv = (Delta_spanC() - (*d)) + t;
102+
}
103+
}
104+
return rv;
105+
}
106+
107+
/*! @brief get the estimate for the base event counter resolution
108+
@return the estimated counter resolution (in counts)
109+
@note quite often the lower bits are stuck-at and are unusable
110+
*/
111+
unsigned long Delta_res()
112+
{
113+
unsigned long j;
114+
j = (unsigned long)Shift();
115+
return (unsigned long) (1 << j);
116+
}
117+
118+
/*! @brief return the APPOXIMATE time span of the counter in nS
119+
@return The approximate time span of the counter
120+
@note This will run Delta2Time() if it hasn't already been run
121+
*/
122+
double Delta_spanT()
123+
{
124+
if(!done) {
125+
Delta2Time(0);
126+
}
127+
return span;
128+
}
129+
/*! @brief
130+
Calculates delta times from struct timeval's,
131+
@param x the after timeval
132+
@param y the before timeval
133+
@return Time difference in nS
134+
@note struct timeval only has uS resolution
135+
136+
*/
137+
static double tv_sub ( struct timeval *x, struct timeval *y)
138+
{
139+
140+
long ds,dus,d;
141+
double result = 0.0;
142+
143+
144+
ds = x->tv_sec - y->tv_sec;
145+
dus = x->tv_usec - y->tv_usec;
146+
/* Normalize to uS */
147+
d = ds * 1000000 + dus;
148+
/* Convert to nS */
149+
result = d *1000.0;
150+
151+
return result;
152+
}
153+
154+
155+
double Delta2Time(int recalc)
156+
{
157+
158+
static double rv = 1.0;
159+
struct timeval tv_now, tv_then;
160+
unsigned long c_now = 0L;
161+
unsigned long delta = 0L;
162+
memset(&tv_then,0,sizeof(struct timeval));
163+
164+
memset(&tv_now,0,sizeof(struct timeval));
165+
166+
if((!done) | recalc) {
167+
Delta_T(1,&c_now);
168+
gettimeofday(&tv_then,NULL);
169+
do {
170+
delta = Delta_T(0,&c_now);
171+
} while(delta < (1<<28));
172+
173+
gettimeofday(&tv_now,NULL);
174+
175+
/* Now do the calcs, we have something near the max count available, and the elapsed time
176+
*/
177+
rv = tv_sub(&tv_now,&tv_then);
178+
/* Calculate the longest usable run time (span)
179+
Needs an OS/wordlength specific switch here
180+
*/
181+
span = rv * ((double)((unsigned int)(-1))/delta);
182+
183+
rv = (rv/(double)delta);
184+
185+
done = 1;
186+
}
187+
return rv;
188+
}

icc/DELTA/delta_t.h

Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
/*
2+
// Copyright IBM Corp. 2023
3+
//
4+
// Licensed under the Apache License 2.0 (the "License").  You may not use
5+
// this file except in compliance with the License.  You can obtain a copy
6+
// in the file LICENSE in the source distribution.
7+
*/
8+
9+
#ifndef INCLUDED_DELTA_T
10+
#define INCLUDED_DELTA_T
11+
12+
#ifdef __cplusplus
13+
extern "C" {
14+
#endif
15+
#if defined(__MVS__)
16+
#pragma export(Delta_T)
17+
#pragma export(Delta_res)
18+
#pragma export(Delta2Time)
19+
#pragma export(Delta_spanT)
20+
#pragma export(Delta_spanC)
21+
#endif
22+
23+
/*! @brief access high speed event counters
24+
@param mode 1 = initialize, 0 = read
25+
@param d a pointer to an unsigned long to hold raw count
26+
@note This code will account for at most one overflow.
27+
- This is important !. This code is intended ONLY to measure SHORT
28+
time spans at high resolution.
29+
- You can try to compenstate for this
30+
by using gettimeofday() or clock() as well to work out how many times
31+
you must have cycled. That's not done internally as the latency needed
32+
to do that may cause it's own problems in many use cases.
33+
\sa Delta_spanT() for the routine to use find the usable timing window
34+
*/
35+
unsigned long Delta_T(int mode, unsigned long *d);
36+
37+
/*! @brief get the estimate for the base event counter resolution
38+
@return the estimated counter resolution (in counts)
39+
@note quite often the lower bits are stuck-at and are unusable
40+
*/
41+
unsigned long Delta_res();
42+
43+
/*! @brief get the estimated conversion factor for counts to nS
44+
@param recalc The recalculation of the conversion factor
45+
can take quite a while depending on the span of the counter (seconds),
46+
so by default we do it once and simply return the previously
47+
generated result on subsequent calls. !0 forces this this to be redone.
48+
@return The conversion factor for counts to nS
49+
@note This isn't particularly accurate and it shouldn't be used
50+
in intermediate calculations. i.e. use count values in any statistics and
51+
use the conversion here to normalize results to real time at the end of the
52+
process.
53+
- Also note, this is extremely expensive in CPU time,
54+
it may appear to hang for quite a while depending on arch
55+
- on the other hand, you don't HAVE to call this routine
56+
- Accuracy SHOULD be better than 1%
57+
- Called by Delta_spanT() if it hasn't been run before
58+
*/
59+
double Delta2Time(int recalc);
60+
61+
/*! @brief return the APPOXIMATE time span of the counter in nS
62+
@return The approximate time span of the counter
63+
@note This will run Delta2Time() if it hasn't already been run
64+
*/
65+
double Delta_spanT();
66+
67+
/*! @brief return the counter span in counts,
68+
i.e. The limit before the counter overflows
69+
@return The counter span in counts
70+
*/
71+
unsigned long Delta_spanC();
72+
73+
#ifdef __cplusplus
74+
}
75+
#endif
76+
77+
#endif /* INCLUDED_DELTA_T */

icc/DELTA/exports/icclib_aix.exp

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
#!
2+
*DESCRIPTION 'Delta timing EXPORT FILE'
3+
4+
Delta_T
5+
Delta_res
6+
Delta2Time
7+
Delta_spanT
8+
Delta_spanC
9+

icc/DELTA/exports/icclib_hpux.exp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
#DESCRIPTION 'DELTA EXPORT FILE'
2+
+e Delta_T
3+
+e Delta_res
4+
+e Delta2Time
5+
+e Delta_spanT
6+
+e Delta_spanC

icc/DELTA/exports/icclib_linux.exp

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
#DESCRIPTION 'DELTA EXPORT FILE'
2+
3+
DELTA {
4+
global:
5+
Delta_T;
6+
Delta_res;
7+
Delta2Time;
8+
Delta_spanT;
9+
Delta_spanC;
10+
local:
11+
*;
12+
};

icc/DELTA/exports/icclib_os2.def

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
LIBRARY delta INITINSTANCE
2+
DATA NONSHARED
3+
4+
DESCRIPTION 'Delta timing Shared Library'
5+
6+
EXPORTS
7+
_Delta_T
8+
_Delta_res
9+
_Delta2Time
10+
_Delta_spanT
11+
_Delta_spanC

icc/DELTA/exports/icclib_os400.exp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
STRPGMEXP PGMLVL(*CURRENT) SIGNATURE("DELTALIB")
2+
EXPORT SYMBOL("Delta_T")
3+
EXPORT SYMBOL("Delta_res")
4+
EXPORT SYMBOL("Delta2Time")
5+
EXPORT SYMBOL("Delta_spanT")
6+
EXPORT SYMBOL("Delta_spanC")
7+
ENDPGMEXP

0 commit comments

Comments
 (0)