Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bignum: Add the new modulus and the residue structures with low level I/O operations #6016

Closed
3 tasks
yanesca opened this issue Jul 4, 2022 · 0 comments · Fixed by #6095
Closed
3 tasks
Assignees
Labels
component-crypto Crypto primitives and low-level interfaces enhancement size-s Estimated task size: small (~2d)

Comments

@yanesca
Copy link
Contributor

yanesca commented Jul 4, 2022

Add the modulus and the residue structures with low level I/O operations.

Residue structure:

typedef struct
{
    size_t n;
    mbedtls_mpi_uint *p;
} mbedtls_mpi_mod_residue;

Modulus structure:

typedef struct {
    mbedtls_mpi_uint *p;
    size_t n; // number of limbs
    size_t plen; // bitlen of p
    int ext_rep; // signals external representation (eg. byte order)
    int int_rep; // selector to signal the active member of the union
    union rep
    {
        mbedtls_mpi_mont_struct mont;
        mbedtls_mpi_opt_red_struct ored;
    };
} mbedtls_mpi_mod_modulus;

(The latter is different from the one in the design document and this is intentional as there were changes based on Gilles's feedback.)

mbedtls_mpi_mont_struct and mbedtls_mpi_opt_red_struct are dummy structs for now (eg aliasing to void*).

The task is to add life cycle functions and low level I/O:

  • Standard init and free functions for the modulus. The residue doesn't own its memory, it only needs a release function, that releases the pointer set in setup (sets the p to NULL and n to 0). (The modulus doesn't own the memory pointed by p either, but will need to allocate memory for mbedtls_mpi_opt_red_struct later). Setup for residue takes a modulus and a raw pointer (mbedtls_mpi_uint*). It takes n from there and fails if the value defined by the raw pointer and n is greater than or equal to the modulus. Setup for the modulus takes p, n, ext_rep, int_rep and calculates plen. All of these have mbedtls_mpi_mod prefix and are declared in library/bignum_mod.h.
  • One set of I/O functions (mbedtls_mpi_core_read_le(),mbedtls_mpi_core_write_le(), mbedtls_mpi_core_read_be(),mbedtls_mpi_core_write_be()). These should work exactly like their legacy counterparts (eg. mbedtls_mpi_read_binary()), but should take a raw pointer (mbedtls_mpi_uint*) and a length instead of an mbedtls_mpi*. The legacy functions should call these new mpi_core_ functions instead of duplicating code. The function declarations go into library/bignum_core.h.
  • Another set of I/O functions (mbedtls_mpi_mod_raw_read() and mbedtls_mpi_mod_raw_write()) should take a raw pointer (mbedtls_mpi_uint*) and a modulus. The length and the external representation should be taken from the modulus. The function declarations go into library/bignum_mod_raw.h.

All new function implementations should go into bignum_new.c.

This task is done when the following changes are merged on development:

  • The two structures and their life cycle functions have been added
  • The core I/O functions have been added with extensive unit tests
  • The raw I/O functions have been added with extensive unit tests
@yanesca yanesca added enhancement component-crypto Crypto primitives and low-level interfaces size-s Estimated task size: small (~2d) needs-info An issue or PR which needs further info from the reporter / author labels Jul 4, 2022
@yanesca yanesca changed the title Add basic structures and dummy I/O for the new Bignum interface Add the new modulus and the residue structures with low level I/O operations Jul 8, 2022
@yanesca yanesca removed the needs-info An issue or PR which needs further info from the reporter / author label Jul 8, 2022
@gabor-mezei-arm gabor-mezei-arm self-assigned this Jul 8, 2022
@tom-cosgrove-arm tom-cosgrove-arm changed the title Add the new modulus and the residue structures with low level I/O operations Bignum: Add the new modulus and the residue structures with low level I/O operations Dec 11, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
component-crypto Crypto primitives and low-level interfaces enhancement size-s Estimated task size: small (~2d)
Projects
None yet
2 participants