]>
git.ipfire.org Git - thirdparty/openssl.git/blob - crypto/idea/i_skey.c
2 * Copyright 1995-2016 The OpenSSL Project Authors. All Rights Reserved.
4 * Licensed under the Apache License 2.0 (the "License"). You may not use
5 * this file except in compliance with the License. You can obtain a copy
6 * in the file LICENSE in the source distribution or at
7 * https://www.openssl.org/source/license.html
10 #include <openssl/idea.h>
11 #include "idea_local.h"
13 static IDEA_INT
inverse(unsigned int xin
);
14 void IDEA_set_encrypt_key(const unsigned char *key
, IDEA_KEY_SCHEDULE
*ks
)
17 register IDEA_INT
*kt
, *kf
, r0
, r1
, r2
;
19 kt
= &(ks
->data
[0][0]);
31 for (i
= 0; i
< 6; i
++) {
34 *(kt
++) = ((r2
<< 9) | (r1
>> 7)) & 0xffff;
36 *(kt
++) = ((r1
<< 9) | (r0
>> 7)) & 0xffff;
38 *(kt
++) = ((r0
<< 9) | (r1
>> 7)) & 0xffff;
40 *(kt
++) = ((r1
<< 9) | (r0
>> 7)) & 0xffff;
42 *(kt
++) = ((r0
<< 9) | (r1
>> 7)) & 0xffff;
44 *(kt
++) = ((r1
<< 9) | (r0
>> 7)) & 0xffff;
48 *(kt
++) = ((r0
<< 9) | (r1
>> 7)) & 0xffff;
49 *(kt
++) = ((r1
<< 9) | (r2
>> 7)) & 0xffff;
54 void IDEA_set_decrypt_key(IDEA_KEY_SCHEDULE
*ek
, IDEA_KEY_SCHEDULE
*dk
)
57 register IDEA_INT
*fp
, *tp
, t
;
59 tp
= &(dk
->data
[0][0]);
60 fp
= &(ek
->data
[8][0]);
61 for (r
= 0; r
< 9; r
++) {
62 *(tp
++) = inverse(fp
[0]);
63 *(tp
++) = ((int)(0x10000L
- fp
[2]) & 0xffff);
64 *(tp
++) = ((int)(0x10000L
- fp
[1]) & 0xffff);
65 *(tp
++) = inverse(fp
[3]);
73 tp
= &(dk
->data
[0][0]);
83 /* taken directly from the 'paper' I'll have a look at it later */
84 static IDEA_INT
inverse(unsigned int xin
)
86 long n1
, n2
, q
, r
, b1
, b2
, t
;