Newsgroups: comp.sources.misc From: glad@daimi.aau.dk (Michael Glad) Subject: v23i098: ufc-crypt - fast crypt/fcrypt routines, Part02/02 Message-ID: <1991Oct22.020049.29227@sparky.imd.sterling.com> X-Md4-Signature: 6e5cc8382ede05bd57174cd24db28617 Date: Tue, 22 Oct 1991 02:00:49 GMT Approved: kent@sparky.imd.sterling.com Submitted-by: glad@daimi.aau.dk (Michael Glad) Posting-number: Volume 23, Issue 98 Archive-name: ufc-crypt/part02 Environment: UNIX, 32BIT #! /bin/sh # into a shell via "sh file" or similar. To overwrite existing files, # type "sh file -c". # The tool that generated this appeared in the comp.sources.unix newsgroup; # send mail to comp-sources-unix@uunet.uu.net if you want that tool. # Contents: Makefile crypt.c crypt.s300.S crypt.sparc.S crypt.sun3.S # patchlevel.h ufc.c # Wrapped by kent@sparky on Wed Oct 16 15:47:03 1991 PATH=/bin:/usr/bin:/usr/ucb ; export PATH echo If this archive is complete, you will see the following message: echo ' "shar: End of archive 2 (of 2)."' if test -f 'Makefile' -a "${1}" != "-c" ; then echo shar: Will not clobber existing file \"'Makefile'\" else echo shar: Extracting \"'Makefile'\" \(1984 characters\) sed "s/^X//" >'Makefile' <<'END_OF_FILE' X# X# UFC-crypt: ultra fast crypt(3) implementation X# Copyright (C) 1991, Michael Glad, email: glad@daimi.aau.dk X# X# This library is free software; you can redistribute it and/or X# modify it under the terms of the GNU Library General Public X# License as published by the Free Software Foundation; either X# version 2 of the License, or (at your option) any later version. X# X# This library is distributed in the hope that it will be useful, X# but WITHOUT ANY WARRANTY; without even the implied warranty of X# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU X# Library General Public License for more details. X# X# You should have received a copy of the GNU Library General Public X# License along with this library; if not, write to the Free X# Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. X# X# @(#)Makefile 2.2 10/04/91 X# X X# X# Select one of the following modules: X# XCRYPT = crypt.o X X# portable C version: crypt.o X# SUN3 models: crypt.sun3.o X# HP series 300/400: crypt.s300.o X# SUN SPARC systems: crypt.sparc.o X X# X# Which compiler to use X# X#CC = gcc XCC = cc X X# On HP's etc: define this XFL = -DSYSV XOFLAGS = -O X X# X# End-of-configuration X# X XCFLAGS = $(OFLAGS) $(FL) XCRYPTOBJ = crypt_util.o $(CRYPT) X X# X# Sample program for debugging/testing/benchmarking X# X Xufc: ufc.o libufc.a X $(CC) ufc.o libufc.a -o ufc X Xlibufc.a: $(CRYPTOBJ) X ar r libufc.a $(CRYPTOBJ) X ranlib libufc.a X X# X# Crypt utility functions X# X Xcrypt_util.o: crypt_util.c Xufc.o: ufc.c X X# X# Crypt functions X# X X# Semiportable Xufc.o: ufc.c X $(CC) $(CFLAGS) -c ufc.c X X# Sun3 Xcrypt.sun3.o: crypt.sun3.S X ./S2o crypt.sun3.S crypt.sun3.o X X# HP 9000 series 300 Xcrypt.s300.o: crypt.s300.S X ./S2o crypt.s300.S crypt.s300.o X X# SUN SPARC architecture Xcrypt.sparc.o: crypt.sparc.S X ./S2o crypt.sparc.S crypt.sparc.o X Xclean: X /bin/rm -f *.o core *~ ufc libufc.a tmp.s mon.out a.out ufc.shar X Xshar: X shar -c -pX COPYING README Makefile S2o crypt.c *.S crypt_util.c ufc.c patchlevel.h > ufc.shar END_OF_FILE if test 1984 -ne `wc -c <'Makefile'`; then echo shar: \"'Makefile'\" unpacked with wrong size! fi # end of 'Makefile' fi if test -f 'crypt.c' -a "${1}" != "-c" ; then echo shar: Will not clobber existing file \"'crypt.c'\" else echo shar: Extracting \"'crypt.c'\" \(1957 characters\) sed "s/^X//" >'crypt.c' <<'END_OF_FILE' X/* X * UFC-crypt: ultra fast crypt(3) implementation X * X * Copyright (C) 1991, Michael Glad, email: glad@daimi.aau.dk X * X * This library is free software; you can redistribute it and/or X * modify it under the terms of the GNU Library General Public X * License as published by the Free Software Foundation; either X * version 2 of the License, or (at your option) any later version. X * X * This library is distributed in the hope that it will be useful, X * but WITHOUT ANY WARRANTY; without even the implied warranty of X * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU X * Library General Public License for more details. X X * You should have received a copy of the GNU Library General Public X * License along with this library; if not, write to the Free X * Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. X * X * @(#)crypt.c 2.2 10/04/91 X * X * Semiportable C version X * X */ X Xextern void setup_salt(), mk_keytab(), pr_bits(); Xextern char *output_conversion(); X Xextern unsigned long sb0[], sb1[], sb2[], sb3[]; Xextern unsigned long keytab[16][2]; X X#define SBA(sb, v) (*(unsigned long*)((char*)(sb)+(v))) X X#define F(I, O1, O2, SBX, SBY) \ X s = *k++ ^ I; \ X O1 ^= SBA(SBX, (s & 0xffff)); O2 ^= SBA(SBX, ((s & 0xffff) + 4)); \ X O1 ^= SBA(SBY, (s >>= 16)); O2 ^= SBA(SBY, ((s) + 4)); X X#define G(I1, I2, O1, O2) \ X F(I1, O1, O2, sb1, sb0) F(I2, O1, O2, sb3, sb2) X X#define H G(r1, r2, l1, l2) ; G(l1, l2, r1, r2) X Xchar *crypt(key, salt) X char *key; X char *salt; X { unsigned long l1, l2, r1, r2, i, j, s, *k; X X setup_salt(salt); X mk_keytab(key); X X l1=l2=r1=r2=0; X X for(j=0; j<25; j++) { X k = &keytab[0][0]; X for(i=8; i--; ) { X H; X } X s=l1; l1=r1; r1=s; s=l2; l2=r2; r2=s; X } X X return output_conversion(l1, l2, r1, r2, salt); X } X END_OF_FILE if test 1957 -ne `wc -c <'crypt.c'`; then echo shar: \"'crypt.c'\" unpacked with wrong size! fi # end of 'crypt.c' fi if test -f 'crypt.s300.S' -a "${1}" != "-c" ; then echo shar: Will not clobber existing file \"'crypt.s300.S'\" else echo shar: Extracting \"'crypt.s300.S'\" \(2491 characters\) sed "s/^X//" >'crypt.s300.S' <<'END_OF_FILE' X # X # UFC-crypt: ultra fast crypt(3) implementation X # Copyright (C) 1991, Michael Glad, email: glad@daimi.aau.dk X # X # This library is free software, you can redistribute it and/or X # modify it under the terms of the GNU Library General Public X # License as published by the Free Software Foundation, either X # version 2 of the License, or (at your option) any later version. X # X # This library is distributed in the hope that it will be useful, X # but WITHOUT ANY WARRANTY, without even the implied warranty of X # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU X # Library General Public License for more details. X # X # You should have received a copy of the GNU Library General Public X # License along with this library, if not, write to the Free X # Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. X # X # @(#)crypt.s300.S 2.2 10/04/91 X # X # MC680x0/Hp9000 s300/s400 assembly code X # X X#define L1 %d0 X#define L2 %d1 X#define R1 %d2 X#define R2 %d3 X#define SCR1 %d4 X#define SCR2 %d5 X#define SCR3 %d6 X X#define I %d7 X#define J -16(%a6) X X#define SB0 %a0 X#define SB1 %a1 X#define SB2 %a2 X#define SB3 %a3 X#define KPTR %a4 X X#define F(I,O1,O2,SBX,SBY) \ X mov.l (KPTR)+,SCR1 ; eor.l I,SCR1 ; \ X mov.l 0(SBX,SCR1.w),SCR2 ; eor.l SCR2,O1 ; \ X mov.l 4(SBX,SCR1.w),SCR2 ; eor.l SCR2,O2 ; \ X swap.w SCR1 ; \ X mov.l 0(SBY,SCR1.w),SCR2 ; eor.l SCR2,O1 ; \ X mov.l 4(SBY,SCR1.w),SCR2 ; eor.l SCR2,O2 ; X X#define G(I1,I2,O1,O2) \ X F(I1,O1,O2,SB1,SB0) F(I2,O1,O2,SB3,SB2) X X#define H G(R1,R2,L1,L2) ; G(L1,L2,R1,R2) X X text X global _crypt X_crypt: X # X # Preamble X # X link %a6,&-56 ; movem.l &15612,(%sp) X # X # Set up salt and key tables X # X mov.l 0xc(%a6),-(%sp) ; jsr _setup_salt ; addq.w &4,%sp X mov.l 0x8(%a6),-(%sp) ; jsr _mk_keytab ; addq.w &4,%sp X # X # Setup address registers with sb pointers X # X mov.l &_sb0,SB0 ; mov.l &_sb1,SB1 ; mov.l &_sb2,SB2 ; mov.l &_sb3,SB3 X # X # Initialize DES working variables X # X moveq &0,L1 ; moveq &0,L2 ; moveq &0,R1 ; moveq &0,R2 X X # X # And loop... X # X mov.l &25,J XLagain: X mov.l &_keytab,KPTR X moveq &4,I XLagain1: X H H X subq.l &1,I X bne Lagain1 X # Permute X mov.l L1,SCR1 ; mov.l R1,L1 ; mov.l SCR1,R1 X mov.l L2,SCR1 ; mov.l R2,L2 ; mov.l SCR1,R2 X # X subq.l &1,J X tst.l J X bne Lagain X # X # Output conversion X # X mov.l 0xc(%a6),-(%sp) X mov.l R2,-(%sp) ; mov.l R1,-(%sp) ; mov.l L2,-(%sp) ; mov.l L1,-(%sp) X jsr _output_conversion ; addq.w &4,%sp X X # X # Postamble X # X movem.l (-56)(%a6),&15612 ; unlk %a6 ; rts END_OF_FILE if test 2491 -ne `wc -c <'crypt.s300.S'`; then echo shar: \"'crypt.s300.S'\" unpacked with wrong size! fi # end of 'crypt.s300.S' fi if test -f 'crypt.sparc.S' -a "${1}" != "-c" ; then echo shar: Will not clobber existing file \"'crypt.sparc.S'\" else echo shar: Extracting \"'crypt.sparc.S'\" \(2735 characters\) sed "s/^X//" >'crypt.sparc.S' <<'END_OF_FILE' X! X! UFC-crypt: ultra fast crypt(3) implementation X! Copyright (C) 1991, Michael Glad, email: glad@daimi.aau.dk X! X! This library is free software, you can redistribute it and/or X! modify it under the terms of the GNU Library General Public X! License as published by the Free Software Foundation, either X! version 2 of the License, or (at your option) any later version. X! X! This library is distributed in the hope that it will be useful, X! but WITHOUT ANY WARRANTY, without even the implied warranty of X! MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU X! Library General Public License for more details. X! X! You should have received a copy of the GNU Library General Public X! License along with this library, if not, write to the Free X! Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. X! X! @(#)crypt.sparc.S 2.2 10/04/91 X! X! Assembly code for SPARC architecture machines X! X X#define J %i2 X#define I %i3 X#define SALT %i4 X#define KEY %i5 X X#define L1 %o0 X#define L2 %o1 X#define R1 %o2 X#define R2 %o3 X X#define KPTR %g1 X#define MASK %g2 X#define SCR1a %g3 X#define SCR1b %g4 X#define SCR1 %g5 X#define SCR2 %g6 X#define SCR3 %g7 X X#define SB0a %l0 X#define SB0b %l1 X#define SB1a %l2 X#define SB1b %l3 X#define SB2a %l4 X#define SB2b %l5 X#define SB3a %l6 X#define SB3b %l7 X X#define ASSIGN(reg,value) sethi %hi(value),reg ; or %lo(value),reg,reg ; X X X#define F(I,O1,O2,SBX1,SBX2,SBY1,SBY2) \ X ld [KPTR],SCR1 ; \ X xor SCR1,I,SCR1 ; \ X and SCR1,MASK,SCR1a ; \ X \ X ld [SBX1+SCR1a],SCR2 ; inc 4,KPTR ; \ X srl SCR1,16,SCR1b ; \ X ld [SBX2+SCR1a],SCR3 ; xor SCR2,O1,O1 ; \ X \ X ld [SBY1+SCR1b],SCR2 ; xor SCR3,O2,O2 ; \ X ld [SBY2+SCR1b],SCR3 ; xor SCR2,O1,O1 ; \ X \ X xor SCR3,O2,O2 ; X X#define G(I1,I2,O1,O2) \ X F(I1,O1,O2,SB1a,SB1b,SB0a,SB0b) F(I2,O1,O2,SB3a,SB3b,SB2a,SB2b) X X#define H G(R1,R2,L1,L2) ; G(L1,L2,R1,R2) X X .seg "text" X .global _crypt X X_crypt: X! X! Preamble X! X save %sp,-104,%sp X! X! Set up salt and key tables X! X mov %i0,KEY ; mov %i1,SALT X call _setup_salt,1 ; mov SALT,%o0 ! delayed branch! X call _mk_keytab,1 ; mov KEY,%o0 ! do X! X! Set up sb pointers X! X ASSIGN(SB0a,_sb0) ; add SB0a,4,SB0b X ASSIGN(SB1a,_sb1) ; add SB1a,4,SB1b X ASSIGN(SB2a,_sb2) ; add SB2a,4,SB2b X ASSIGN(SB3a,_sb3) ; add SB3a,4,SB3b X! X ASSIGN(MASK,0xffff) X! X! Initialize working variables X! X mov 0,L1 ; mov 0,L2 ; mov 0,R1 ; mov 0,R2 X! X! And loop... X! X X ASSIGN(J,25) XLagain: X ASSIGN(KPTR,_keytab) X ASSIGN(I, 8) XLagain1: X H X deccc I X bnz Lagain1 X nop X! Permute X mov L1,SCR1 ; mov R1,L1 ; mov SCR1,R1 X mov L2,SCR1 ; mov R2,L2 ; mov SCR1,R2 X! X deccc J X bnz Lagain X nop X! X! Output conversion X! X call _output_conversion,5 X mov SALT,%o4 X! X! Postamble X! X ret ; restore %g0,%o0,%o0 END_OF_FILE if test 2735 -ne `wc -c <'crypt.sparc.S'`; then echo shar: \"'crypt.sparc.S'\" unpacked with wrong size! fi # end of 'crypt.sparc.S' fi if test -f 'crypt.sun3.S' -a "${1}" != "-c" ; then echo shar: Will not clobber existing file \"'crypt.sun3.S'\" else echo shar: Extracting \"'crypt.sun3.S'\" \(2388 characters\) sed "s/^X//" >'crypt.sun3.S' <<'END_OF_FILE' X| X| UFC-crypt: ultra fast crypt(3) implementation X| Copyright (C) 1991, Michael Glad, email: glad@daimi.aau.dk X| X| This library is free software, you can redistribute it and/or X| modify it under the terms of the GNU Library General Public X| License as published by the Free Software Foundation, either X| version 2 of the License, or (at your option) any later version. X| X| This library is distributed in the hope that it will be useful, X| but WITHOUT ANY WARRANTY, without even the implied warranty of X| MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU X| Library General Public License for more details. X| X| You should have received a copy of the GNU Library General Public X| License along with this library, if not, write to the Free X| Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. X| X| @(#)crypt.sun3.S 2.2 10/04/91 X| X| Assembly code for SUN3 models X| X X#define L1 d0 X#define L2 d1 X#define R1 d2 X#define R2 d3 X#define SCR1 d4 X#define SCR2 d5 X#define SCR3 d6 X X#define I d7 X#define J a6@(-16) X X#define SB0 a0 X#define SB1 a1 X#define SB2 a2 X#define SB3 a3 X#define KPTR a4 X X#define F(I,O1,O2,SBX,SBY) \ X movl KPTR@+,SCR1 ; eorl I,SCR1 ; \ X movl SBX@(0,SCR1:w),SCR2 ; eorl SCR2,O1 ; \ X movl SBX@(4,SCR1:w),SCR2 ; eorl SCR2,O2 ; \ X swap SCR1 ; \ X movl SBY@(0,SCR1:w),SCR2 ; eorl SCR2,O1 ; \ X movl SBY@(4,SCR1:w),SCR2 ; eorl SCR2,O2 ; X X#define G(I1,I2,O1,O2) \ X F(I1,O1,O2,SB1,SB0) F(I2,O1,O2,SB3,SB2) X X#define H G(R1,R2,L1,L2) ; G(L1,L2,R1,R2) X X .text X .proc X .globl _crypt X_crypt: X| X| Preamble X| X link a6,#-56 ; moveml #15612,sp@ X| X| Set up salt and key tables X| X movl a6@(0xc),sp@- ; jbsr _setup_salt ; addqw #4,sp X movl a6@(0x8),sp@- ; jbsr _mk_keytab ; addqw #4,sp X| X| Setup address registers with sb pointers X| X movl #_sb0,SB0 ; movl #_sb1,SB1 ; movl #_sb2,SB2 ; movl #_sb3,SB3 X| X| Initialize DES working variables X| X moveq #0,L1 ; moveq #0,L2 ; moveq #0,R1 ; moveq #0,R2 X X| X| And loop... X| X movl #25,J XLagain: X movl #_keytab,KPTR X moveq #4,I XLagain1: X H H X subql #1,I X tstl I X jne Lagain1 X| Permute X movl L1,SCR1 ; movl R1,L1 ; movl SCR1,R1 X movl L2,SCR1 ; movl R2,L2 ; movl SCR1,R2 X| X subql #1,J X jne Lagain X| X| Output conversion X| X movl a6@(0xc),sp@- X movl R2,sp@- ; movl R1,sp@- ; movl L2,sp@- ; movl L1,sp@- X jbsr _output_conversion ; addqw #4,sp X X| X| Postamble X| X moveml a6@(-56),#15612 ; unlk a6 ; rts END_OF_FILE if test 2388 -ne `wc -c <'crypt.sun3.S'`; then echo shar: \"'crypt.sun3.S'\" unpacked with wrong size! fi # end of 'crypt.sun3.S' fi if test -f 'patchlevel.h' -a "${1}" != "-c" ; then echo shar: Will not clobber existing file \"'patchlevel.h'\" else echo shar: Extracting \"'patchlevel.h'\" \(57 characters\) sed "s/^X//" >'patchlevel.h' <<'END_OF_FILE' X/* @(#)patchlevel.h 1.1 10/04/91 */ X#define PATCHLEVEL 0 END_OF_FILE if test 57 -ne `wc -c <'patchlevel.h'`; then echo shar: \"'patchlevel.h'\" unpacked with wrong size! fi # end of 'patchlevel.h' fi if test -f 'ufc.c' -a "${1}" != "-c" ; then echo shar: Will not clobber existing file \"'ufc.c'\" else echo shar: Extracting \"'ufc.c'\" \(1429 characters\) sed "s/^X//" >'ufc.c' <<'END_OF_FILE' X/* X * UFC-crypt: ultra fast crypt(3) implementation X * X * Copyright (C) 1991, Michael Glad, email: glad@daimi.aau.dk X * X * This library is free software; you can redistribute it and/or X * modify it under the terms of the GNU Library General Public X * License as published by the Free Software Foundation; either X * version 2 of the License, or (at your option) any later version. X * X * This library is distributed in the hope that it will be useful, X * but WITHOUT ANY WARRANTY; without even the implied warranty of X * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU X * Library General Public License for more details. X X * You should have received a copy of the GNU Library General Public X * License along with this library; if not, write to the Free X * Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. X * X * @(#)ufc.c 2.2 10/04/91 X * X * Stub main program for debugging X * and benchmarking. X * X */ X X#include X Xchar *crypt(); X Xmain(argc, argv) X int argc; X char **argv; X { char *s; X unsigned long i,iterations; X X if(argc != 2) { X fprintf(stderr, "usage: ufc iterations\n"); X exit(1); X } X argv++; X iterations = atoi(*argv); X printf("ufc: running %d iterations\n", iterations); X X for(i=0; i