Skip to content

Commit 3363ee4

Browse files
committed
Add proper status indication APIs for all algorithms
Each algorithm type received a proper status API that may return information about the given particular algorithm instance. This update allows for FIPS that, say, lc_sha256 is marked as FIPS approved algorithm, but any other implementation such as lc_sha256_ahani on ARM (which would point to the C implementation and thus would not point to the accelerated ARM implementation) are not marked as FIPS-approved. To complete the implementation, the following changes are applied which all are not visible to the caller: - add lc_*_null.c implementation which define a symbol in case the associated algorithm is not compiled - wrap ChaCha20 DRNG into an lc_rng structure Signed-off-by: Stephan Mueller <smueller@chronox.de>
1 parent f8742e6 commit 3363ee4

File tree

143 files changed

+2245
-745
lines changed

Some content is hidden

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

143 files changed

+2245
-745
lines changed

CHANGES.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,10 @@ Changes 1.7.0-prerelease
4747

4848
* Update of X.509 composite signatures with latest draft + cross testing with all IETF-Hackathon providers
4949

50+
* Add proper status indication APIs for all algorithms
51+
52+
* ChaCha20 DRNG wrapped in common wrapper
53+
5054
Changes 1.6.0
5155
* ASN.1: use stack for small generator for small use cases
5256

aead/api/lc_aead.h

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222

2323
#include "lc_aes.h"
2424
#include "lc_memory_support.h"
25+
#include "lc_status.h"
2526

