Ejemplo n.º 1
0
static void print_context(const poet_ctx_t *ctx)
{
    print128("K:   ", ctx->aes_enc[0]);
    print128("L:   ", ctx->l);
    print128("K_F: ", ctx->aes_axu[0]);
    print128("Tau: ", ctx->tau);
}
Ejemplo n.º 2
0
/*******************************************************************************
**
** Function         cmac_subkey_cont
**
** Description      This is the callback function when CIPHk(0[128]) is completed.
**
** Returns          void
**
*******************************************************************************/
static void cmac_subkey_cont(tSMP_ENC *p)
{
    UINT8 k1[BT_OCTET16_LEN], k2[BT_OCTET16_LEN];
    UINT8 *pp = p->param_buf;
    SMP_TRACE_EVENT ("cmac_subkey_cont ");
    print128(pp, (const UINT8 *)"K1 before shift");

    /* If MSB(L) = 0, then K1 = L << 1 */
    if ( (pp[BT_OCTET16_LEN - 1] & 0x80) != 0 ) {
        /* Else K1 = ( L << 1 ) (+) Rb */
        leftshift_onebit(pp, k1);
        smp_xor_128(k1, const_Rb);
    } else {
        leftshift_onebit(pp, k1);
    }

    if ( (k1[BT_OCTET16_LEN - 1] & 0x80) != 0 ) {
        /* K2 =  (K1 << 1) (+) Rb */
        leftshift_onebit(k1, k2);
        smp_xor_128(k2, const_Rb);
    } else {
        /* If MSB(K1) = 0, then K2 = K1 << 1 */
        leftshift_onebit(k1, k2);
    }

    print128(k1, (const UINT8 *)"K1");
    print128(k2, (const UINT8 *)"K2");

    cmac_prepare_last_block (k1, k2);
}
Ejemplo n.º 3
0
int test_b64to128(
  char *name,           /* function name */
  fn_b64to128 *ref,     /* reference to test against */
  fn_b64to128 *fn,      /* function to test */
  fn_u64 *nextb,        /* generator for "b" values */
  fn_u64 *nextc,        /* generator for "c" values */
  int maxerr            /* maximum error alowed */
)
{
  int64 b=0,c=0;
  uint128 refout, out;
  int d;
  int err=0;
  
  printf("Testing function: %s\n", name);
  
  do
  {
#if VERBOSE
    printf("b = %016llx\n", b);
#endif
    do
    {
      /* test the function */
      refout = (*ref)(b,c);
      out = (*fn)(b,c);
      d = (int)(out.a0-refout.a0);
      if (d<0) d=-d;
      if (out.a1!=refout.a1 ||
          out.a2!=refout.a2 ||
          out.a3!=refout.a3 ||
          d>=maxerr)
      {
        printf("FAIL %s(%016llx, %016llx)\n", name, b, c);
        printf("  out: ");
        print128(out);
        printf("\n  ref: ");
        print128(refout);
        printf("\n");
        err++;
      }
      c = (*nextc)(c);
    } while (c);
    
    b = (*nextb)(b);
  } while (b);

  return err;
}
Ejemplo n.º 4
0
int main()
{
  int8_t m[16] = {45, 37, 35, 45, 37, 35, 45, 37, 35, 45, 37, 35,  0, 0,  0, 0};
  int8_t s[16] = {-4, -4, -4, -4,  1,  1, -4, -4, -4, -4,  1,  1, -4,-4, -4, -4};

  __m128i M = _mm_load_si128((__m128i*)m);
  __m128i S = _mm_load_si128((__m128i*)s);
  __m128i zero = _mm_set1_epi32(0);

  //__m128i sum = _mm_mask_add_epi8(zero, _mm_cmpneq_epi8_mask(M, zero), S,S);
  __m128i sum = _mm_andnot_si128(_mm_cmpeq_epi8(M, zero), _mm_add_epi8(M, S));
  print128(M);
  print128(S);
  print128(sum);

  return 0;
}
Ejemplo n.º 5
0
inline std::ostream& operator<<(std::ostream& out, __m128i in)
{
	// Avoid http://gcc.gnu.org/bugzilla/show_bug.cgi?id=35414
	uint8 data[16] __attribute__ ((aligned (16)));
	_mm_store_si128((m128*)(data), in);
	print128(out, data);
	return out;
}
Ejemplo n.º 6
0
int main()
{

  //print128(dummy_cipher_eval());
  print128(mul_check());
  //print128(para_test());

  return 0;
}