Skip to content

Commit

Permalink
Expose callback API for replacing low-level cryptographic primitives
Browse files Browse the repository at this point in the history
This makes the callback API to replace low-level cryptographic
implementation public again after #1667.

Signed-off-by: Daiki Ueno <[email protected]>
  • Loading branch information
ueno committed Jul 10, 2024
1 parent d2089c5 commit b929e79
Show file tree
Hide file tree
Showing 11 changed files with 737 additions and 623 deletions.
4 changes: 4 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -150,8 +150,12 @@ if(${OQS_USE_OPENSSL})
endif()

set(PUBLIC_HEADERS ${PROJECT_SOURCE_DIR}/src/oqs.h
${PROJECT_SOURCE_DIR}/src/common/aes/aes_ops.h
${PROJECT_SOURCE_DIR}/src/common/common.h
${PROJECT_SOURCE_DIR}/src/common/rand/rand.h
${PROJECT_SOURCE_DIR}/src/common/sha2/sha2_ops.h
${PROJECT_SOURCE_DIR}/src/common/sha3/sha3_ops.h
${PROJECT_SOURCE_DIR}/src/common/sha3/sha3x4_ops.h
${PROJECT_SOURCE_DIR}/src/kem/kem.h
${PROJECT_SOURCE_DIR}/src/sig/sig.h
${PROJECT_SOURCE_DIR}/src/sig_stfl/sig_stfl.h)
Expand Down
6 changes: 5 additions & 1 deletion docs/.Doxyfile
Original file line number Diff line number Diff line change
Expand Up @@ -949,8 +949,12 @@ WARN_LOGFILE =
# spaces. See also FILE_PATTERNS and EXTENSION_MAPPING
# Note: If this tag is empty the current directory is searched.

INPUT = src/common/common.h \
INPUT = src/common/aes/aes_ops.h \
src/common/common.h \
src/common/rand/rand.h \
src/common/sha2/sha2_ops.h \
src/common/sha3/sha3_ops.h \
src/common/sha3/sha3x4_ops.h \
src/kem/kem.h \
src/sig/sig.h \
README.md \
Expand Down
82 changes: 1 addition & 81 deletions src/common/aes/aes.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
#include <stdint.h>
#include <stdlib.h>

#include <oqs/common.h>
#include <oqs/aes_ops.h>