2627
#ifdef __cplusplus
2728
extern "C" {
@@ -268,23 +269,23 @@ int lc_aead_dec_final(struct lc_aead_ctx *ctx, const uint8_t *tag,
268269

269270
/**
270271
* @ingroup AEAD
271-
* @brief Obtain algorithm type usable with lc_alg_status
272+
* @brief Obtain algorithm status
272273
*
273274
* @param [in] aead AEAD algorithm instance
274275
*
275-
* @return algorithm type
276+
* @return algorithm status
276277
*/
277-
uint64_t lc_aead_algorithm_type(const struct lc_aead *aead);
278+
enum lc_alg_status_val lc_aead_alg_status(const struct lc_aead *aead);
278279

279280
/**
280281
* @ingroup AEAD
281-
* @brief Obtain algorithm type usable with lc_alg_status
282+
* @brief Obtain algorithm status
282283
*
283284
* @param [in] ctx AEAD context handle
284285
*
285-
* @return algorithm type
286+
* @return algorithm status
286287
*/
287-
uint64_t lc_aead_ctx_algorithm_type(const struct lc_aead_ctx *ctx);
288+
enum lc_alg_status_val lc_aead_ctx_alg_status(const struct lc_aead_ctx *ctx);
288289

289290
#ifdef __cplusplus
290291
}

aead/src/aead_api.c

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
#include "ext_headers_internal.h"
2121
#include "lc_aead.h"
2222
#include "lc_memory_support.h"
23+
#include "status_algorithms.h"
2324
#include "visibility.h"
2425

2526
LC_INTERFACE_FUNCTION(void, lc_aead_zero, struct lc_aead_ctx *ctx)
@@ -231,20 +232,21 @@ LC_INTERFACE_FUNCTION(int, lc_aead_dec_final, struct lc_aead_ctx *ctx,
231232
return aead->dec_final(aead_state, tag, taglen);
232233
}
233234

234-
LC_INTERFACE_FUNCTION(uint64_t, lc_aead_algorithm_type,
235+
LC_INTERFACE_FUNCTION(enum lc_alg_status_val, lc_aead_alg_status,
235236
const struct lc_aead *aead)
236237
{
237238
if (!aead)
238-
return 0;
239+
return lc_alg_status_unknown;
239240

240-
return aead->algorithm_type;
241+
/* No algorithm is ruled out a-priori for FIPS compliance */
242+
return lc_alg_status(aead->algorithm_type | LC_ALG_STATUS_FIPS);
241243
}
242244

243-
LC_INTERFACE_FUNCTION(uint64_t, lc_aead_ctx_algorithm_type,
245+
LC_INTERFACE_FUNCTION(enum lc_alg_status_val, lc_aead_ctx_alg_status,
244246
const struct lc_aead_ctx *ctx)
245247
{
246248
if (!ctx)
247-
return 0;
249+
return lc_alg_status_unknown;
248250

249-
return lc_aead_algorithm_type(ctx->aead);
251+
return lc_aead_alg_status(ctx->aead);
250252
}

aead/tests/aes_gcm_tester.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -210,7 +210,7 @@ LC_TEST_FUNC(int, main, int argc, char *argv[])
210210

211211
ret = lc_aes_gcm_test(argc);
212212

213-
ret = test_validate_status(ret, LC_ALG_STATUS_AES_GCM, 1);
213+
ret = test_validate_status(ret, lc_aead_alg_status(lc_aes_gcm_aead), 1);
214214
ret += test_print_status();
215215

216216
lc_cpu_feature_enable();

aead/tests/ascon_crypt_test.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -178,7 +178,7 @@ LC_TEST_FUNC(int, main, int argc, char *argv[])
178178
ret += ascon_tester_128();
179179
ret += ascon_tester_128_non_aligned();
180180

181-
ret = test_validate_status(ret, LC_ALG_STATUS_ASCON_AEAD_128, 1);
181+
ret = test_validate_status(ret, lc_aead_alg_status(lc_ascon_aead), 1);
182182
ret += test_print_status();
183183

184184
return ret;

aead/tests/ascon_keccak_crypt_test.c

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -392,15 +392,16 @@ LC_TEST_FUNC(int, main, int argc, char *argv[])
392392
LC_EXEC_ONE_TEST_256(lc_sha3_256_avx512);
393393
LC_EXEC_ONE_TEST_256(lc_sha3_256_riscv_asm);
394394

395-
if (!(lc_alg_status(lc_aead_algorithm_type(lc_ascon_keccak_aead)) &
395+
if (!(lc_aead_alg_status(lc_ascon_keccak_aead) &
396396
lc_alg_status_self_test_passed)) {
397-
printf("lc_aead_algorithm_type failure\n");
397+
printf("lc_aead_alg_status failure\n");
398398
ret++;
399399
} else {
400-
printf("lc_aead_algorithm_type pass\n");
400+
printf("lc_aead_alg_status pass\n");
401401
}
402402

403-
ret = test_validate_status(ret, LC_ALG_STATUS_ASCON_KECCAK, 0);
403+
ret = test_validate_status(ret,
404+
lc_aead_alg_status(lc_ascon_keccak_aead), 0);
404405
ret += test_print_status();
405406

406407
return ret;

aead/tests/chacha20poly1305_tester.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -146,7 +146,8 @@ LC_TEST_FUNC(int, main, int argc, char *argv[])
146146

147147
ret = lc_chacha20_poly1305_test(argc);
148148

149-
ret = test_validate_status(ret, LC_ALG_STATUS_CHACHA20_POLY1305, 0);
149+
ret = test_validate_status(
150+
ret, lc_aead_alg_status(lc_chacha20_poly1305_aead), 0);
150151
ret += test_print_status();
151152

152153
return ret;

aead/tests/cshake_crypt_test.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -245,7 +245,7 @@ LC_TEST_FUNC(int, main, int argc, char *argv[])
245245
}
246246
ret += ret2;
247247

248-
ret = test_validate_status(ret, LC_ALG_STATUS_CSHAKE_CRYPT, 0);
248+
ret = test_validate_status(ret, lc_aead_alg_status(lc_cshake_aead), 0);
249249
ret += test_print_status();
250250

251251
out:

aead/tests/hash_crypt_test.c

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
#include "compare.h"
2121
#include "ext_headers_internal.h"
2222
#include "lc_hash_crypt.h"
23+
#include "lc_sha256.h"
2324
#include "lc_sha512.h"
2425
#include "test_helper_common.h"
2526
#include "visibility.h"
@@ -175,16 +176,16 @@ LC_TEST_FUNC(int, main, int argc, char *argv[])
175176

176177
ret = hc_tester_sha512();
177178

178-
ret = test_validate_status(ret, LC_ALG_STATUS_HASH_CRYPT, 0);
179-
ret = test_validate_status(ret, LC_ALG_STATUS_HASH_DRBG, 0);
180-
ret = test_validate_status(ret, LC_ALG_STATUS_SHA512, 1);
179+
ret = test_validate_status(ret, lc_aead_alg_status(lc_hash_aead), 0);
180+
ret = test_validate_status(ret, lc_rng_alg_status(lc_hash_drbg), 0);
181+
ret = test_validate_status(ret, lc_hash_alg_status(lc_sha512), 1);
181182
#ifndef LC_FIPS140_DEBUG
182183
/*
183184
* These algos are not even triggered due to initialization errors
184185
* of the higher tests.
185186
*/
186-
ret = test_validate_status(ret, LC_ALG_STATUS_SHA256, 1);
187-
ret = test_validate_status(ret, LC_ALG_STATUS_HMAC, 1);
187+
ret = test_validate_status(ret, lc_hash_alg_status(lc_sha256), 1);
188+
ret = test_validate_status(ret, lc_hmac_alg_status(lc_sha256), 1);
188189
#endif
189190
ret += test_print_status();
190191

aead/tests/kmac_crypt_test.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -243,9 +243,9 @@ LC_TEST_FUNC(int, main, int argc, char *argv[])
243243
}
244244
ret += ret2;
245245

246-
ret = test_validate_status(ret, LC_ALG_STATUS_KMAC_CRYPT, 0);
246+
ret = test_validate_status(ret, lc_aead_alg_status(lc_kmac_aead), 0);
247247
#ifndef LC_FIPS140_DEBUG
248-
ret = test_validate_status(ret, LC_ALG_STATUS_KMAC, 1);
248+
ret = test_validate_status(ret, lc_kmac_alg_status(lc_cshake256), 1);
249249
#endif
250250
ret += test_print_status();
251251

0 commit comments

Comments
 (0)