diff options
| author | patrick-scho | 2023-11-13 19:58:33 +0100 |
|---|---|---|
| committer | patrick-scho | 2023-11-13 19:58:33 +0100 |
| commit | da776f86b42946715c27edd64f7558b9d5080df1 (patch) | |
| tree | c7e340bb253bd38f73368baeec7f12e914a39955 /ext/olm/lib/curve25519-donna/test-noncanon.c | |
| parent | 21c6e8484b0bd05c27e5a91f2884d431926adc61 (diff) | |
| download | matrix_esp_thesis-da776f86b42946715c27edd64f7558b9d5080df1.tar.gz matrix_esp_thesis-da776f86b42946715c27edd64f7558b9d5080df1.zip | |
add dependencies to repo
Diffstat (limited to 'ext/olm/lib/curve25519-donna/test-noncanon.c')
| -rw-r--r-- | ext/olm/lib/curve25519-donna/test-noncanon.c | 39 |
1 files changed, 39 insertions, 0 deletions
diff --git a/ext/olm/lib/curve25519-donna/test-noncanon.c b/ext/olm/lib/curve25519-donna/test-noncanon.c new file mode 100644 index 0000000..6de4e8d --- /dev/null +++ b/ext/olm/lib/curve25519-donna/test-noncanon.c @@ -0,0 +1,39 @@ +/* This file can be used to test whether the code handles non-canonical curve + * points (i.e. points with the 256th bit set) in the same way as the reference + * implementation. */ + +#include <stdint.h> +#include <stdio.h> +#include <string.h> + +extern void curve25519_donna(unsigned char *output, const unsigned char *a, + const unsigned char *b); +int +main() +{ + static const uint8_t point1[32] = { + 0x25,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + }; + static const uint8_t point2[32] = { + 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff, + 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff, + 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff, + 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff, + }; + static const uint8_t scalar[32] = { 1 }; + uint8_t out1[32], out2[32]; + + curve25519_donna(out1, scalar, point1); + curve25519_donna(out2, scalar, point2); + + if (0 == memcmp(out1, out2, sizeof(out1))) { + fprintf(stderr, "Top bit not ignored.\n"); + return 1; + } + + fprintf(stderr, "Top bit correctly ignored.\n"); + return 0; +} |
