medfall

A super great game engine
Log | Files | Refs

genkeys.cc (864B)


      1 #include <sys/random.h>
      2 
      3 #include <stdio.h>
      4 
      5 #include "intrinsics.h"
      6 #include "log.h"
      7 #include "libs/monocypher/monocypher.h"
      8 
      9 int main( int argc, char ** argv ) {
     10 	u8 secret_key[ 32 ];
     11 	int ok = getentropy( secret_key, sizeof( secret_key ) );
     12 	if( ok == -1 ) {
     13 		FATAL( "getentropy" );
     14 	}
     15 
     16 	u8 public_key[ 32 ];
     17 	crypto_sign_public_key( public_key, secret_key );
     18 
     19 	printf( "const u8 public_key[] = {" );
     20 
     21 	for( size_t i = 0; i < sizeof( public_key ); i++ ) {
     22 		if( i % 8 == 0 ) {
     23 			ggprint( "\n\t" );
     24 		}
     25 		else {
     26 			ggprint( " " );
     27 		}
     28 
     29 		ggprint( "0x{02x},", public_key[ i ] );
     30 	}
     31 
     32 	printf( "\n};\n" );
     33 
     34 	printf( "const u8 secret_key[] = {" );
     35 
     36 	for( size_t i = 0; i < sizeof( secret_key ); i++ ) {
     37 		if( i % 8 == 0 ) {
     38 			ggprint( "\n\t" );
     39 		}
     40 		else {
     41 			ggprint( " " );
     42 		}
     43 
     44 		ggprint( "0x{02x},", secret_key[ i ] );
     45 	}
     46 
     47 	printf( "\n};\n" );
     48 
     49 	return 0;
     50 }