Esempio n. 1
0
int main( int argc, char **argv )
{
  uint8_t key[BLAKE2S_KEYBYTES];
  uint8_t buf[KAT_LENGTH];

  for( size_t i = 0; i < BLAKE2S_KEYBYTES; ++i )
    key[i] = ( uint8_t )i;

  for( size_t i = 0; i < KAT_LENGTH; ++i )
    buf[i] = ( uint8_t )i;

  for( size_t i = 0; i < KAT_LENGTH; ++i )
  {
    uint8_t hash[BLAKE2S_OUTBYTES];

    if( blake2s( hash, buf, key, BLAKE2S_OUTBYTES, i, BLAKE2S_KEYBYTES ) < 0 ||
        0 != memcmp( hash, blake2s_keyed_kat[i], BLAKE2S_OUTBYTES ) )
    {
      puts( "error" );
      return -1;
    }
  }

  puts( "ok" );
  return 0;
}
Esempio n. 2
0
void __init wg_noise_init(void)
{
	struct blake2s_state blake;

	blake2s(handshake_init_chaining_key, handshake_name, NULL,
		NOISE_HASH_LEN, sizeof(handshake_name), 0);
	blake2s_init(&blake, NOISE_HASH_LEN);
	blake2s_update(&blake, handshake_init_chaining_key, NOISE_HASH_LEN);
	blake2s_update(&blake, identifier_name, sizeof(identifier_name));
	blake2s_final(&blake, handshake_init_hash);
}
Esempio n. 3
0
// Hash the data with a secure hash function.
static bool H(SkinnyCat_HashType hashType, uint8_t out[32], const uint8_t *in, uint32_t inSize) {
    switch(hashType) {
    case SKINNYCAT_BLAKE2S:
        return !blake2s(out, in, NULL, 32, inSize, 0);
    case SKINNYCAT_SHA256:
        return SHA256(in, inSize, out) != NULL;
    default:
        fprintf(stderr, "Unknown hash type\n");
    }
    return false;
}
Esempio n. 4
0
VALUE m_blake2_digest(VALUE self, VALUE _input, VALUE _representation) {
  Blake2 *blake2;

  char *input      = RSTRING_PTR(_input);
  int input_length = RSTRING_LEN(_input);
  int i;

  Data_Get_Struct(self, Blake2, blake2);

  blake2s(blake2->output, input, blake2->key_bytes,
      blake2->output_length, input_length, blake2->key_length);

  VALUE result;

  if(_representation == blake2->to_bytes) {
    result = rb_ary_new2(blake2->output_length);

    for(i = 0; i < blake2->output_length; i++) {
      rb_ary_push(result, INT2NUM(blake2->output[i]));
    }
  } else if(_representation == blake2->to_hex) {
    int ary_len = blake2->output_length * sizeof(char) * 2;
    char *c_str = (char*)malloc(ary_len + 1);

    for(i = 0; i < blake2->output_length; i++) {
      sprintf(c_str + (i * 2), "%02x", blake2->output[i]);
    }
    c_str[ary_len] = 0;

    result = rb_str_new(c_str, ary_len);

    if(RSTRING_LEN(result) != ary_len) {
      rb_raise(rb_eRuntimeError, "m_blake2_digest: sizes don't match. Ary: %d != %d", RSTRING_LEN(result), ary_len);
    }

    free(c_str);
  } else {
    rb_raise(rb_eArgError, "unknown representation :%"PRIsVALUE"", _representation);
  }

  return result;
}
Esempio n. 5
0
int crypto_hash( unsigned char *out, unsigned char *in, unsigned long long inlen )
{
  return blake2s( out, in, NULL, BLAKE2S_OUTBYTES, inlen, 0 );
}