source: rtems-libbsd/freebsd/sys/crypto/blowfish/bf_enc.c @ f244de9

4.1155-freebsd-126-freebsd-12freebsd-9.3
Last change on this file since f244de9 was f244de9, checked in by Sebastian Huber <sebastian.huber@…>, on 11/06/13 at 07:56:38

Rename rtems-bsd-config.h

Rename rtems-bsd-config.h in rtems-bsd-kernel-space.h.

  • Property mode set to 100644
File size: 5.3 KB
Line 
1#include <machine/rtems-bsd-kernel-space.h>
2
3/*      $KAME: bf_enc.c,v 1.7 2002/02/27 01:33:59 itojun Exp $  */
4
5/* crypto/bf/bf_enc.c */
6
7/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
8 * All rights reserved.
9 *
10 * This package is an SSL implementation written
11 * by Eric Young (eay@cryptsoft.com).
12 * The implementation was written so as to conform with Netscapes SSL.
13 *
14 * This library is free for commercial and non-commercial use as long as
15 * the following conditions are aheared to.  The following conditions
16 * apply to all code found in this distribution, be it the RC4, RSA,
17 * lhash, DES, etc., code; not just the SSL code.  The SSL documentation
18 * included with this distribution is covered by the same copyright terms
19 * except that the holder is Tim Hudson (tjh@cryptsoft.com).
20 *
21 * Copyright remains Eric Young's, and as such any Copyright notices in
22 * the code are not to be removed.
23 * If this package is used in a product, Eric Young should be given attribution
24 * as the author of the parts of the library used.
25 * This can be in the form of a textual message at program startup or
26 * in documentation (online or textual) provided with the package.
27 *
28 * Redistribution and use in source and binary forms, with or without
29 * modification, are permitted provided that the following conditions
30 * are met:
31 * 1. Redistributions of source code must retain the copyright
32 *    notice, this list of conditions and the following disclaimer.
33 * 2. Redistributions in binary form must reproduce the above copyright
34 *    notice, this list of conditions and the following disclaimer in the
35 *    documentation and/or other materials provided with the distribution.
36 * 3. All advertising materials mentioning features or use of this software
37 *    must display the following acknowledgement:
38 *    "This product includes cryptographic software written by
39 *     Eric Young (eay@cryptsoft.com)"
40 *    The word 'cryptographic' can be left out if the rouines from the library
41 *    being used are not cryptographic related :-).
42 * 4. If you include any Windows specific code (or a derivative thereof) from
43 *    the apps directory (application code) you must include an acknowledgement:
44 *    "This product includes software written by Tim Hudson (tjh@cryptsoft.com)"
45 *
46 * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND
47 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
48 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
49 * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
50 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
51 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
52 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
53 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
54 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
55 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
56 * SUCH DAMAGE.
57 *
58 * The licence and distribution terms for any publically available version or
59 * derivative of this code cannot be changed.  i.e. this code cannot simply be
60 * copied and put under another distribution licence
61 * [including the GNU Public Licence.]
62 */
63
64#include <sys/cdefs.h>
65__FBSDID("$FreeBSD$");
66
67#include <rtems/bsd/sys/types.h>
68#include <crypto/blowfish/blowfish.h>
69#include <crypto/blowfish/bf_locl.h>
70
71/* Blowfish as implemented from 'Blowfish: Springer-Verlag paper'
72 * (From LECTURE NOTES IN COIMPUTER SCIENCE 809, FAST SOFTWARE ENCRYPTION,
73 * CAMBRIDGE SECURITY WORKSHOP, CAMBRIDGE, U.K., DECEMBER 9-11, 1993)
74 */
75
76#if (BF_ROUNDS != 16) && (BF_ROUNDS != 20)
77If you set BF_ROUNDS to some value other than 16 or 20, you will have
78to modify the code.
79#endif
80
81/* XXX "data" is host endian */
82void
83BF_encrypt(data, key)
84        BF_LONG *data;
85        BF_KEY *key;
86{
87        register BF_LONG l, r, *p, *s;
88
89        p = key->P;
90        s= &key->S[0];
91        l = data[0];
92        r = data[1];
93
94        l^=p[0];
95        BF_ENC(r, l, s, p[ 1]);
96        BF_ENC(l, r, s, p[ 2]);
97        BF_ENC(r, l, s, p[ 3]);
98        BF_ENC(l, r, s, p[ 4]);
99        BF_ENC(r, l, s, p[ 5]);
100        BF_ENC(l, r, s, p[ 6]);
101        BF_ENC(r, l, s, p[ 7]);
102        BF_ENC(l, r, s, p[ 8]);
103        BF_ENC(r, l, s, p[ 9]);
104        BF_ENC(l, r, s, p[10]);
105        BF_ENC(r, l, s, p[11]);
106        BF_ENC(l, r, s, p[12]);
107        BF_ENC(r, l, s, p[13]);
108        BF_ENC(l, r, s, p[14]);
109        BF_ENC(r, l, s, p[15]);
110        BF_ENC(l, r, s, p[16]);
111#if BF_ROUNDS == 20
112        BF_ENC(r, l, s, p[17]);
113        BF_ENC(l, r, s, p[18]);
114        BF_ENC(r, l, s, p[19]);
115        BF_ENC(l, r, s, p[20]);
116#endif
117        r ^= p[BF_ROUNDS + 1];
118
119        data[1] = l & 0xffffffff;
120        data[0] = r & 0xffffffff;
121}
122
123/* XXX "data" is host endian */
124void
125BF_decrypt(data, key)
126        BF_LONG *data;
127        BF_KEY *key;
128{
129        register BF_LONG l, r, *p, *s;
130
131        p = key->P;
132        s= &key->S[0];
133        l = data[0];
134        r = data[1];
135
136        l ^= p[BF_ROUNDS + 1];
137#if BF_ROUNDS == 20
138        BF_ENC(r, l, s, p[20]);
139        BF_ENC(l, r, s, p[19]);
140        BF_ENC(r, l, s, p[18]);
141        BF_ENC(l, r, s, p[17]);
142#endif
143        BF_ENC(r, l, s, p[16]);
144        BF_ENC(l, r, s, p[15]);
145        BF_ENC(r, l, s, p[14]);
146        BF_ENC(l, r, s, p[13]);
147        BF_ENC(r, l, s, p[12]);
148        BF_ENC(l, r, s, p[11]);
149        BF_ENC(r, l, s, p[10]);
150        BF_ENC(l, r, s, p[ 9]);
151        BF_ENC(r, l, s, p[ 8]);
152        BF_ENC(l, r, s, p[ 7]);
153        BF_ENC(r, l, s, p[ 6]);
154        BF_ENC(l, r, s, p[ 5]);
155        BF_ENC(r, l, s, p[ 4]);
156        BF_ENC(l, r, s, p[ 3]);
157        BF_ENC(r, l, s, p[ 2]);
158        BF_ENC(l, r, s, p[ 1]);
159        r ^= p[0];
160
161        data[1] = l & 0xffffffff;
162        data[0] = r & 0xffffffff;
163}
Note: See TracBrowser for help on using the repository browser.