hash_skinny_key_schedule1.c 2.69 KB
Newer Older
Enrico Pozzobon committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126
/******************************************************************************
 * Copyright (c) 2020, NEC Corporation.
 *
 * THIS CODE IS FURNISHED TO YOU "AS IS" WITHOUT WARRANTY OF ANY KIND.
 *
 *****************************************************************************/

/*
 * SKINNY-128-384
 *
 * T1 -> store
 * ART(TK1)
 *
 * number of rounds : 40 or 56
 */

#include "hash_skinny.h"

#define PERMUTATION_TK1()                                                         \
                                                                                  \
  /* permutation */                                                               \
                                                                                  \
    PERMUTATION(w0, w1)                                                           \
                                                                                  \
  /* store */                                                                     \
                                                                                  \
    *tk1++ = w0;                                                                  \
    *tk1++ = w1;                                                                  \
    tk1 += 2;

#ifndef ___SKINNY_LOOP

void hash_RunEncryptionKeyScheduleTK1(uint32_t *roundKeys)
{

  uint32_t *tk1;
  uint32_t t0;          // used in MACRO
  uint32_t t1;          // used in MACRO
  uint32_t t2;          // used in MACRO
  uint32_t w0;
  uint32_t w1;

  // odd

  // load master key
  w0 = roundKeys[0];
  w1 = roundKeys[1];

  // 1st round
  // not need to store

  tk1 = &roundKeys[4];

  // 3rd, ... ,15th round
  PERMUTATION_TK1();
  PERMUTATION_TK1();
  PERMUTATION_TK1();
  PERMUTATION_TK1();
  PERMUTATION_TK1();
  PERMUTATION_TK1();
  PERMUTATION_TK1();

  // even

  tk1 = &roundKeys[2];

  // load master key
  w0 = roundKeys[2];
  w1 = roundKeys[3];

  // 2nd, ... ,16th round
  PERMUTATION_TK1();
  PERMUTATION_TK1();
  PERMUTATION_TK1();
  PERMUTATION_TK1();
  PERMUTATION_TK1();
  PERMUTATION_TK1();
  PERMUTATION_TK1();
  PERMUTATION_TK1();

}

#else

void hash_RunEncryptionKeyScheduleTK1(uint32_t *roundKeys)
{

  uint32_t *tk1;
  uint32_t t0;          // used in MACRO
  uint32_t t1;          // used in MACRO
  uint32_t t2;          // used in MACRO
  uint32_t w0;
  uint32_t w1;

  // odd

  // load master key
  w0 = roundKeys[0];
  w1 = roundKeys[1];

  // 1st round
  // not need to store

  tk1 = &roundKeys[4];

  // 3rd, ... ,15th round
  for(int i=0;i<7;i++) {
    PERMUTATION_TK1();
  }

  // even

  tk1 = &roundKeys[2];

  // load master key
  w0 = roundKeys[2];
  w1 = roundKeys[3];

  // 2nd, ... ,16th round
  for(int i=0;i<8;i++) {
    PERMUTATION_TK1();
  }

}

#endif