<commit_before>/* j/5/shax.c
**
** This file is in the public domain.
*/
#include "all.h"
#include "../pit.h"

#pragma GCC diagnostic ignored "-Wdeprecated-declarations"

#include <openssl/sha.h>

/* functions
*/
  u2_weak                                                         //  produce
  j2_mbc(Pt5, shax)(u2_wire wir_r,
                    u2_atom a)                                    //  retain
  {
    c3_w  met_w = u2_met(3, a);
    c3_y* fat_y = c3_malloc(met_w + 1);

    u2_bytes(0, met_w, fat_y, a);
    {
      c3_y dig_y[32];
      SHA256_CTX ctx_h;

      SHA256_Init(&ctx_h);
      SHA256_Update(&ctx_h, fat_y, met_w);
      SHA256_Final(dig_y, &ctx_h);
      free(fat_y);
      return u2_rl_bytes(wir_r, 32, dig_y);
    }
  }

  u2_weak                                                         //  produce
  j2_mbc(Pt5, shal)(u2_wire wir_r,
                    u2_atom a,                                    //  retain
                    u2_atom b)                                    //  retain
  {
    c3_assert(u2_fly_is_cat(a));
    c3_y* fat_y = c3_malloc(a + 1);

    u2_bytes(0, a, fat_y, b);
    {
      c3_y dig_y[64];
      SHA512_CTX ctx_h;

      SHA512_Init(&ctx_h);
      SHA512_Update(&ctx_h, fat_y, a);
      SHA512_Final(dig_y, &ctx_h);
      free(fat_y);
      return u2_rl_bytes(wir_r, 64, dig_y);
    }
  }<commit_msg>Use CommonCrypto for sha on OS X<commit_after>/* j/5/shax.c
**
** This file is in the public domain.
*/
#include "all.h"
#include "../pit.h"

#if defined(U2_OS_osx)
#include <CommonCrypto/CommonDigest.h>
#else
#include <openssl/sha.h>
#endif

/* functions
*/
  u2_weak                                                         //  produce
  j2_mbc(Pt5, shax)(u2_wire wir_r,
                    u2_atom a)                                    //  retain
  {
    c3_w  met_w = u2_met(3, a);
    c3_y* fat_y = c3_malloc(met_w + 1);

    u2_bytes(0, met_w, fat_y, a);
    {
      c3_y dig_y[32];
#if defined(U2_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
      free(fat_y);
      return u2_rl_bytes(wir_r, 32, dig_y);
    }
  }

  u2_weak                                                         //  produce
  j2_mbc(Pt5, shal)(u2_wire wir_r,
                    u2_atom a,                                    //  retain
                    u2_atom b)                                    //  retain
  {
    c3_assert(u2_fly_is_cat(a));
    c3_y* fat_y = c3_malloc(a + 1);

    u2_bytes(0, a, fat_y, b);
    {
      c3_y dig_y[64];
#if defined(U2_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
      free(fat_y);
      return u2_rl_bytes(wir_r, 64, dig_y);
    }
  }
{'fraction_non_alphanumeric': 0.11789405684754523, 'fraction_numerical': 0.04941860465116279, 'mean_word_length': 1.5322976287816843, 'pattern_counts': {'":': 0, '<': 6, '<?xml version=': 0, '>': 6, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 14, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7270889', 'n_tokens_mistral': 1310, 'n_tokens_neox': 1224, 'n_words': 213}