tseed.c - sick - sign and check files using ed25519
 (HTM) git clone git://z3bra.org/sick
 (DIR) Log
 (DIR) Files
 (DIR) Refs
 (DIR) README
 (DIR) LICENSE
       ---
       tseed.c (644B)
       ---
            1 #include "ed25519.h"
            2 
            3 #ifndef ED25519_NO_SEED
            4 
            5 #ifdef _WIN32
            6 #include <windows.h>
            7 #include <wincrypt.h>
            8 #else
            9 #include <stdio.h>
           10 #endif
           11 
           12 int ed25519_create_seed(unsigned char *seed) {
           13 #ifdef _WIN32
           14     HCRYPTPROV prov;
           15 
           16     if (!CryptAcquireContext(&prov, NULL, NULL, PROV_RSA_FULL, CRYPT_VERIFYCONTEXT))  {
           17         return 1;
           18     }
           19 
           20     if (!CryptGenRandom(prov, 32, seed))  {
           21         CryptReleaseContext(prov, 0);
           22         return 1;
           23     }
           24 
           25     CryptReleaseContext(prov, 0);
           26 #else
           27     FILE *f = fopen("/dev/urandom", "rb");
           28 
           29     if (f == NULL) {
           30         return 1;
           31     }
           32 
           33     fread(seed, 1, 32, f);
           34     fclose(f);
           35 #endif
           36 
           37     return 0;
           38 }
           39 
           40 #endif