diff options
Diffstat (limited to 'libcmix-bignum')
| -rw-r--r-- | libcmix-bignum/CMakeLists.txt | 33 | ||||
| -rw-r--r-- | libcmix-bignum/bignum.h | 72 | ||||
| -rw-r--r-- | libcmix-bignum/gmp/CMakeLists.txt | 14 | ||||
| -rw-r--r-- | libcmix-bignum/gmp/gmp_bignum.c | 49 | ||||
| -rw-r--r-- | libcmix-bignum/null/CMakeLists.txt | 11 | ||||
| -rw-r--r-- | libcmix-bignum/null/null_bignum.c | 9 |
6 files changed, 0 insertions, 188 deletions
diff --git a/libcmix-bignum/CMakeLists.txt b/libcmix-bignum/CMakeLists.txt deleted file mode 100644 index 2cadc87..0000000 --- a/libcmix-bignum/CMakeLists.txt +++ /dev/null @@ -1,33 +0,0 @@ - -add_library(cmix-bignum-interface INTERFACE) - -target_include_directories(cmix-bignum-interface - INTERFACE ${CMAKE_CURRENT_SOURCE_DIR} -) - -set(interface_sources - ${CMAKE_CURRENT_SOURCE_DIR}/bignum.h -) - -target_sources(cmix-bignum-interface - INTERFACE ${interface_sources} -) - -include(bignum_implementations) -foreach(impl ${libcmix_bignum_implementations}) - add_subdirectory(${impl}) -endforeach() - -add_library(cmix-bignum INTERFACE) - -target_include_directories(cmix-bignum - INTERFACE ${CMAKE_CURRENT_SOURCE_DIR} -) - -target_sources(cmix-bignum - INTERFACE ${interface_sources} -) - -target_link_libraries(cmix-bignum - INTERFACE libcmix-bignum-${libcmix_bignum_implementation} -) diff --git a/libcmix-bignum/bignum.h b/libcmix-bignum/bignum.h deleted file mode 100644 index fe690cc..0000000 --- a/libcmix-bignum/bignum.h +++ /dev/null @@ -1,72 +0,0 @@ -#pragma once - -#include <stddef.h> -#include <stdlib.h> - -#ifdef __cplusplus -extern "C" { -#endif - -/*! - * \file - */ - -/*! - * \brief The bignum_error enum - */ -enum bignum_error { - NoError = 0, - error = -1 -}; - -/*! - * \brief cMix internal bignum representation. - */ -struct Bignum { - unsigned char* data; ///< Pointer to the start of the bignum. - size_t len; ///< The length of the data array. -}; - -/*! - * \brief allocate_bignum. Reserves space for a len size Bignum. - * \param len The length of the bignum data array. - * \return The Bignum array just allocated. - */ -inline struct Bignum allocate_bignum(size_t len) { - return (struct Bignum){ - (unsigned char*) malloc(len), - len - }; -} - -/*! - * \brief free_bignum. Counterpart to allocate_bignum. - * \param b The bignum to free - */ -inline void free_bignum(struct Bignum* b) { - free(b->data); - b->data = 0; - b->len = 0; -} - -/*! - * \brief get_curve25519_mod. Conveniance for now, but this returns the mod of curve25519 algorith (2^255-19) - * \param result The bignum to store the modulus in, has to be preallocated. - * \return Error status code based on backend errors. - */ -extern enum bignum_error get_curve25519_mod(struct Bignum* result); - -/*! - * \brief multiply_mod Multiplies 2 bignums module mod and stores the result in result. - * \param result Preallocated Bignum where the result will be stored. - * \param lh Lefthand of Multiplication. - * \param rh Righthand of Multiplaction. - * \param mod The modulus. - * \return Error status code based on backend errors. - */ -extern enum bignum_error multiply_mod(struct Bignum* result, struct Bignum const lh, struct Bignum const rh, struct Bignum const mod); - - -#ifdef __cplusplus -} -#endif
\ No newline at end of file diff --git a/libcmix-bignum/gmp/CMakeLists.txt b/libcmix-bignum/gmp/CMakeLists.txt deleted file mode 100644 index 4b3acbb..0000000 --- a/libcmix-bignum/gmp/CMakeLists.txt +++ /dev/null @@ -1,14 +0,0 @@ -include(get_target_name) - -get_target_name(target_name) - -find_package(gmp REQUIRED) - -add_library(${target_name} SHARED - gmp_bignum.c -) - -target_link_libraries(${target_name} - PRIVATE cmix-bignum-interface - PRIVATE gmp -) diff --git a/libcmix-bignum/gmp/gmp_bignum.c b/libcmix-bignum/gmp/gmp_bignum.c deleted file mode 100644 index cc40b48..0000000 --- a/libcmix-bignum/gmp/gmp_bignum.c +++ /dev/null @@ -1,49 +0,0 @@ -#include "bignum.h" - -#include "gmp.h" - -void from_bignum(mpz_t i, struct Bignum b) { - mpz_import(i, b.len, -1, 1, 0, 0, b.data); -} - -void to_bignum(struct Bignum* b, mpz_t i) { - mpz_export(b->data, &b->len, -1, 1, 0, 0, i); -} - -enum bignum_error get_curve25519_mod(struct Bignum* result) { - mpz_t mod; - mpz_init(mod); - mpz_ui_pow_ui(mod, 2, 255); - mpz_sub_ui(mod, mod, 19); - - to_bignum(result, mod); - return NoError; -} - -enum bignum_error multiply_mod(struct Bignum* result, struct Bignum const lh, struct Bignum const rh, struct Bignum const mod) { - mpz_t lh_; - mpz_init(lh_); - from_bignum(lh_, lh); - - mpz_t rh_; - mpz_init(rh_); - from_bignum(rh_, rh); - - mpz_t result_; - mpz_init(result_); - mpz_mul(result_, lh_, rh_); - - mpz_t mod_; - mpz_init(mod_); - from_bignum(mod_, mod); - mpz_mod(result_, result_, mod_); - - to_bignum(result, result_); - - mpz_clear(result_); - mpz_clear(lh_); - mpz_clear(rh_); - mpz_clear(mod_); - - return NoError; -} diff --git a/libcmix-bignum/null/CMakeLists.txt b/libcmix-bignum/null/CMakeLists.txt deleted file mode 100644 index 325d1c8..0000000 --- a/libcmix-bignum/null/CMakeLists.txt +++ /dev/null @@ -1,11 +0,0 @@ -include(get_target_name) - -get_target_name(target_name) - -add_library(${target_name} SHARED - null_bignum.c -) - -target_link_libraries(${target_name} - PRIVATE cmix-bignum-interface -) diff --git a/libcmix-bignum/null/null_bignum.c b/libcmix-bignum/null/null_bignum.c deleted file mode 100644 index 3b45132..0000000 --- a/libcmix-bignum/null/null_bignum.c +++ /dev/null @@ -1,9 +0,0 @@ -#include "bignum.h" - -extern enum bignum_error get_curve25519_mod(struct Bignum* result) { - return NoError; -} - -extern enum bignum_error multiply_mod(struct Bignum* result, struct Bignum const lh, struct Bignum const rh, struct Bignum const mod) { - return NoError; -} |
