source: git/src-ed25519/supercop-ref/test.c

Last change on this file was 9598517, checked in by Brian Warner <warner@…>, at 2012-02-12T15:05:37Z

Add Ed25519 signatures, in pycryptopp.publickey.ed25519 . Closes #75.

This copies in version 1.0 of python-ed25519, from
https://github.com/warner/python-ed25519 (or pypi), with minor source-code
rearrangement to match pycryptopp's build process. It includes unit tests,
power-on self-tests, and full known-answer tests. The standard 'setup.py
test' target only exercises 10% of the test vectors, to let the suite run in
about 1.0s on my laptop. The API documentation is in README.ed25519 .

Tests have been run successfully on Linux, OS-X and windows.

  • Property mode set to 100644
File size: 1.1 KB
Line 
1
2#include <stdlib.h>
3#include <stdio.h>
4#include <string.h>
5#include "crypto_sign.h"
6
7char *msg = "Hello World";
8
9int main(int argc, char *argv[]) {
10    unsigned char sk[SECRETKEYBYTES], vk[PUBLICKEYBYTES];
11    unsigned char *sigmsg, *newmsg;
12    unsigned long long sigmsglen, newmsglen;
13    int ret;
14    crypto_sign_keypair(vk, sk);
15    printf("got keypair\n");
16    sigmsg = malloc(strlen(msg)+1+BYTES);
17    if (!sigmsg)
18        return 1;
19    crypto_sign(sigmsg, &sigmsglen, (unsigned char *)msg, strlen(msg)+1, sk);
20    printf("got signature\n");
21    if (sigmsglen != strlen(msg)+1+BYTES)
22        return 2;
23    newmsg = malloc(sigmsglen);
24    if (!newmsg)
25        return 3;
26    ret = crypto_sign_open(newmsg, &newmsglen, sigmsg, sigmsglen, vk);
27    printf("verified signature\n");
28    if (ret == 0)
29        printf("good!\n");
30    else
31        printf("bad\n");
32    sigmsg[0] ^= 0x01;
33    ret = crypto_sign_open(newmsg, &newmsglen, sigmsg, sigmsglen, vk);
34    if (ret == 0) 
35        printf("bad: failed to detect simple corruption\n");
36    else
37        printf("good: detected simple corruption\n");
38    return 0;
39}
Note: See TracBrowser for help on using the repository browser.