xref: /openbsd-src/sys/crypto/ecb3_enc.c (revision 6ecdaf80b8f961c3cd28021e361200301a0c4e41)
1*6ecdaf80Sbrad /*	$OpenBSD: ecb3_enc.c,v 1.3 2013/11/18 18:49:53 brad Exp $	*/
221f2d90fSderaadt 
321f2d90fSderaadt /* lib/des/ecb3_enc.c */
421f2d90fSderaadt /* Copyright (C) 1995 Eric Young (eay@mincom.oz.au)
521f2d90fSderaadt  * All rights reserved.
621f2d90fSderaadt  *
721f2d90fSderaadt  * This file is part of an SSL implementation written
821f2d90fSderaadt  * by Eric Young (eay@mincom.oz.au).
921f2d90fSderaadt  * The implementation was written so as to conform with Netscapes SSL
1021f2d90fSderaadt  * specification.  This library and applications are
1121f2d90fSderaadt  * FREE FOR COMMERCIAL AND NON-COMMERCIAL USE
1221f2d90fSderaadt  * as long as the following conditions are aheared to.
1321f2d90fSderaadt  *
1421f2d90fSderaadt  * Copyright remains Eric Young's, and as such any Copyright notices in
1521f2d90fSderaadt  * the code are not to be removed.  If this code is used in a product,
1621f2d90fSderaadt  * Eric Young should be given attribution as the author of the parts used.
1721f2d90fSderaadt  * This can be in the form of a textual message at program startup or
1821f2d90fSderaadt  * in documentation (online or textual) provided with the package.
1921f2d90fSderaadt  *
2021f2d90fSderaadt  * Redistribution and use in source and binary forms, with or without
2121f2d90fSderaadt  * modification, are permitted provided that the following conditions
2221f2d90fSderaadt  * are met:
2321f2d90fSderaadt  * 1. Redistributions of source code must retain the copyright
2421f2d90fSderaadt  *    notice, this list of conditions and the following disclaimer.
2521f2d90fSderaadt  * 2. Redistributions in binary form must reproduce the above copyright
2621f2d90fSderaadt  *    notice, this list of conditions and the following disclaimer in the
2721f2d90fSderaadt  *    documentation and/or other materials provided with the distribution.
2821f2d90fSderaadt  * 3. All advertising materials mentioning features or use of this software
2921f2d90fSderaadt  *    must display the following acknowledgement:
3021f2d90fSderaadt  *    This product includes software developed by Eric Young (eay@mincom.oz.au)
3121f2d90fSderaadt  *
3221f2d90fSderaadt  * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND
3321f2d90fSderaadt  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
3421f2d90fSderaadt  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
3521f2d90fSderaadt  * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
3621f2d90fSderaadt  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
3721f2d90fSderaadt  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
3821f2d90fSderaadt  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
3921f2d90fSderaadt  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
4021f2d90fSderaadt  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
4121f2d90fSderaadt  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
4221f2d90fSderaadt  * SUCH DAMAGE.
4321f2d90fSderaadt  *
4421f2d90fSderaadt  * The licence and distribution terms for any publically available version or
4521f2d90fSderaadt  * derivative of this code cannot be changed.  i.e. this code cannot simply be
4621f2d90fSderaadt  * copied and put under another distribution licence
4721f2d90fSderaadt  * [including the GNU Public Licence.]
4821f2d90fSderaadt  */
4921f2d90fSderaadt 
5021f2d90fSderaadt #include "des_locl.h"
5121f2d90fSderaadt 
52*6ecdaf80Sbrad void
des_ecb3_encrypt(des_cblock (* input),des_cblock (* output),des_key_schedule ks1,des_key_schedule ks2,des_key_schedule ks3,int encrypt)53*6ecdaf80Sbrad des_ecb3_encrypt(des_cblock (*input), des_cblock (*output),
54*6ecdaf80Sbrad     des_key_schedule ks1, des_key_schedule ks2, des_key_schedule ks3,
55*6ecdaf80Sbrad     int encrypt)
5621f2d90fSderaadt {
5736075556Smiod 	register u_int32_t l0, l1;
5821f2d90fSderaadt 	register unsigned char *in, *out;
5936075556Smiod 	u_int32_t ll[2];
6021f2d90fSderaadt 
6121f2d90fSderaadt 	in = (unsigned char *) input;
6221f2d90fSderaadt 	out = (unsigned char *) output;
6321f2d90fSderaadt 	c2l(in, l0);
6421f2d90fSderaadt 	c2l(in, l1);
6521f2d90fSderaadt 	IP(l0, l1);
6621f2d90fSderaadt 	ll[0] = l0;
6721f2d90fSderaadt 	ll[1] = l1;
6821f2d90fSderaadt 	des_encrypt2(ll, ks1, encrypt);
6921f2d90fSderaadt 	des_encrypt2(ll, ks2, !encrypt);
7021f2d90fSderaadt 	des_encrypt2(ll, ks3, encrypt);
7121f2d90fSderaadt 	l0 = ll[0];
7221f2d90fSderaadt 	l1 = ll[1];
7321f2d90fSderaadt 	FP(l1, l0);
7421f2d90fSderaadt 	l2c(l0, out);
7521f2d90fSderaadt 	l2c(l1, out);
7621f2d90fSderaadt }
77