]>
git.ipfire.org Git - thirdparty/openssl.git/blob - crypto/idea/i_skey.c
2 * Copyright 1995-2020 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
11 * IDEA low level APIs are deprecated for public use, but still ok for internal
12 * use where we're using them to implement the higher level EVP interface, as is
15 #include "internal/deprecated.h"
17 #include <openssl/idea.h>
18 #include "idea_local.h"
20 static IDEA_INT
inverse(unsigned int xin
);
21 void IDEA_set_encrypt_key(const unsigned char *key
, IDEA_KEY_SCHEDULE
*ks
)
24 register IDEA_INT
*kt
, *kf
, r0
, r1
, r2
;
26 kt
= &(ks
->data
[0][0]);
38 for (i
= 0; i
< 6; i
++) {
41 *(kt
++) = ((r2
<< 9) | (r1
>> 7)) & 0xffff;
43 *(kt
++) = ((r1
<< 9) | (r0
>> 7)) & 0xffff;
45 *(kt
++) = ((r0
<< 9) | (r1
>> 7)) & 0xffff;
47 *(kt
++) = ((r1
<< 9) | (r0
>> 7)) & 0xffff;
49 *(kt
++) = ((r0
<< 9) | (r1
>> 7)) & 0xffff;
51 *(kt
++) = ((r1
<< 9) | (r0
>> 7)) & 0xffff;
55 *(kt
++) = ((r0
<< 9) | (r1
>> 7)) & 0xffff;
56 *(kt
++) = ((r1
<< 9) | (r2
>> 7)) & 0xffff;
61 void IDEA_set_decrypt_key(IDEA_KEY_SCHEDULE
*ek
, IDEA_KEY_SCHEDULE
*dk
)
64 register IDEA_INT
*fp
, *tp
, t
;
66 tp
= &(dk
->data
[0][0]);
67 fp
= &(ek
->data
[8][0]);
68 for (r
= 0; r
< 9; r
++) {
69 *(tp
++) = inverse(fp
[0]);
70 *(tp
++) = ((int)(0x10000L
- fp
[2]) & 0xffff);
71 *(tp
++) = ((int)(0x10000L
- fp
[1]) & 0xffff);
72 *(tp
++) = inverse(fp
[3]);
80 tp
= &(dk
->data
[0][0]);
90 /* taken directly from the 'paper' I'll have a look at it later */
91 static IDEA_INT
inverse(unsigned int xin
)
93 long n1
, n2
, q
, r
, b1
, b2
, t
;