Exemple #1
0
  u3_noun
  u3qe_shal(u3_atom a,
            u3_atom b)
  {
    c3_assert(_(u3a_is_cat(a)));
    c3_y* fat_y = u3a_malloc(a + 1);

    u3r_bytes(0, a, fat_y, b);
    {
      c3_y dig_y[64];
#if defined(U3_OS_osx)
      CC_SHA512_CTX ctx_h;

      CC_SHA512_Init(&ctx_h);
      CC_SHA512_Update(&ctx_h, fat_y, a);
      CC_SHA512_Final(dig_y, &ctx_h);
#else
      SHA512_CTX ctx_h;

      SHA512_Init(&ctx_h);
      SHA512_Update(&ctx_h, fat_y, a);
      SHA512_Final(dig_y, &ctx_h);
#endif
      u3a_free(fat_y);
      return u3i_bytes(64, dig_y);
    }
  }
Exemple #2
0
Fichier : muk.c Projet : bd/urbit
/* functions
*/
  u3_noun
  u3qc_muk(u3_atom seed,
           u3_atom len,
           u3_atom key)
  {
    c3_w seed_w;
    c3_w len_w;
    c3_y *key_y;
    c3_w out_w;

    c3_assert(u3r_met(5, seed) <= 1);
    c3_assert(u3r_met(0, len)  <= 31);
    c3_assert(u3r_met(3, key)  <= len);

    seed_w = u3r_word(0, seed);
    len_w  = u3r_word(0, len);
    if (len_w > 0) { /* can't u3a_calloc 0 bytes */
      key_y  = u3a_calloc(sizeof(c3_y), len);
    } else {
      key_y = 0;
    }
    u3r_bytes(0, len, key_y, key);

    MurmurHash3_x86_32(key_y, len, seed_w, &out_w);

    u3a_free(key_y);
    return u3i_words(1, &out_w);
  }
Exemple #3
0
//   u3_noun
//   u3qe_shax(
//                     u3_atom a)
//   {
//     c3_w  met_w = u3r_met(3, a);
//     return u3qe_shay(met_w, a);
//   }
//  XX  preformance
u3_noun
  u3qe_shax(u3_atom a)
  {
    c3_w  met_w = u3r_met(3, a);
    c3_y* fat_y = u3a_malloc(met_w + 1);

    u3r_bytes(0, met_w, fat_y, a);
    {
      c3_y dig_y[32];
#if defined(U3_OS_osx)
      CC_SHA256_CTX ctx_h;

      CC_SHA256_Init(&ctx_h);
      CC_SHA256_Update(&ctx_h, fat_y, met_w);
      CC_SHA256_Final(dig_y, &ctx_h);
#else
      SHA256_CTX ctx_h;

      SHA256_Init(&ctx_h);
      SHA256_Update(&ctx_h, fat_y, met_w);
      SHA256_Final(dig_y, &ctx_h);
#endif
      u3a_free(fat_y);
      return u3i_bytes(32, dig_y);
    }
  }
Exemple #4
0
 void argon2_free(uint8_t* memory, size_t bytes)
 {
   u3a_free(memory);
 }