#if defined(__cplusplus)
extern "C" {
Expand Down Expand Up @@ -149,86 +149,6 @@ void OQS_AES256_CTR_inc_stream_iv(const uint8_t *iv, size_t iv_len, const void *
*/
void OQS_AES256_CTR_inc_stream_blks(void *ctx, uint8_t *out, size_t out_blks);

/** Data structure implemented by cryptographic provider for AES operations.
*/
struct OQS_AES_callbacks {
/**
* Implementation of function OQS_AES128_ECB_load_schedule.
*/
void (*AES128_ECB_load_schedule)(const uint8_t *key, void **ctx);

/**
* Implementation of function OQS_AES128_free_schedule.
*/
void (*AES128_free_schedule)(void *ctx);

/**
* Implementation of function OQS_AES128_ECB_enc.
*/
void (*AES128_ECB_enc)(const uint8_t *plaintext, const size_t plaintext_len, const uint8_t *key, uint8_t *ciphertext);

/**
* Implementation of function OQS_AES128_ECB_enc_sch.
*/
void (*AES128_ECB_enc_sch)(const uint8_t *plaintext, const size_t plaintext_len, const void *schedule, uint8_t *ciphertext);

/**
* Implementation of function OQS_AES256_ECB_load_schedule.
*/
void (*AES256_ECB_load_schedule)(const uint8_t *key, void **ctx);

/**
* Implementation of function OQS_AES256_CTR_inc_init.
*/
void (*AES256_CTR_inc_init)(const uint8_t *key, void **ctx);

/**
* Implementation of function OQS_AES256_CTR_inc_iv.
*/
void (*AES256_CTR_inc_iv)(const uint8_t *iv, size_t iv_len, void *ctx);

/**
* Implementation of function OQS_AES256_CTR_inc_ivu64.
*/
void (*AES256_CTR_inc_ivu64)(uint64_t iv, void *ctx);

/**
* Implementation of function OQS_AES256_free_schedule.
*/
void (*AES256_free_schedule)(void *ctx);

/**
* Implementation of function OQS_AES256_ECB_enc.
*/
void (*AES256_ECB_enc)(const uint8_t *plaintext, const size_t plaintext_len, const uint8_t *key, uint8_t *ciphertext);

/**
* Implementation of function OQS_AES256_ECB_enc_sch.
*/
void (*AES256_ECB_enc_sch)(const uint8_t *plaintext, const size_t plaintext_len, const void *schedule, uint8_t *ciphertext);

/**
* Implementation of function OQS_AES256_CTR_inc_stream_iv.
*/
void (*AES256_CTR_inc_stream_iv)(const uint8_t *iv, size_t iv_len, const void *ctx, uint8_t *out, size_t out_len);

/**
* Implementation of function OQS_AES256_CTR_inc_stream_blks.
*/
void (*AES256_CTR_inc_stream_blks)(void *ctx, uint8_t *out, size_t out_blks);
};

/**
* Set callback functions for AES operations.
*
* This function may be called before OQS_init to switch the
* cryptographic provider for AES operations. If it is not called, the
* default provider determined at build time will be used.
*
* @param[in] new_callbacks Callback functions defined in OQS_AES_callbacks
*/
OQS_API void OQS_AES_set_callbacks(struct OQS_AES_callbacks *new_callbacks);

#if defined(__cplusplus)
} // extern "C"
#endif
Expand Down
104 changes: 104 additions & 0 deletions src/common/aes/aes_ops.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,104 @@
/**
* \file aes_ops.h
* \brief Header defining the callback API for OQS AES
*
* SPDX-License-Identifier: MIT
*/

#ifndef OQS_AES_OPS_H
#define OQS_AES_OPS_H

#include <stdint.h>
#include <stdlib.h>

#include <oqs/common.h>

#if defined(__cplusplus)
extern "C" {
#endif

/** Data structure implemented by cryptographic provider for AES operations.
*/
struct OQS_AES_callbacks {
/**
* Implementation of function OQS_AES128_ECB_load_schedule.
*/
void (*AES128_ECB_load_schedule)(const uint8_t *key, void **ctx);

/**
* Implementation of function OQS_AES128_free_schedule.
*/
void (*AES128_free_schedule)(void *ctx);

/**
* Implementation of function OQS_AES128_ECB_enc.
*/
void (*AES128_ECB_enc)(const uint8_t *plaintext, const size_t plaintext_len, const uint8_t *key, uint8_t *ciphertext);

/**
* Implementation of function OQS_AES128_ECB_enc_sch.
*/
void (*AES128_ECB_enc_sch)(const uint8_t *plaintext, const size_t plaintext_len, const void *schedule, uint8_t *ciphertext);

/**
* Implementation of function OQS_AES256_ECB_load_schedule.
*/
void (*AES256_ECB_load_schedule)(const uint8_t *key, void **ctx);

/**
* Implementation of function OQS_AES256_CTR_inc_init.
*/
void (*AES256_CTR_inc_init)(const uint8_t *key, void **ctx);

/**
* Implementation of function OQS_AES256_CTR_inc_iv.
*/
void (*AES256_CTR_inc_iv)(const uint8_t *iv, size_t iv_len, void *ctx);

/**
* Implementation of function OQS_AES256_CTR_inc_ivu64.
*/
void (*AES256_CTR_inc_ivu64)(uint64_t iv, void *ctx);

/**
* Implementation of function OQS_AES256_free_schedule.
*/
void (*AES256_free_schedule)(void *ctx);

/**
* Implementation of function OQS_AES256_ECB_enc.
*/
void (*AES256_ECB_enc)(const uint8_t *plaintext, const size_t plaintext_len, const uint8_t *key, uint8_t *ciphertext);

/**
* Implementation of function OQS_AES256_ECB_enc_sch.
*/
void (*AES256_ECB_enc_sch)(const uint8_t *plaintext, const size_t plaintext_len, const void *schedule, uint8_t *ciphertext);

/**
* Implementation of function OQS_AES256_CTR_inc_stream_iv.
*/
void (*AES256_CTR_inc_stream_iv)(const uint8_t *iv, size_t iv_len, const void *ctx, uint8_t *out, size_t out_len);

/**
* Implementation of function OQS_AES256_CTR_inc_stream_blks.
*/
void (*AES256_CTR_inc_stream_blks)(void *ctx, uint8_t *out, size_t out_blks);
};

/**
* Set callback functions for AES operations.
*
* This function may be called before OQS_init to switch the
* cryptographic provider for AES operations. If it is not called, the
* default provider determined at build time will be used.
*
* @param[in] new_callbacks Callback functions defined in OQS_AES_callbacks
*/
OQS_API void OQS_AES_set_callbacks(struct OQS_AES_callbacks *new_callbacks);

#if defined(__cplusplus)
} // extern "C"
#endif

#endif // OQS_AES_OPS_H
Loading

0 comments on commit b929e79

Please sign in to comment.