supercop

Basic CLI for supercop
git clone git://git.finwo.net/app/supercop
Log | Files | Refs | README | LICENSE

decode.c (785B)


      1 #include <stdlib.h>
      2 #include <string.h>
      3 
      4 #include "common.h"
      5 
      6 #ifdef __cplusplus
      7 extern "C" {
      8 #endif
      9 
     10 struct KeyPair * fmt_0x00_decode(unsigned char *cipherdata, size_t len) {
     11   struct KeyPair *kp;
     12   // Pub-only (33 bytes) or full (97 bytes), anything else is invalid
     13   if (len != 33 && len != 97) return NULL;
     14   kp = calloc(1, sizeof(struct KeyPair));
     15   if (!kp) return NULL;
     16   kp->public_key  = calloc(1, 32);
     17   if (!kp->public_key) {
     18     free(kp);
     19     return NULL;
     20   }
     21   memcpy(kp->public_key , cipherdata +  1, 32);
     22   if (len == 97) {
     23     kp->private_key = calloc(1, 64);
     24     if (!kp->private_key) {
     25       free(kp->public_key);
     26       free(kp);
     27       return NULL;
     28     }
     29     memcpy(kp->private_key, cipherdata + 33, 64);
     30   }
     31   return kp;
     32 }
     33 
     34 #ifdef __cplusplus
     35 } // extern "C"
     36 #endif