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

lowram implementation #91

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open

Conversation

dop-amin
Copy link

This PR adds a third implementation variant called lowram. It focuses on using very little memory at a performance tradeoff. The implementation is written in C and based on the code in pqm4, which was added in this PR.

The original ideas for this implementation are taken from the paper

Joppe W. Bos, Joost Renes, and Amber Sprenkels. 2022. Dilithium for Memory
Constrained Devices. In Progress in Cryptology - AFRICACRYPT 2022: 13th
International Conference on Cryptology in Africa, AFRICACRYPT 2022, Fes,
Morocco, July 18–20, 2022, Proceedings. Springer-Verlag, Berlin, Heidelberg,
217–235. https://doi.org/10.1007/978-3-031-17433-9_10

and parts of the implementation in this PR are written by @mkannwischer.

I tried to retain as many files as possible from the ref implementation by moving most memory-optimization related code to lowram.c. Further, smallntt_3329.c and smallpoly.c contain functions to operate on polynomials with 16-bit coefficients. api.h, config.h, Makefile, and sign.c are the only files that should be different from ref -- everything else is just symlinks.

If there's anything that could be done to improve the quality of the implementation, feel free to let me know!

Cheers,
Amin

Copy link
Contributor

@mkannwischer mkannwischer left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

some small suggestions.

* - size_t *mlen: pointer to output length of message
* - const uint8_t *sm: pointer to signed message
* - size_t smlen: length of signed message
* - const uint8_t *ctx: pointer to context tring
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
* - const uint8_t *ctx: pointer to context tring
* - const uint8_t *ctx: pointer to context string

if(ctxlen > 255 || siglen != CRYPTO_BYTES)
return -1;

/* Compute CRH(h(rho, t1), msg) */
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
/* Compute CRH(h(rho, t1), msg) */
/* Compute mu = CRH(H(rho, t1), 0, ctxlen, ctx, msg) */

#include "poly.h"
#include "polyvec.h"

#define SMALL_POLY_16_BIT
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
#define SMALL_POLY_16_BIT

Comment on lines +47 to +54
#ifdef SMALL_POLY_16_BIT
int j;
// buffer is the same, so we neeed to be careful
for (j = N - 1; j >= 0; j--)
{
r->coeffs[j] = tmp->coeffs[j];
}
#endif
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
#ifdef SMALL_POLY_16_BIT
int j;
// buffer is the same, so we neeed to be careful
for (j = N - 1; j >= 0; j--)
{
r->coeffs[j] = tmp->coeffs[j];
}
#endif
int j;
// buffer is the same, so we neeed to be careful
for (j = N - 1; j >= 0; j--)
{
r->coeffs[j] = tmp->coeffs[j];
}


/* Code to generate zetas and zetas_inv used in the number-theoretic transform:

#define KYBER_ROOT_OF_UNITY 17
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
#define KYBER_ROOT_OF_UNITY 17
#define KYBER_ROOT_OF_UNITY 17
#define KYBER_Q 3329
#define MONT -1044

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants