示例#1
0
int module_hash_decode (MAYBE_UNUSED const hashconfig_t *hashconfig, MAYBE_UNUSED void *digest_buf, MAYBE_UNUSED salt_t *salt, MAYBE_UNUSED void *esalt_buf, MAYBE_UNUSED void *hook_salt_buf, MAYBE_UNUSED hashinfo_t *hash_info, const char *line_buf, MAYBE_UNUSED const int line_len)
{
  u32 *digest = (u32 *) digest_buf;

  token_t token;

  token.token_cnt  = 3;

  token.signatures_cnt    = 1;
  token.signatures_buf[0] = SIGNATURE_MYSQL_AUTH;

  token.len[0]     = 9;
  token.attr[0]    = TOKEN_ATTR_FIXED_LENGTH
                   | TOKEN_ATTR_VERIFY_SIGNATURE;

  token.sep[1]     = '*';
  token.len_min[1] = 40;
  token.len_max[1] = 40;
  token.attr[1]    = TOKEN_ATTR_VERIFY_LENGTH
                   | TOKEN_ATTR_VERIFY_HEX;

  token.sep[2]     = '*';
  token.len_min[2] = 40;
  token.len_max[2] = 40;
  token.attr[2]    = TOKEN_ATTR_VERIFY_LENGTH
                   | TOKEN_ATTR_VERIFY_HEX;

  const int rc_tokenizer = input_tokenizer ((const u8 *) line_buf, line_len, &token);

  if (rc_tokenizer != PARSER_OK) return (rc_tokenizer);

  // hash

  const u8 *hash_pos = token.buf[2];

  digest[0] = hex_to_u32 (hash_pos +  0);
  digest[1] = hex_to_u32 (hash_pos +  8);
  digest[2] = hex_to_u32 (hash_pos + 16);
  digest[3] = hex_to_u32 (hash_pos + 24);
  digest[4] = hex_to_u32 (hash_pos + 32);

  digest[0] = byte_swap_32 (digest[0]);
  digest[1] = byte_swap_32 (digest[1]);
  digest[2] = byte_swap_32 (digest[2]);
  digest[3] = byte_swap_32 (digest[3]);
  digest[4] = byte_swap_32 (digest[4]);

  /*
   * store salt
   */

  const u8 *salt_pos = token.buf[1];
  const int salt_len = token.len[1];

  const bool parse_rc = generic_salt_decode (hashconfig, salt_pos, salt_len, (u8 *) salt->salt_buf, (int *) &salt->salt_len);

  if (parse_rc == false) return (PARSER_SALT_LENGTH);

  return (PARSER_OK);
}
示例#2
0
int module_hash_decode (MAYBE_UNUSED const hashconfig_t *hashconfig, MAYBE_UNUSED void *digest_buf, MAYBE_UNUSED salt_t *salt, MAYBE_UNUSED void *esalt_buf, MAYBE_UNUSED void *hook_salt_buf, MAYBE_UNUSED hashinfo_t *hash_info, const char *line_buf, MAYBE_UNUSED const int line_len)
{
  u32 *digest = (u32 *) digest_buf;

  token_t token;

  token.token_cnt  = 2;

  token.sep[0]     = hashconfig->separator;
  token.len_min[0] = 40;
  token.len_max[0] = 40;
  token.attr[0]    = TOKEN_ATTR_VERIFY_LENGTH
                   | TOKEN_ATTR_VERIFY_HEX;

  token.len_min[1] = 20;
  token.len_max[1] = 20;
  token.attr[1]    = TOKEN_ATTR_VERIFY_LENGTH
                   | TOKEN_ATTR_VERIFY_HEX;

  const int rc_tokenizer = input_tokenizer ((const u8 *) line_buf, line_len, &token);

  if (rc_tokenizer != PARSER_OK) return (rc_tokenizer);

  const u8 *hash_pos = token.buf[0];

  digest[0] = hex_to_u32 (hash_pos +  0);
  digest[1] = hex_to_u32 (hash_pos +  8);
  digest[2] = hex_to_u32 (hash_pos + 16);
  digest[3] = hex_to_u32 (hash_pos + 24);
  digest[4] = hex_to_u32 (hash_pos + 32);

  digest[0] = byte_swap_32 (digest[0]);
  digest[1] = byte_swap_32 (digest[1]);
  digest[2] = byte_swap_32 (digest[2]);
  digest[3] = byte_swap_32 (digest[3]);
  digest[4] = byte_swap_32 (digest[4]);

  if (hashconfig->opti_type & OPTI_TYPE_OPTIMIZED_KERNEL)
  {
    digest[0] -= SHA1M_A;
    digest[1] -= SHA1M_B;
    digest[2] -= SHA1M_C;
    digest[3] -= SHA1M_D;
    digest[4] -= SHA1M_E;
  }

  const u8 *salt_pos = token.buf[1];
  const int salt_len = token.len[1];

  const bool parse_rc = generic_salt_decode (hashconfig, salt_pos, salt_len, (u8 *) salt->salt_buf, (int *) &salt->salt_len);

  if (parse_rc == false) return (PARSER_SALT_LENGTH);

  return (PARSER_OK);
}
示例#3
0
int module_hash_encode (MAYBE_UNUSED const hashconfig_t *hashconfig, MAYBE_UNUSED const void *digest_buf, MAYBE_UNUSED const salt_t *salt, MAYBE_UNUSED const void *esalt_buf, MAYBE_UNUSED const void *hook_salt_buf, MAYBE_UNUSED const hashinfo_t *hash_info, char *line_buf, MAYBE_UNUSED const int line_size)
{
  const u32 *digest = (const u32 *) digest_buf;

  const ikepsk_t *ikepsk = (const ikepsk_t *) esalt_buf;

  int line_len = 0;

  // msg_buf

  const u32 ikepsk_msg_len = ikepsk->msg_len[5] / 4;

  for (u32 i = 0; i < ikepsk_msg_len; i++)
  {
    if ((i == ikepsk->msg_len[0] / 4) || (i == ikepsk->msg_len[1] / 4) || (i == ikepsk->msg_len[2] / 4) || (i == ikepsk->msg_len[3] / 4) || (i == ikepsk->msg_len[4] / 4))
    {
      line_len += snprintf (line_buf + line_len, line_size - line_len, ":");
    }

    line_len += snprintf (line_buf + line_len, line_size - line_len, "%08x", byte_swap_32 (ikepsk->msg_buf[i]));
  }

  // nr_buf

  const u32 ikepsk_nr_len = ikepsk->nr_len / 4;

  for (u32 i = 0; i < ikepsk_nr_len; i++)
  {
    if ((i == 0) || (i == 5))
    {
      line_len += snprintf (line_buf + line_len, line_size - line_len, ":");
    }

    line_len += snprintf (line_buf + line_len, line_size - line_len, "%08x", byte_swap_32 (ikepsk->nr_buf[i]));
  }

  // digest_buf

  for (u32 i = 0; i < 4; i++)
  {
    if (i == 0)
    {
      line_len += snprintf (line_buf + line_len, line_size - line_len, ":");
    }

    line_len += snprintf (line_buf + line_len, line_size - line_len, "%08x", byte_swap_32 (digest[i]));
  }

  return line_len;
}
示例#4
0
int module_hash_decode (MAYBE_UNUSED const hashconfig_t *hashconfig, MAYBE_UNUSED void *digest_buf, MAYBE_UNUSED salt_t *salt, MAYBE_UNUSED void *esalt_buf, MAYBE_UNUSED void *hook_salt_buf, MAYBE_UNUSED hashinfo_t *hash_info, const char *line_buf, MAYBE_UNUSED const int line_len)
{
  u32 *digest = (u32 *) digest_buf;

  token_t token;

  token.token_cnt  = 2;

  token.signatures_cnt    = 1;
  token.signatures_buf[0] = "{SHA}";

  token.len[0]     = 5;
  token.attr[0]    = TOKEN_ATTR_FIXED_LENGTH
                   | TOKEN_ATTR_VERIFY_SIGNATURE;

  token.len_min[1] = 28;
  token.len_max[1] = 28;
  token.attr[1]    = TOKEN_ATTR_VERIFY_LENGTH
                   | TOKEN_ATTR_VERIFY_BASE64A;

  const int rc_tokenizer = input_tokenizer ((const u8 *) line_buf, line_len, &token);

  if (rc_tokenizer != PARSER_OK) return (rc_tokenizer);

  const u8 *hash_pos = token.buf[1];
  const int hash_len = token.len[1];

  u8 tmp_buf[100] = { 0 };

  base64_decode (base64_to_int, hash_pos, hash_len, tmp_buf);

  memcpy (digest, tmp_buf, 20);

  digest[0] = byte_swap_32 (digest[0]);
  digest[1] = byte_swap_32 (digest[1]);
  digest[2] = byte_swap_32 (digest[2]);
  digest[3] = byte_swap_32 (digest[3]);
  digest[4] = byte_swap_32 (digest[4]);

  if (hashconfig->opti_type & OPTI_TYPE_OPTIMIZED_KERNEL)
  {
    digest[0] -= SHA1M_A;
    digest[1] -= SHA1M_B;
    digest[2] -= SHA1M_C;
    digest[3] -= SHA1M_D;
    digest[4] -= SHA1M_E;
  }

  return (PARSER_OK);
}
示例#5
0
int module_hash_encode (MAYBE_UNUSED const hashconfig_t *hashconfig, MAYBE_UNUSED const void *digest_buf, MAYBE_UNUSED const salt_t *salt, MAYBE_UNUSED const void *esalt_buf, MAYBE_UNUSED const void *hook_salt_buf, MAYBE_UNUSED const hashinfo_t *hash_info, char *line_buf, MAYBE_UNUSED const int line_size)
{
  const u32 *digest = (const u32 *) digest_buf;

  char tmp_buf[64];

  // salt

  memcpy (tmp_buf, salt->salt_buf, 12);

  // digest

  u32 tmp[5];

  tmp[0] = digest[0];
  tmp[1] = digest[1];
  tmp[2] = digest[2];
  tmp[3] = digest[3];
  tmp[4] = digest[4];

  if (hashconfig->opti_type & OPTI_TYPE_OPTIMIZED_KERNEL)
  {
    tmp[0] += SHA1M_A;
    tmp[1] += SHA1M_B;
    tmp[2] += SHA1M_C;
    tmp[3] += SHA1M_D;
    tmp[4] += SHA1M_E;
  }

  tmp[0] = byte_swap_32 (tmp[0]);
  tmp[1] = byte_swap_32 (tmp[1]);
  tmp[2] = byte_swap_32 (tmp[2]);
  tmp[3] = byte_swap_32 (tmp[3]);
  tmp[4] = byte_swap_32 (tmp[4]);

  memcpy (tmp_buf + 12, tmp, 20);

  // base64 encode (salt + SHA1)

  char ptr_plain[48];

  base64_encode (int_to_base64, (const u8 *) tmp_buf, 12 + 20, (u8 *) ptr_plain);

  ptr_plain[44] = 0;

  const int line_len = snprintf (line_buf, line_size, "%s%s", SIGNATURE_FORTIGATE, ptr_plain);

  return line_len;
}
示例#6
0
int module_hash_encode (MAYBE_UNUSED const hashconfig_t *hashconfig, MAYBE_UNUSED const void *digest_buf, MAYBE_UNUSED const salt_t *salt, MAYBE_UNUSED const void *esalt_buf, MAYBE_UNUSED const void *hook_salt_buf, MAYBE_UNUSED const hashinfo_t *hash_info, char *line_buf, MAYBE_UNUSED const int line_size)
{
  const u32 *digest = (const u32 *) digest_buf;

  u32 tmp[5];

  tmp[0] = byte_swap_32 (digest[0]);
  tmp[1] = byte_swap_32 (digest[1]);
  tmp[2] = byte_swap_32 (digest[2]);
  tmp[3] = byte_swap_32 (digest[3]);
  tmp[4] = byte_swap_32 (digest[4]);

  char digest_buf_c[34];

  base32_encode (int_to_itoa32, (const u8 *) tmp, 20, (u8 *) digest_buf_c);

  digest_buf_c[32] = 0;

  // domain

  const u32 salt_pc_len = salt->salt_len_pc;

  char domain_buf_c[33] = { 0 };

  memcpy (domain_buf_c, (char *) salt->salt_buf_pc, salt_pc_len);

  for (u32 i = 0; i < salt_pc_len; i++)
  {
    const char next = domain_buf_c[i];

    domain_buf_c[i] = '.';

    i += next;
  }

  domain_buf_c[salt_pc_len] = 0;

  // final

  char tmp_salt[SALT_MAX * 2];

  const int salt_len = generic_salt_encode (hashconfig, (const u8 *) salt->salt_buf, (const int) salt->salt_len, (u8 *) tmp_salt);

  tmp_salt[salt_len] = 0;

  const int line_len = snprintf (line_buf, line_size, "%s:%s:%s:%u", digest_buf_c, domain_buf_c, tmp_salt, salt->salt_iter);

  return line_len;
}
示例#7
0
int module_hash_encode (MAYBE_UNUSED const hashconfig_t *hashconfig, MAYBE_UNUSED const void *digest_buf, MAYBE_UNUSED const salt_t *salt, MAYBE_UNUSED const void *esalt_buf, MAYBE_UNUSED const void *hook_salt_buf, MAYBE_UNUSED const hashinfo_t *hash_info, char *line_buf, MAYBE_UNUSED const int line_size)
{
  const jks_sha1_t *jks_sha1 = (const jks_sha1_t *) esalt_buf;

  char enc_key[16384 + 1] = { 0 };

  u8 *ptr = (u8 *) jks_sha1->enc_key_buf;

  for (u32 i = 0, j = 0; i < jks_sha1->enc_key_len; i += 1, j += 2)
  {
    sprintf (enc_key + j, "%02X", ptr[i]);
  }

  u8 *der = (u8 *) jks_sha1->der;

  const int line_len = snprintf (line_buf, line_size, "%s*%08X%08X%08X%08X%08X*%08X%08X%08X%08X%08X*%s*%02X*%02X%02X%02X%02X%02X%02X%02X%02X%02X%02X%02X%02X%02X%02X*%s",
    SIGNATURE_JKS_SHA1,
    byte_swap_32 (jks_sha1->checksum[0]),
    byte_swap_32 (jks_sha1->checksum[1]),
    byte_swap_32 (jks_sha1->checksum[2]),
    byte_swap_32 (jks_sha1->checksum[3]),
    byte_swap_32 (jks_sha1->checksum[4]),
    byte_swap_32 (jks_sha1->iv[0]),
    byte_swap_32 (jks_sha1->iv[1]),
    byte_swap_32 (jks_sha1->iv[2]),
    byte_swap_32 (jks_sha1->iv[3]),
    byte_swap_32 (jks_sha1->iv[4]),
    enc_key,
    der[ 0],
    der[ 6],
    der[ 7],
    der[ 8],
    der[ 9],
    der[10],
    der[11],
    der[12],
    der[13],
    der[14],
    der[15],
    der[16],
    der[17],
    der[18],
    der[19],
    (char *) jks_sha1->alias
  );

  return line_len;
}
示例#8
0
int module_hash_encode (MAYBE_UNUSED const hashconfig_t *hashconfig, MAYBE_UNUSED const void *digest_buf, MAYBE_UNUSED const salt_t *salt, MAYBE_UNUSED const void *esalt_buf, MAYBE_UNUSED const void *hook_salt_buf, MAYBE_UNUSED const hashinfo_t *hash_info, char *line_buf, MAYBE_UNUSED const int line_size)
{
  const u32 *digest = (const u32 *) digest_buf;

  // we can not change anything in the original buffer, otherwise destroying sorting
  // therefore create some local buffer

  u32 tmp[5];

  tmp[0] = digest[0];
  tmp[1] = digest[1];
  tmp[2] = digest[2];
  tmp[3] = digest[3];
  tmp[4] = digest[4];

  if (hashconfig->opti_type & OPTI_TYPE_OPTIMIZED_KERNEL)
  {
    tmp[0] += SHA1M_A;
    tmp[1] += SHA1M_B;
    tmp[2] += SHA1M_C;
    tmp[3] += SHA1M_D;
    tmp[4] += SHA1M_E;
  }

  tmp[0] = byte_swap_32 (tmp[0]);
  tmp[1] = byte_swap_32 (tmp[1]);
  tmp[2] = byte_swap_32 (tmp[2]);
  tmp[3] = byte_swap_32 (tmp[3]);
  tmp[4] = byte_swap_32 (tmp[4]);

  u8 *out_buf = (u8 *) line_buf;

  int out_len = 0;

  u32_to_hex (tmp[0], out_buf + out_len); out_len += 8;
  u32_to_hex (tmp[1], out_buf + out_len); out_len += 8;
  u32_to_hex (tmp[2], out_buf + out_len); out_len += 8;
  u32_to_hex (tmp[3], out_buf + out_len); out_len += 8;
  u32_to_hex (tmp[4], out_buf + out_len); out_len += 8;

  out_buf[out_len] = hashconfig->separator;

  out_len += 1;

  out_len += generic_salt_encode (hashconfig, (const u8 *) salt->salt_buf, (const int) salt->salt_len, out_buf + out_len);

  return out_len;
}
示例#9
0
static
void Sun2Intel_SQADS( struct sqads2_meris *sqads )
{
     sqads->mjd.days = byte_swap_32( sqads->mjd.days );
     sqads->mjd.secnd = byte_swap_u32( sqads->mjd.secnd );
     sqads->mjd.musec = byte_swap_u32( sqads->mjd.musec );
}
示例#10
0
static
void Sun2Intel_DOAS( struct doas_scia *doas )
{
     register unsigned short nc;

     unsigned int n_cross;

     doas->mjd.days = byte_swap_32( doas->mjd.days );
     doas->mjd.secnd = byte_swap_u32( doas->mjd.secnd );
     doas->mjd.musec = byte_swap_u32( doas->mjd.musec );
     doas->dsrlen = byte_swap_u32( doas->dsrlen );
     doas->intg_time = byte_swap_u16( doas->intg_time );
     IEEE_Swap__FLT( &doas->vcd );
     IEEE_Swap__FLT( &doas->errvcd );
     IEEE_Swap__FLT( &doas->esc );
     IEEE_Swap__FLT( &doas->erresc );
     IEEE_Swap__FLT( &doas->rms );
     IEEE_Swap__FLT( &doas->chi2 );
     IEEE_Swap__FLT( &doas->goodness );
     IEEE_Swap__FLT( &doas->amfgnd );
     IEEE_Swap__FLT( &doas->amfcld );
     IEEE_Swap__FLT( &doas->reflgnd );
     IEEE_Swap__FLT( &doas->reflcld );
     IEEE_Swap__FLT( &doas->refl );

     doas->numiter = byte_swap_u16( doas->numiter );
     n_cross = (doas->numfitp * (doas->numfitp - 1)) / 2;
     for ( nc = 0; nc < n_cross; nc++ ) IEEE_Swap__FLT( &doas->corrpar[nc] );
}
示例#11
0
static
void Sun2Intel_MDS_14( struct mds_rr2_14_meris *mds_14 )
{
     mds_14->mjd.days = byte_swap_32( mds_14->mjd.days );
     mds_14->mjd.secnd = byte_swap_u32( mds_14->mjd.secnd );
     mds_14->mjd.musec = byte_swap_u32( mds_14->mjd.musec );
}
示例#12
0
/* Convert the user provided key KEY of KEY_LENGTH bytes into the
   internally used format.  */
static void
serpent_key_prepare (const byte *key, unsigned int key_length,
		     serpent_key_t key_prepared)
{
  unsigned int i;

  /* Copy key.  */
  for (i = 0; i < key_length / 4; i++)
    {
#ifdef WORDS_BIGENDIAN
      key_prepared[i] = byte_swap_32 (((u32 *) key)[i]);
#else
      key_prepared[i] = ((u32 *) key)[i];
#endif
    }

  if (i < 8)
    {
      /* Key must be padded according to the Serpent
	 specification.  */
      key_prepared[i] = 0x00000001;

      for (i++; i < 8; i++)
	key_prepared[i] = 0;
    }
}
示例#13
0
static
void Sun2Intel_BIAS( struct bias_scia *bias )
{
     register unsigned short nc;

     unsigned int n_cross;

     bias->mjd.days = byte_swap_32( bias->mjd.days );
     bias->mjd.secnd = byte_swap_u32( bias->mjd.secnd );
     bias->mjd.musec = byte_swap_u32( bias->mjd.musec );
     bias->dsrlen = byte_swap_u32( bias->dsrlen );
     bias->intg_time = byte_swap_u16( bias->intg_time );
     bias->numsegm = byte_swap_u16( bias->numsegm );
     IEEE_Swap__FLT( &bias->hght );
     IEEE_Swap__FLT( &bias->errhght );
     IEEE_Swap__FLT( &bias->vcd );
     IEEE_Swap__FLT( &bias->errvcd );
     IEEE_Swap__FLT( &bias->closure );
     IEEE_Swap__FLT( &bias->errclosure );
     IEEE_Swap__FLT( &bias->rms );
     IEEE_Swap__FLT( &bias->chi2 );
     IEEE_Swap__FLT( &bias->goodness );
     IEEE_Swap__FLT( &bias->cutoff );

     bias->numiter = byte_swap_u16( bias->numiter );
     n_cross = (bias->numfitp * (bias->numfitp - 1)) / 2;
     for ( nc = 0; nc < n_cross; nc++ ) IEEE_Swap__FLT( &bias->corrpar[nc] );
}
示例#14
0
static
void Sun2Intel_CLD( struct cld_sci_ol *cld )
{
     register unsigned short np;

     cld->mjd.days = byte_swap_32( cld->mjd.days );
     cld->mjd.secnd = byte_swap_u32( cld->mjd.secnd );
     cld->mjd.musec = byte_swap_u32( cld->mjd.musec );
     cld->dsrlen = byte_swap_u32( cld->dsrlen );
     cld->intg_time = byte_swap_u16( cld->intg_time );

     IEEE_Swap__FLT( &cld->surfpress );
     IEEE_Swap__FLT( &cld->cloudfrac );
     IEEE_Swap__FLT( &cld->errcldfrac );
     cld->numpmdpix = byte_swap_u16( cld->numpmdpix );
     cld->fullfree[0] = byte_swap_u16( cld->fullfree[0] );
     cld->fullfree[1] = byte_swap_u16( cld->fullfree[1] );
     IEEE_Swap__FLT( &cld->toppress );
     IEEE_Swap__FLT( &cld->errtoppress );
     IEEE_Swap__FLT( &cld->cldoptdepth );
     IEEE_Swap__FLT( &cld->errcldoptdep );
     cld->cloudtype = byte_swap_u16( cld->cloudtype );
     IEEE_Swap__FLT( &cld->cloudbrdf );
     IEEE_Swap__FLT( &cld->errcldbrdf );
     IEEE_Swap__FLT( &cld->effsurfrefl );
     IEEE_Swap__FLT( &cld->erreffsrefl );
     cld->cloudflag = byte_swap_u16( cld->cloudflag );
     IEEE_Swap__FLT( &cld->aai );
     IEEE_Swap__FLT( &cld->aaidiag );
     cld->aaiflag = byte_swap_u16( cld->aaiflag );
     for ( np = 0; np < cld->numaeropars; np++ )
	  IEEE_Swap__FLT( &cld->aeropars[np] );
}
示例#15
0
文件: crc.hpp 项目: 7890/osrm-backend
        void update_int32(uint32_t value) {
#if __BYTE_ORDER == __LITTLE_ENDIAN
            m_crc.process_bytes(&value, sizeof(uint32_t));
#else
            uint32_t v = byte_swap_32(value);
            m_crc.process_bytes(&v, sizeof(uint32_t));
#endif
        }
示例#16
0
int module_hash_encode (MAYBE_UNUSED const hashconfig_t *hashconfig, MAYBE_UNUSED const void *digest_buf, MAYBE_UNUSED const salt_t *salt, MAYBE_UNUSED const void *esalt_buf, MAYBE_UNUSED const void *hook_salt_buf, MAYBE_UNUSED const hashinfo_t *hash_info, char *line_buf, MAYBE_UNUSED const int line_size)
{
  const u32 *digest = (const u32 *) digest_buf;

  // we can not change anything in the original buffer, otherwise destroying sorting
  // therefore create some local buffer

  u32 tmp[8];

  tmp[0] = digest[0];
  tmp[1] = digest[1];
  tmp[2] = digest[2];
  tmp[3] = digest[3];
  tmp[4] = digest[4];
  tmp[5] = digest[5];
  tmp[6] = digest[6];
  tmp[7] = digest[7];

  if (hashconfig->opti_type & OPTI_TYPE_OPTIMIZED_KERNEL)
  {
    tmp[0] += SHA256M_A;
    tmp[1] += SHA256M_B;
    tmp[2] += SHA256M_C;
    tmp[3] += SHA256M_D;
    tmp[4] += SHA256M_E;
    tmp[5] += SHA256M_F;
    tmp[6] += SHA256M_G;
    tmp[7] += SHA256M_H;
  }

  tmp[0] = byte_swap_32 (tmp[0]);
  tmp[1] = byte_swap_32 (tmp[1]);
  tmp[2] = byte_swap_32 (tmp[2]);
  tmp[3] = byte_swap_32 (tmp[3]);
  tmp[4] = byte_swap_32 (tmp[4]);
  tmp[5] = byte_swap_32 (tmp[5]);
  tmp[6] = byte_swap_32 (tmp[6]);
  tmp[7] = byte_swap_32 (tmp[7]);

  u8 *out_buf = (u8 *) line_buf;

  u32_to_hex (tmp[0], out_buf +  0);
  u32_to_hex (tmp[1], out_buf +  8);
  u32_to_hex (tmp[2], out_buf + 16);
  u32_to_hex (tmp[3], out_buf + 24);
  u32_to_hex (tmp[4], out_buf + 32);
  u32_to_hex (tmp[5], out_buf + 40);
  u32_to_hex (tmp[6], out_buf + 48);
  u32_to_hex (tmp[7], out_buf + 56);

  const int out_len = 64;

  return out_len;
}
示例#17
0
int module_hash_encode (MAYBE_UNUSED const hashconfig_t *hashconfig, MAYBE_UNUSED const void *digest_buf, MAYBE_UNUSED const salt_t *salt, MAYBE_UNUSED const void *esalt_buf, MAYBE_UNUSED const void *hook_salt_buf, MAYBE_UNUSED const hashinfo_t *hash_info, char *line_buf, MAYBE_UNUSED const int line_size)
{
  const u32 *digest = (const u32 *) digest_buf;

  char tmp_salt[SALT_MAX * 2];

  const int salt_len = generic_salt_encode (hashconfig, (const u8 *) salt->salt_buf, (const int) salt->salt_len, (u8 *) tmp_salt);

  tmp_salt[salt_len] = 0;

  u32 tmp[5];

  tmp[0] = digest[0];
  tmp[1] = digest[1];
  tmp[2] = digest[2];
  tmp[3] = digest[3];
  tmp[4] = digest[4];

  if (hashconfig->opti_type & OPTI_TYPE_OPTIMIZED_KERNEL)
  {
    tmp[0] += SHA1M_A;
    tmp[1] += SHA1M_B;
    tmp[2] += SHA1M_C;
    tmp[3] += SHA1M_D;
    tmp[4] += SHA1M_E;
  }

  tmp[0] = byte_swap_32 (tmp[0]);
  tmp[1] = byte_swap_32 (tmp[1]);
  tmp[2] = byte_swap_32 (tmp[2]);
  tmp[3] = byte_swap_32 (tmp[3]);
  tmp[4] = byte_swap_32 (tmp[4]);

  char ptr_plain[32];

  base64_encode (int_to_base64, (const u8 *) tmp, 20, (u8 *) ptr_plain);

  ptr_plain[27] = 0;

  const int line_len = snprintf (line_buf, line_size, "%s*0*%s*%s", SIGNATURE_EPISERVER, tmp_salt, ptr_plain);

  return line_len;
}
示例#18
0
static void serpent_decrypt(serpent_ctx* ctx, serpent_word32* plainText, const serpent_word32* cipherText)
{
	serpent_word32 storage[4], next[4];
	int round = 32;
#if BYTE_ORDER == BIG_ENDIAN
	next[0] = byte_swap_32(cipherText[0]); next[1] = byte_swap_32(cipherText[1]); next[2] = byte_swap_32(cipherText[2]); next[3] = byte_swap_32(cipherText[3]);
#else
	next[0] = cipherText[0]; next[1] = cipherText[1]; next[2] = cipherText[2]; next[3] = cipherText[3];
#endif

	ROUND_FIRST_INVERSE(7, ctx->subkey, next, storage);
	for(round = 30; round >= 0; round--)
		ROUND_INVERSE(round % 8, ctx->subkey, storage, next);

#if BYTE_ORDER == BIG_ENDIAN
plainText[0] = byte_swap_32(next[0]); plainText[1] = byte_swap_32(next[1]);	plainText[2] = byte_swap_32(next[2]); plainText[3] = byte_swap_32(next[3]);	
#else
plainText[0] = next[0]; plainText[1] = next[1];	plainText[2] = next[2]; plainText[3] = next[3];
#endif
}
示例#19
0
int module_hash_decode (MAYBE_UNUSED const hashconfig_t *hashconfig, MAYBE_UNUSED void *digest_buf, MAYBE_UNUSED salt_t *salt, MAYBE_UNUSED void *esalt_buf, MAYBE_UNUSED void *hook_salt_buf, MAYBE_UNUSED hashinfo_t *hash_info, const char *line_buf, MAYBE_UNUSED const int line_len)
{
  u32 *digest = (u32 *) digest_buf;

  token_t token;

  token.token_cnt  = 1;

  token.len_min[0] = 64;
  token.len_max[0] = 64;
  token.attr[0]    = TOKEN_ATTR_VERIFY_LENGTH
                   | TOKEN_ATTR_VERIFY_HEX;

  const int rc_tokenizer = input_tokenizer ((const u8 *) line_buf, line_len, &token);

  if (rc_tokenizer != PARSER_OK) return (rc_tokenizer);

  const u8 *hash_pos = token.buf[0];

  digest[0] = hex_to_u32 (hash_pos +  0);
  digest[1] = hex_to_u32 (hash_pos +  8);
  digest[2] = hex_to_u32 (hash_pos + 16);
  digest[3] = hex_to_u32 (hash_pos + 24);
  digest[4] = hex_to_u32 (hash_pos + 32);
  digest[5] = hex_to_u32 (hash_pos + 40);
  digest[6] = hex_to_u32 (hash_pos + 48);
  digest[7] = hex_to_u32 (hash_pos + 56);

  digest[0] = byte_swap_32 (digest[0]);
  digest[1] = byte_swap_32 (digest[1]);
  digest[2] = byte_swap_32 (digest[2]);
  digest[3] = byte_swap_32 (digest[3]);
  digest[4] = byte_swap_32 (digest[4]);
  digest[5] = byte_swap_32 (digest[5]);
  digest[6] = byte_swap_32 (digest[6]);
  digest[7] = byte_swap_32 (digest[7]);

  if (hashconfig->opti_type & OPTI_TYPE_OPTIMIZED_KERNEL)
  {
    digest[0] -= SHA256M_A;
    digest[1] -= SHA256M_B;
    digest[2] -= SHA256M_C;
    digest[3] -= SHA256M_D;
    digest[4] -= SHA256M_E;
    digest[5] -= SHA256M_F;
    digest[6] -= SHA256M_G;
    digest[7] -= SHA256M_H;
  }

  return (PARSER_OK);
}
示例#20
0
static void serpent_encrypt(serpent_ctx* ctx, const serpent_word32* plainText, serpent_word32* cipherText)
{
	serpent_word32 storage[4], next[4];
	int round = 0;
#if BYTE_ORDER == BIG_ENDIAN
	storage[0] = byte_swap_32(plainText[0]); storage[1] = byte_swap_32(plainText[1]); storage[2] = byte_swap_32(plainText[2]); storage[3] = byte_swap_32(plainText[3]);
#else
	storage[0] = plainText[0]; storage[1] = plainText[1]; storage[2] = plainText[2]; storage[3] = plainText[3];
#endif
	
	for(round = 0; round < 31; round++)
		ROUND(round % 8, ctx->subkey, storage, next);

	//Final Round
	ROUND_LAST(7, ctx->subkey, storage, next);
#if BYTE_ORDER == BIG_ENDIAN
	cipherText[0] = byte_swap_32(next[0]); cipherText[1] = byte_swap_32(next[1]);	cipherText[2] = byte_swap_32(next[2]);	cipherText[3] = byte_swap_32(next[3]);
#else
	cipherText[0] = next[0]; cipherText[1] = next[1];	cipherText[2] = next[2];	cipherText[3] = next[3];
#endif	
}
示例#21
0
int module_hash_encode (MAYBE_UNUSED const hashconfig_t *hashconfig, MAYBE_UNUSED const void *digest_buf, MAYBE_UNUSED const salt_t *salt, MAYBE_UNUSED const void *esalt_buf, MAYBE_UNUSED const void *hook_salt_buf, MAYBE_UNUSED const hashinfo_t *hash_info, char *line_buf, MAYBE_UNUSED const int line_size)
{
  const apple_secure_notes_t *apple_secure_notes = (const apple_secure_notes_t *) esalt_buf;

  const int line_len = snprintf (line_buf, line_size, "%s%u$16$%08x%08x%08x%08x$%u$%08x%08x%08x%08x%08x%08x",
    SIGNATURE_FILEVAULT2,
    apple_secure_notes->Z_PK,
    byte_swap_32 (apple_secure_notes->ZCRYPTOSALT[0]),
    byte_swap_32 (apple_secure_notes->ZCRYPTOSALT[1]),
    byte_swap_32 (apple_secure_notes->ZCRYPTOSALT[2]),
    byte_swap_32 (apple_secure_notes->ZCRYPTOSALT[3]),
    apple_secure_notes->ZCRYPTOITERATIONCOUNT,
    byte_swap_32 (apple_secure_notes->ZCRYPTOWRAPPEDKEY[0]),
    byte_swap_32 (apple_secure_notes->ZCRYPTOWRAPPEDKEY[1]),
    byte_swap_32 (apple_secure_notes->ZCRYPTOWRAPPEDKEY[2]),
    byte_swap_32 (apple_secure_notes->ZCRYPTOWRAPPEDKEY[3]),
    byte_swap_32 (apple_secure_notes->ZCRYPTOWRAPPEDKEY[4]),
    byte_swap_32 (apple_secure_notes->ZCRYPTOWRAPPEDKEY[5]));

  return line_len;
}
示例#22
0
int module_hash_encode (MAYBE_UNUSED const hashconfig_t *hashconfig, MAYBE_UNUSED const void *digest_buf, MAYBE_UNUSED const salt_t *salt, MAYBE_UNUSED const void *esalt_buf, MAYBE_UNUSED const void *hook_salt_buf, MAYBE_UNUSED const hashinfo_t *hash_info, char *line_buf, MAYBE_UNUSED const int line_size)
{
  const u32 *digest = (const u32 *) digest_buf;

  char buf[52] = { 0 };

  // salt

  memcpy (buf + 0, salt->salt_buf, 16);

  buf[3] -= -4;

  // iteration

  snprintf (buf + 16, 11, "%010u", salt->salt_iter + 1);

  // chars

  buf[26] = salt->salt_buf_pc[0]; // not a bug
  buf[27] = salt->salt_buf_pc[1]; // not a bug

  // digest

  u32 tmp[2];

  tmp[0] = byte_swap_32 (digest[0]);
  tmp[1] = byte_swap_32 (digest[1]);

  memcpy (buf + 28, tmp, 8);

  char tmp_buf[64];

  const int tmp_len = base64_encode (int_to_lotus64, (const u8 *) buf, 36, (u8 *) tmp_buf);

  tmp_buf[tmp_len] = 0;

  const int line_len = snprintf (line_buf, line_size, "(H%s)", tmp_buf);

  return line_len;
}
示例#23
0
int module_hash_encode (MAYBE_UNUSED const hashconfig_t *hashconfig, MAYBE_UNUSED const void *digest_buf, MAYBE_UNUSED const salt_t *salt, MAYBE_UNUSED const void *esalt_buf, MAYBE_UNUSED const void *hook_salt_buf, MAYBE_UNUSED const hashinfo_t *hash_info, char *line_buf, MAYBE_UNUSED const int line_size)
{
  const odf11_t *odf11 = (const odf11_t *) esalt_buf;

  int out_len = snprintf (line_buf, line_size, "%s*0*0*%d*16*%08x%08x%08x%08x%08x*8*%08x%08x*16*%08x%08x%08x%08x*0*",
    SIGNATURE_ODF,
    odf11->iterations,
    byte_swap_32 (odf11->checksum[0]),
    byte_swap_32 (odf11->checksum[1]),
    byte_swap_32 (odf11->checksum[2]),
    byte_swap_32 (odf11->checksum[3]),
    byte_swap_32 (odf11->checksum[4]),
    odf11->iv[0],
    odf11->iv[1],
    salt->salt_buf[0],
    salt->salt_buf[1],
    salt->salt_buf[2],
    salt->salt_buf[3]);

  u8 *out_buf = (u8 *) line_buf;

  for (int i = 0; i < 256; i++)
  {
    u32_to_hex (byte_swap_32 (odf11->encrypted_data[i]), out_buf + out_len); out_len += 8;
  }

  return out_len;
}
示例#24
0
int module_hash_encode (MAYBE_UNUSED const hashconfig_t *hashconfig, MAYBE_UNUSED const void *digest_buf, MAYBE_UNUSED const salt_t *salt, MAYBE_UNUSED const void *esalt_buf, MAYBE_UNUSED const void *hook_salt_buf, MAYBE_UNUSED const hashinfo_t *hash_info, char *line_buf, MAYBE_UNUSED const int line_size)
{
  const agilekey_t *agilekey = (const agilekey_t *) esalt_buf;

  int line_len = snprintf (line_buf, line_size, "%u:%08x%08x:", salt->salt_iter + 1, byte_swap_32 (salt->salt_buf[0]), byte_swap_32 (salt->salt_buf[1]));

  for (u32 i = 0; i < 1040; i++)
  {
    line_len += snprintf (line_buf + line_len, line_size - line_len, "%02x", agilekey->cipher[i]);
  }

  return line_len;
}
示例#25
0
int module_hash_decode (MAYBE_UNUSED const hashconfig_t *hashconfig, MAYBE_UNUSED void *digest_buf, MAYBE_UNUSED salt_t *salt, MAYBE_UNUSED void *esalt_buf, MAYBE_UNUSED void *hook_salt_buf, MAYBE_UNUSED hashinfo_t *hash_info, const char *line_buf, MAYBE_UNUSED const int line_len)
{
  u32 *digest = (u32 *) digest_buf;

  token_t token;

  token.token_cnt = 1;

  token.len[0]  = 43;
  token.attr[0] = TOKEN_ATTR_FIXED_LENGTH
                | TOKEN_ATTR_VERIFY_BASE64B;

  const int rc_tokenizer = input_tokenizer ((const u8 *) line_buf, line_len, &token);

  if (rc_tokenizer != PARSER_OK) return (rc_tokenizer);

  const u8 *hash_pos = token.buf[0];
  const int hash_len = token.len[0];

  u8 tmp_buf[100] = { 0 };

  base64_decode (itoa64_to_int, (const u8 *) hash_pos, hash_len, tmp_buf);

  memcpy (digest, tmp_buf, 32);

  digest[0] = byte_swap_32 (digest[0]);
  digest[1] = byte_swap_32 (digest[1]);
  digest[2] = byte_swap_32 (digest[2]);
  digest[3] = byte_swap_32 (digest[3]);
  digest[4] = byte_swap_32 (digest[4]);
  digest[5] = byte_swap_32 (digest[5]);
  digest[6] = byte_swap_32 (digest[6]);
  digest[7] = byte_swap_32 (digest[7]);

  if (hashconfig->opti_type & OPTI_TYPE_OPTIMIZED_KERNEL)
  {
    digest[0] -= SHA256M_A;
    digest[1] -= SHA256M_B;
    digest[2] -= SHA256M_C;
    digest[3] -= SHA256M_D;
    digest[4] -= SHA256M_E;
    digest[5] -= SHA256M_F;
    digest[6] -= SHA256M_G;
    digest[7] -= SHA256M_H;
  }

  return (PARSER_OK);
}
示例#26
0
int module_hash_encode (MAYBE_UNUSED const hashconfig_t *hashconfig, MAYBE_UNUSED const void *digest_buf, MAYBE_UNUSED const salt_t *salt, MAYBE_UNUSED const void *esalt_buf, MAYBE_UNUSED const void *hook_salt_buf, MAYBE_UNUSED const hashinfo_t *hash_info, char *line_buf, MAYBE_UNUSED const int line_size)
{
  const u32 *digest = (const u32 *) digest_buf;

  // we can not change anything in the original buffer, otherwise destroying sorting
  // therefore create some local buffer

  u32 tmp[5];

  tmp[0] = digest[0];
  tmp[1] = digest[1];
  tmp[2] = digest[2];
  tmp[3] = digest[3];
  tmp[4] = digest[4];

  if (hashconfig->opti_type & OPTI_TYPE_OPTIMIZED_KERNEL)
  {
    tmp[0] += SHA1M_A;
    tmp[1] += SHA1M_B;
    tmp[2] += SHA1M_C;
    tmp[3] += SHA1M_D;
    tmp[4] += SHA1M_E;
  }

  tmp[0] = byte_swap_32 (tmp[0]);
  tmp[1] = byte_swap_32 (tmp[1]);
  tmp[2] = byte_swap_32 (tmp[2]);
  tmp[3] = byte_swap_32 (tmp[3]);
  tmp[4] = byte_swap_32 (tmp[4]);

  u8 ptr_plain[100] = { 0 };

  base64_encode (int_to_base64, (const u8 *) tmp, 20, (u8 *) ptr_plain);

  const int out_len = snprintf (line_buf, line_size, "{SHA}%s", (char *) ptr_plain);

  return out_len;
}
示例#27
0
static
void Sun2Intel_GEO( struct geo_scia *geo )
{
     register unsigned short ni;

     geo->mjd.days = byte_swap_32( geo->mjd.days );
     geo->mjd.secnd = byte_swap_u32( geo->mjd.secnd );
     geo->mjd.musec = byte_swap_u32( geo->mjd.musec );
     geo->intg_time = byte_swap_u16( geo->intg_time );
     IEEE_Swap__FLT( &geo->sat_h );
     IEEE_Swap__FLT( &geo->earth_rad );
     for ( ni = 0; ni < 3; ni++ ) {
	  IEEE_Swap__FLT( &geo->sun_zen_ang[ni] );
	  IEEE_Swap__FLT( &geo->los_zen_ang[ni] );
	  IEEE_Swap__FLT( &geo->rel_azi_ang[ni] );
     }
     for ( ni = 0; ni < 4; ni++ ) {
	  geo->corner[ni].lon = byte_swap_32( geo->corner[ni].lon );
	  geo->corner[ni].lat = byte_swap_32( geo->corner[ni].lat );
     }
     geo->center.lon = byte_swap_32( geo->center.lon );
     geo->center.lat = byte_swap_32( geo->center.lat );
}
示例#28
0
int module_hash_encode (MAYBE_UNUSED const hashconfig_t *hashconfig, MAYBE_UNUSED const void *digest_buf, MAYBE_UNUSED const salt_t *salt, MAYBE_UNUSED const void *esalt_buf, MAYBE_UNUSED const void *hook_salt_buf, MAYBE_UNUSED const hashinfo_t *hash_info, char *line_buf, MAYBE_UNUSED const int line_size)
{
  const u32 *digest = (const u32 *) digest_buf;

  u32 tmp[5];

  tmp[0] = digest[0];
  tmp[1] = digest[1];
  tmp[2] = digest[2];
  tmp[3] = digest[3];
  tmp[4] = digest[4];

  if (hashconfig->opti_type & OPTI_TYPE_OPTIMIZED_KERNEL)
  {
    tmp[0] += SHA1M_A;
    tmp[1] += SHA1M_B;
    tmp[2] += SHA1M_C;
    tmp[3] += SHA1M_D;
    tmp[4] += SHA1M_E;
  }

  u32 tmp_salt[3];

  tmp_salt[0] = byte_swap_32 (salt->salt_buf[0]);
  tmp_salt[1] = byte_swap_32 (salt->salt_buf[1]);
  tmp_salt[2] = 0;

  const int line_len = snprintf (line_buf, line_size, "1%s%08x%08x%08x%08x%08x",
    (unsigned char *) tmp_salt,
    tmp[0],
    tmp[1],
    tmp[2],
    tmp[3],
    tmp[4]);

  return line_len;
}
示例#29
0
int module_hash_encode (MAYBE_UNUSED const hashconfig_t *hashconfig, MAYBE_UNUSED const void *digest_buf, MAYBE_UNUSED const salt_t *salt, MAYBE_UNUSED const void *esalt_buf, MAYBE_UNUSED const void *hook_salt_buf, MAYBE_UNUSED const hashinfo_t *hash_info, char *line_buf, MAYBE_UNUSED const int line_size)
{
  const u32 *digest = (const u32 *) digest_buf;
    // the encoder is a bit too intelligent, it expects the input data in the wrong BOM

  u32 tmp[8];

  tmp[0] = digest[0];
  tmp[1] = digest[1];
  tmp[2] = digest[2];
  tmp[3] = digest[3];
  tmp[4] = digest[4];
  tmp[5] = digest[5];
  tmp[6] = digest[6];
  tmp[7] = digest[7];

  if (hashconfig->opti_type & OPTI_TYPE_OPTIMIZED_KERNEL)
  {
    tmp[0] += SHA256M_A;
    tmp[1] += SHA256M_B;
    tmp[2] += SHA256M_C;
    tmp[3] += SHA256M_D;
    tmp[4] += SHA256M_E;
    tmp[5] += SHA256M_F;
    tmp[6] += SHA256M_G;
    tmp[7] += SHA256M_H;
  }

  tmp[0] = byte_swap_32 (tmp[0]);
  tmp[1] = byte_swap_32 (tmp[1]);
  tmp[2] = byte_swap_32 (tmp[2]);
  tmp[3] = byte_swap_32 (tmp[3]);
  tmp[4] = byte_swap_32 (tmp[4]);
  tmp[5] = byte_swap_32 (tmp[5]);
  tmp[6] = byte_swap_32 (tmp[6]);
  tmp[7] = byte_swap_32 (tmp[7]);

  char ptr_plain[64];

  base64_encode (int_to_itoa64, (const u8 *) tmp, 32, (u8 *) ptr_plain);

  ptr_plain[43] = 0;

  return snprintf (line_buf, line_size, "%s", ptr_plain);
}
示例#30
0
static
void Sun2Intel_PPGN( struct ppgn_scia *ppgn )
{
     register int ni = 0;

     ppgn->mjd.days = byte_swap_32( ppgn->mjd.days );
     ppgn->mjd.secnd = byte_swap_u32( ppgn->mjd.secnd );
     ppgn->mjd.musec = byte_swap_u32( ppgn->mjd.musec );
     do {
	  IEEE_Swap__FLT( &ppgn->gain_fact[ni] );
	  IEEE_Swap__FLT( &ppgn->etalon_fact[ni] );
	  IEEE_Swap__FLT( &ppgn->etalon_resid[ni] );
	  IEEE_Swap__FLT( &ppgn->avg_wls_spec[ni] );
	  IEEE_Swap__FLT( &ppgn->sd_wls_spec[ni] );
     } while ( ++ni < (SCIENCE_PIXELS) );
}