mirror of
https://github.com/openssl/openssl.git
synced 2025-01-06 13:26:43 +08:00
6853d09368
Reviewed-by: Bernd Edlinger <bernd.edlinger@hotmail.de> (Merged from https://github.com/openssl/openssl/pull/5105)
146 lines
5.4 KiB
C
146 lines
5.4 KiB
C
#include <stdio.h>
|
|
#include <string.h>
|
|
#include <openssl/e_os2.h>
|
|
#include "curve448_lcl.h"
|
|
|
|
/* Test vectors from RFC7748 */
|
|
|
|
const uint8_t in_scalar1[56] = {
|
|
0x3d, 0x26, 0x2f, 0xdd, 0xf9, 0xec, 0x8e, 0x88, 0x49, 0x52, 0x66, 0xfe,
|
|
0xa1, 0x9a, 0x34, 0xd2, 0x88, 0x82, 0xac, 0xef, 0x04, 0x51, 0x04, 0xd0,
|
|
0xd1, 0xaa, 0xe1, 0x21, 0x70, 0x0a, 0x77, 0x9c, 0x98, 0x4c, 0x24, 0xf8,
|
|
0xcd, 0xd7, 0x8f, 0xbf, 0xf4, 0x49, 0x43, 0xeb, 0xa3, 0x68, 0xf5, 0x4b,
|
|
0x29, 0x25, 0x9a, 0x4f, 0x1c, 0x60, 0x0a, 0xd3
|
|
};
|
|
|
|
const uint8_t in_u1[56] = {
|
|
0x06, 0xfc, 0xe6, 0x40, 0xfa, 0x34, 0x87, 0xbf, 0xda, 0x5f, 0x6c, 0xf2,
|
|
0xd5, 0x26, 0x3f, 0x8a, 0xad, 0x88, 0x33, 0x4c, 0xbd, 0x07, 0x43, 0x7f,
|
|
0x02, 0x0f, 0x08, 0xf9, 0x81, 0x4d, 0xc0, 0x31, 0xdd, 0xbd, 0xc3, 0x8c,
|
|
0x19, 0xc6, 0xda, 0x25, 0x83, 0xfa, 0x54, 0x29, 0xdb, 0x94, 0xad, 0xa1,
|
|
0x8a, 0xa7, 0xa7, 0xfb, 0x4e, 0xf8, 0xa0, 0x86
|
|
};
|
|
|
|
const uint8_t out_u1[56] = {
|
|
0xce, 0x3e, 0x4f, 0xf9, 0x5a, 0x60, 0xdc, 0x66, 0x97, 0x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uint8_t out_u2[56] = {
|
|
0x88, 0x4a, 0x02, 0x57, 0x62, 0x39, 0xff, 0x7a, 0x2f, 0x2f, 0x63, 0xb2,
|
|
0xdb, 0x6a, 0x9f, 0xf3, 0x70, 0x47, 0xac, 0x13, 0x56, 0x8e, 0x1e, 0x30,
|
|
0xfe, 0x63, 0xc4, 0xa7, 0xad, 0x1b, 0x3e, 0xe3, 0xa5, 0x70, 0x0d, 0xf3,
|
|
0x43, 0x21, 0xd6, 0x20, 0x77, 0xe6, 0x36, 0x33, 0xc5, 0x75, 0xc1, 0xc9,
|
|
0x54, 0x51, 0x4e, 0x99, 0xda, 0x7c, 0x17, 0x9d
|
|
};
|
|
|
|
const uint8_t in_u3[56] = {
|
|
0x05, 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, 0x00, 0x00, 0x00, 0x00,
|
|
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
|
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
|
|
};
|
|
|
|
const uint8_t out_u3[3][56] = {
|
|
{
|
|
0x3f, 0x48, 0x2c, 0x8a, 0x9f, 0x19, 0xb0, 0x1e, 0x6c, 0x46, 0xee, 0x97,
|
|
0x11, 0xd9, 0xdc, 0x14, 0xfd, 0x4b, 0xf6, 0x7a, 0xf3, 0x07, 0x65, 0xc2,
|
|
0xae, 0x2b, 0x84, 0x6a, 0x4d, 0x23, 0xa8, 0xcd, 0x0d, 0xb8, 0x97, 0x08,
|
|
0x62, 0x39, 0x49, 0x2c, 0xaf, 0x35, 0x0b, 0x51, 0xf8, 0x33, 0x86, 0x8b,
|
|
0x9b, 0xc2, 0xb3, 0xbc, 0xa9, 0xcf, 0x41, 0x13
|
|
}, {
|
|
0xaa, 0x3b, 0x47, 0x49, 0xd5, 0x5b, 0x9d, 0xaf, 0x1e, 0x5b, 0x00, 0x28,
|
|
0x88, 0x26, 0xc4, 0x67, 0x27, 0x4c, 0xe3, 0xeb, 0xbd, 0xd5, 0xc1, 0x7b,
|
|
0x97, 0x5e, 0x09, 0xd4, 0xaf, 0x6c, 0x67, 0xcf, 0x10, 0xd0, 0x87, 0x20,
|
|
0x2d, 0xb8, 0x82, 0x86, 0xe2, 0xb7, 0x9f, 0xce, 0xea, 0x3e, 0xc3, 0x53,
|
|
0xef, 0x54, 0xfa, 0xa2, 0x6e, 0x21, 0x9f, 0x38
|
|
}, {
|
|
0x07, 0x7f, 0x45, 0x36, 0x81, 0xca, 0xca, 0x36, 0x93, 0x19, 0x84, 0x20,
|
|
0xbb, 0xe5, 0x15, 0xca, 0xe0, 0x00, 0x24, 0x72, 0x51, 0x9b, 0x3e, 0x67,
|
|
0x66, 0x1a, 0x7e, 0x89, 0xca, 0xb9, 0x46, 0x95, 0xc8, 0xf4, 0xbc, 0xd6,
|
|
0x6e, 0x61, 0xb9, 0xb9, 0xc9, 0x46, 0xda, 0x8d, 0x52, 0x4d, 0xe3, 0xd6,
|
|
0x9b, 0xd9, 0xd9, 0xd6, 0x6b, 0x99, 0x7e, 0x37
|
|
}
|
|
};
|
|
|
|
int main(int argc, char *argv[])
|
|
{
|
|
uint8_t u[56], k[56], out[56];
|
|
unsigned int i, max = 1000;
|
|
int j = -1;
|
|
|
|
if (argc != 1 && (argc != 2 || strcmp(argv[1], "-f") != 0)) {
|
|
printf ("Usage: curve448_test [-f]\n");
|
|
return 1;
|
|
}
|
|
|
|
if (argc == 2)
|
|
max = 1000000;
|
|
|
|
if (!X448(out, in_scalar1, in_u1)) {
|
|
printf("Failed in X448 call (1)\n");
|
|
return 1;
|
|
}
|
|
if (memcmp(out, out_u1, sizeof(out)) != 0) {
|
|
printf("Calculated output and expected output differ (1)\n");
|
|
return 1;
|
|
}
|
|
|
|
if (!X448(out, in_scalar2, in_u2)) {
|
|
printf("Failed in X448 call (2)\n");
|
|
return 1;
|
|
}
|
|
if (memcmp(out, out_u2, sizeof(out)) != 0) {
|
|
printf("Calculated output and expected output differ (2)\n");
|
|
return 1;
|
|
}
|
|
|
|
memcpy(u, in_u3, sizeof(u));
|
|
memcpy(k, in_u3, sizeof(k));
|
|
for (i = 1; i <= max; i++) {
|
|
if (i % 10000 == 0) {
|
|
printf(".");
|
|
fflush(stdout);
|
|
}
|
|
|
|
if (!X448(out, k, u)) {
|
|
printf("Failed in X448 call (3, %ud)\n", i);
|
|
return 1;
|
|
}
|
|
if (i == 1 || i == 1000 || i == 1000000) {
|
|
j++;
|
|
if (memcmp(out, out_u3[j], sizeof(out)) != 0) {
|
|
printf("Calculated output and expected output differ (3, %ud)\n",
|
|
i);
|
|
return 1;
|
|
}
|
|
}
|
|
memcpy(u, k, sizeof(u));
|
|
memcpy(k, out, sizeof(k));
|
|
}
|
|
|
|
printf("\nSuccess!\n");
|
|
|
|
return 0;
|
|
}
|