40 *
41 * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND
42 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
43 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
44 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
45 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
46 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
47 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
48 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
49 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
50 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
51 * SUCH DAMAGE.
52 *
53 * The licence and distribution terms for any publically available version or
54 * derivative of this code cannot be changed. i.e. this code cannot simply be
55 * copied and put under another distribution licence
56 * [including the GNU Public Licence.]
57 */
58
59 #include <openssl/cast.h>
60 #include "cast_lcl.h"
61
62 void CAST_encrypt(CAST_LONG *data, const CAST_KEY *key)
63 {
64 register CAST_LONG l,r,t;
65 const register CAST_LONG *k;
66
67 k= &(key->data[0]);
68 l=data[0];
69 r=data[1];
70
71 E_CAST( 0,k,l,r,+,^,-);
72 E_CAST( 1,k,r,l,^,-,+);
73 E_CAST( 2,k,l,r,-,+,^);
74 E_CAST( 3,k,r,l,+,^,-);
75 E_CAST( 4,k,l,r,^,-,+);
76 E_CAST( 5,k,r,l,-,+,^);
77 E_CAST( 6,k,l,r,+,^,-);
78 E_CAST( 7,k,r,l,^,-,+);
79 E_CAST( 8,k,l,r,-,+,^);
80 E_CAST( 9,k,r,l,+,^,-);
81 E_CAST(10,k,l,r,^,-,+);
82 E_CAST(11,k,r,l,-,+,^);
83 if(!key->short_key)
84 {
85 E_CAST(12,k,l,r,+,^,-);
86 E_CAST(13,k,r,l,^,-,+);
87 E_CAST(14,k,l,r,-,+,^);
88 E_CAST(15,k,r,l,+,^,-);
89 }
90
91 data[1]=l&0xffffffffL;
92 data[0]=r&0xffffffffL;
93 }
94
95 void CAST_decrypt(CAST_LONG *data, const CAST_KEY *key)
96 {
97 register CAST_LONG l,r,t;
98 const register CAST_LONG *k;
99
100 k= &(key->data[0]);
101 l=data[0];
102 r=data[1];
103
104 if(!key->short_key)
105 {
106 E_CAST(15,k,l,r,+,^,-);
107 E_CAST(14,k,r,l,-,+,^);
108 E_CAST(13,k,l,r,^,-,+);
109 E_CAST(12,k,r,l,+,^,-);
110 }
111 E_CAST(11,k,l,r,-,+,^);
112 E_CAST(10,k,r,l,^,-,+);
113 E_CAST( 9,k,l,r,+,^,-);
114 E_CAST( 8,k,r,l,-,+,^);
115 E_CAST( 7,k,l,r,^,-,+);
116 E_CAST( 6,k,r,l,+,^,-);
117 E_CAST( 5,k,l,r,-,+,^);
118 E_CAST( 4,k,r,l,^,-,+);
|
40 *
41 * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND
42 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
43 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
44 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
45 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
46 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
47 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
48 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
49 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
50 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
51 * SUCH DAMAGE.
52 *
53 * The licence and distribution terms for any publically available version or
54 * derivative of this code cannot be changed. i.e. this code cannot simply be
55 * copied and put under another distribution licence
56 * [including the GNU Public Licence.]
57 */
58
59 #include <openssl/cast.h>
60 #include <cast_lcl.h>
61
62 void CAST_encrypt(CAST_LONG *data, const CAST_KEY *key)
63 {
64 register CAST_LONG l,r,t;
65 register const CAST_LONG *k;
66
67 k= &(key->data[0]);
68 l=data[0];
69 r=data[1];
70
71 E_CAST( 0,k,l,r,+,^,-);
72 E_CAST( 1,k,r,l,^,-,+);
73 E_CAST( 2,k,l,r,-,+,^);
74 E_CAST( 3,k,r,l,+,^,-);
75 E_CAST( 4,k,l,r,^,-,+);
76 E_CAST( 5,k,r,l,-,+,^);
77 E_CAST( 6,k,l,r,+,^,-);
78 E_CAST( 7,k,r,l,^,-,+);
79 E_CAST( 8,k,l,r,-,+,^);
80 E_CAST( 9,k,r,l,+,^,-);
81 E_CAST(10,k,l,r,^,-,+);
82 E_CAST(11,k,r,l,-,+,^);
83 if(!key->short_key)
84 {
85 E_CAST(12,k,l,r,+,^,-);
86 E_CAST(13,k,r,l,^,-,+);
87 E_CAST(14,k,l,r,-,+,^);
88 E_CAST(15,k,r,l,+,^,-);
89 }
90
91 data[1]=l&0xffffffffL;
92 data[0]=r&0xffffffffL;
93 }
94
95 void CAST_decrypt(CAST_LONG *data, const CAST_KEY *key)
96 {
97 register CAST_LONG l,r,t;
98 register const CAST_LONG *k;
99
100 k= &(key->data[0]);
101 l=data[0];
102 r=data[1];
103
104 if(!key->short_key)
105 {
106 E_CAST(15,k,l,r,+,^,-);
107 E_CAST(14,k,r,l,-,+,^);
108 E_CAST(13,k,l,r,^,-,+);
109 E_CAST(12,k,r,l,+,^,-);
110 }
111 E_CAST(11,k,l,r,-,+,^);
112 E_CAST(10,k,r,l,^,-,+);
113 E_CAST( 9,k,l,r,+,^,-);
114 E_CAST( 8,k,r,l,-,+,^);
115 E_CAST( 7,k,l,r,^,-,+);
116 E_CAST( 6,k,r,l,+,^,-);
117 E_CAST( 5,k,l,r,-,+,^);
118 E_CAST( 4,k,r,l,^,-,+);
|