Exemplo n.º 1
0
inline void setupECC()
{
#ifdef DEBUG
  print("Start ECC, Curve %d\n\r", uECC_curve());
  print("Start ECC, Wordsize %d\n\r", getWordSize());
  print("Start ECC, UECC Bytes %d\n\r", uECC_BYTES);
#endif
  uECC_set_rng(&fake_rng);
  int failed = uECC_make_key(public, private);
#ifdef INFO
  if (!failed){
    print("uECC_make_key() failed\n\r");
  }
#endif

#ifdef INFO
  int i;
  print("Public key:\n\r");
  for(i=0; i<uECC_BYTES * 2; i++){
    print("%x",public[i]);
  }
  print("\n\rPrivate key:\n\r");
  for(i=0; i<uECC_BYTES; i++){
    print("%x",private[i]);
  }
  print("\n\r");
#endif
  memcpy(hash, public, uECC_BYTES);
}
Exemplo n.º 2
0
void
mynewt_tinycrypt_pkg_init(void)
{
    g_trng = (struct trng_dev *)os_dev_open(MYNEWT_VAL(TINYCRYPT_UECC_RNG_TRNG_DEV_NAME),
                                            OS_WAIT_FOREVER, NULL);
    assert(g_trng);
    uECC_set_rng(uecc_rng_trng);
}
Exemplo n.º 3
0
int main(int argc, char **argv)
{
    unsigned l_num = 1;
    unsigned i, j;
    
    if(argc > 1)
    {
        l_num = strtoul(argv[1], NULL, 10);
    }
    
    randfd = open("/dev/urandom", O_RDONLY);
    if(randfd == -1)
    {
        printf("No access to urandom\n");
        return -1;
    }
    
    uint8_t l_private[uECC_BYTES];
    uint8_t l_public[uECC_BYTES*2];
    uint8_t base64enc[uECC_BYTES*4];
    
    for(i=0; i<l_num; ++i)
    {
	uECC_set_rng(&getRandomBytes);
	uECC_make_key(l_public, l_private);
	
	base64_encode(base64enc, l_private, uECC_BYTES);
        printf("Private_key_%u= \"", i);
        printf(base64enc);
        printf("\";\n");
        printf("uint8_t private_%u[NUM_ECC_DIGITS] = {", i);
        vli_print(l_private);
        printf("};\n");


 	base64_encode(base64enc, l_public, uECC_BYTES*2);
        printf("Public_key_%u= \"", i);
        printf(base64enc);
        printf("\";\n");

        printf("uint8_t public_%u[2*NUM_ECC_DIGITS] = {", i);
        vli_print(l_public);
        vli_print(l_public+uECC_BYTES);
        printf("};\n\n");
    }
    
    return 0;
}
Exemplo n.º 4
0
e3x_cipher_t cs1a_init(lob_t options)
{
  e3x_cipher_t ret = malloc(sizeof(struct e3x_cipher_struct));
  if(!ret) return NULL;
  memset(ret,0,sizeof (struct e3x_cipher_struct));

  // identifying markers
  ret->id = CS_1a;
  ret->csid = 0x1a;
  memcpy(ret->hex,"1a",3);

  // which alg's we support
  ret->alg = "HS256 ES160";

  // normal init stuff
  uECC_set_rng(&RNG);

  // configure our callbacks (no RNG, default to platform's)
  ret->hash = cipher_hash;
  ret->err = cipher_err;
  ret->generate = cipher_generate;

  // need to cast these to map our struct types to voids
  ret->local_new = (void *(*)(lob_t, lob_t))local_new;
  ret->local_free = (void (*)(void *))local_free;
  ret->local_decrypt = (lob_t (*)(void *, lob_t))local_decrypt;
  ret->local_sign = (lob_t (*)(void *, lob_t, uint8_t *, size_t))local_sign;
  ret->remote_new = (void *(*)(lob_t, uint8_t *))remote_new;
  ret->remote_free = (void (*)(void *))remote_free;
  ret->remote_verify = (uint8_t (*)(void *, void *, lob_t))remote_verify;
  ret->remote_encrypt = (lob_t (*)(void *, void *, lob_t))remote_encrypt;
  ret->remote_validate = (uint8_t (*)(void *, lob_t, lob_t, uint8_t *, size_t))remote_validate;
  ret->ephemeral_new = (void *(*)(void *, lob_t))ephemeral_new;
  ret->ephemeral_free = (void (*)(void *))ephemeral_free;
  ret->ephemeral_encrypt = (lob_t (*)(void *, lob_t))ephemeral_encrypt;
  ret->ephemeral_decrypt = (lob_t (*)(void *, lob_t))ephemeral_decrypt;

  return ret;
}
Exemplo n.º 5
0
int crypt_init_1a()
{
  uECC_set_rng(&RNG);
  return 0;
}