~ubuntu-branches/ubuntu/trusty/nettle/trusty

« back to all changes in this revision

Viewing changes to camellia-crypt-internal.c

  • Committer: Package Import Robot
  • Author(s): Magnus Holmgren
  • Date: 2011-09-03 17:59:01 UTC
  • mfrom: (8.1.4 sid)
  • Revision ID: package-import@ubuntu.com-20110903175901-s07iotf0smzqshl2
New upstream bugfix release.

Show diffs side-by-side

added added

removed removed

Lines of Context:
33
33
#endif
34
34
 
35
35
#include <assert.h>
 
36
#include <limits.h>
36
37
 
37
38
#include "camellia-internal.h"
38
39
 
62
63
  (x) = ((uint64_t) __xl << 32) | __xr;         \
63
64
} while (0)
64
65
 
65
 
#define CAMELLIA_ROUNDSM(T, x, k, y) do {                       \
66
 
    uint32_t __il, __ir;                                        \
67
 
    __ir                                                        \
68
 
      = T->sp1110[(x) & 0xff]                           \
69
 
      ^ T->sp0222[((x) >> 24) & 0xff]                   \
70
 
      ^ T->sp3033[((x) >> 16) & 0xff]                   \
71
 
      ^ T->sp4404[((x) >> 8) & 0xff];                   \
72
 
    /* ir == (t6^t7^t8),(t5^t7^t8),(t5^t6^t8),(t5^t6^t7) */     \
73
 
    __il                                                        \
74
 
      = T->sp1110[ (x) >> 56]                           \
75
 
      ^ T->sp0222[((x) >> 48) & 0xff]                   \
76
 
      ^ T->sp3033[((x) >> 40) & 0xff]                   \
77
 
      ^ T->sp4404[((x) >> 32) & 0xff];                  \
 
66
#if HAVE_NATIVE_64_BIT
 
67
#define CAMELLIA_ROUNDSM(T, x, k, y) do {                       \
 
68
    uint32_t __il, __ir;                                        \
 
69
    __ir                                                        \
 
70
      = T->sp1110[(x) & 0xff]                                   \
 
71
      ^ T->sp0222[((x) >> 24) & 0xff]                           \
 
72
      ^ T->sp3033[((x) >> 16) & 0xff]                           \
 
73
      ^ T->sp4404[((x) >> 8) & 0xff];                           \
 
74
    /* ir == (t6^t7^t8),(t5^t7^t8),(t5^t6^t8),(t5^t6^t7) */     \
 
75
    __il                                                        \
 
76
      = T->sp1110[ (x) >> 56]                                   \
 
77
      ^ T->sp0222[((x) >> 48) & 0xff]                           \
 
78
      ^ T->sp3033[((x) >> 40) & 0xff]                           \
 
79
      ^ T->sp4404[((x) >> 32) & 0xff];                          \
 
80
    /* il == (t1^t3^t4),(t1^t2^t4),(t1^t2^t3),(t2^t3^t4) */     \
 
81
    __ir ^= __il;                                               \
 
82
    /* ir == (t1^t3^t4^t6^t7^t8),(t1^t2^t4^t5^t7^t8),           \
 
83
       (t1^t2^t3^t5^t6^t8),(t2^t3^t4^t5^t6^t7)                  \
 
84
       == y1,y2,y3,y4 */                                        \
 
85
    __il = ROL32(24, __il);                                     \
 
86
    /* il == (t2^t3^t4),(t1^t3^t4),(t1^t2^t4),(t1^t2^t3) */     \
 
87
    __il ^= __ir;                                               \
 
88
    /* il == (t1^t2^t6^t7^t8),(t2^t3^t5^t7^t8),                 \
 
89
       (t3^t4^t5^t6^t8),(t1^t4^t5^t6^t7)                        \
 
90
       == y5,y6,y7,y8 */                                        \
 
91
    y ^= (k);                                                   \
 
92
    y ^= ((uint64_t) __ir << 32) | __il;                        \
 
93
  } while (0)
 
94
#else /* !HAVE_NATIVE_64_BIT */
 
95
#define CAMELLIA_ROUNDSM(T, x, k, y) do {                       \
 
96
    uint32_t __il, __ir;                                        \
 
97
    __ir                                                        \
 
98
      = T->sp1110[(x) & 0xff]                                   \
 
99
      ^ T->sp0222[((x) >> 24) & 0xff]                           \
 
100
      ^ T->sp3033[((x) >> 16) & 0xff]                           \
 
101
      ^ T->sp4404[((x) >> 8) & 0xff];                           \
 
102
    /* ir == (t6^t7^t8),(t5^t7^t8),(t5^t6^t8),(t5^t6^t7) */     \
 
103
    __il                                                        \
 
104
      = T->sp1110[ (x) >> 56]                                   \
 
105
      ^ T->sp0222[((x) >> 48) & 0xff]                           \
 
106
      ^ T->sp3033[((x) >> 40) & 0xff]                           \
 
107
      ^ T->sp4404[((x) >> 32) & 0xff];                          \
78
108
    /* il == (t1^t3^t4),(t1^t2^t4),(t1^t2^t3),(t2^t3^t4) */     \
79
109
    __il ^= (k) >> 32;                                          \
80
110
    __ir ^= (k) & 0xffffffff;                                   \
81
111
    __ir ^= __il;                                               \
82
112
    /* ir == (t1^t3^t4^t6^t7^t8),(t1^t2^t4^t5^t7^t8),           \
83
 
             (t1^t2^t3^t5^t6^t8),(t2^t3^t4^t5^t6^t7)            \
84
 
          == y1,y2,y3,y4 */                                     \
 
113
       (t1^t2^t3^t5^t6^t8),(t2^t3^t4^t5^t6^t7)                  \
 
114
       == y1,y2,y3,y4 */                                        \
85
115
    __il = ROL32(24, __il);                                     \
86
116
    /* il == (t2^t3^t4),(t1^t3^t4),(t1^t2^t4),(t1^t2^t3) */     \
87
117
    __il ^= __ir;                                               \
88
118
    /* il == (t1^t2^t6^t7^t8),(t2^t3^t5^t7^t8),                 \
89
 
             (t3^t4^t5^t6^t8),(t1^t4^t5^t6^t7)                  \
90
 
          == y5,y6,y7,y8 */                                     \
 
119
       (t3^t4^t5^t6^t8),(t1^t4^t5^t6^t7)                        \
 
120
       == y5,y6,y7,y8 */                                        \
91
121
    y ^= ((uint64_t) __ir << 32) | __il;                        \
92
122
  } while (0)
 
123
#endif
93
124
 
94
125
void
95
126
_camellia_crypt(const struct camellia_ctx *ctx,