1#pragma ident "%Z%%M% %I% %E% SMI"
| |
2/* 3 * These routines check and fix parity of encryption keys for the DES 4 * algorithm. 5 * 6 * They are a replacement for routines in key_parity.c, that don't require 7 * the table building that they do. 8 * 9 * Mark Eichin -- Cygnus Support 10 */ 11 12
| 1/* 2 * These routines check and fix parity of encryption keys for the DES 3 * algorithm. 4 * 5 * They are a replacement for routines in key_parity.c, that don't require 6 * the table building that they do. 7 * 8 * Mark Eichin -- Cygnus Support 9 */ 10 11
|
13#include <des_int.h>
| 12#include "des_int.h"
|
14 15/* 16 * des_fixup_key_parity: Forces odd parity per byte; parity is bits 17 * 8,16,...64 in des order, implies 0, 8, 16, ... 18 * vax order. 19 */ 20#define smask(step) ((1<<step)-1) 21#define pstep(x,step) (((x)&smask(step))^(((x)>>step)&smask(step))) 22#define parity_char(x) pstep(pstep(pstep((x),4),2),1) 23 24void
| 13 14/* 15 * des_fixup_key_parity: Forces odd parity per byte; parity is bits 16 * 8,16,...64 in des order, implies 0, 8, 16, ... 17 * vax order. 18 */ 19#define smask(step) ((1<<step)-1) 20#define pstep(x,step) (((x)&smask(step))^(((x)>>step)&smask(step))) 21#define parity_char(x) pstep(pstep(pstep((x),4),2),1) 22 23void
|
25mit_des_fixup_key_parity(key) 26 register mit_des_cblock key;
| 24mit_des_fixup_key_parity(mit_des_cblock key)
|
27{ 28 int i; 29 for (i=0; i<sizeof(mit_des_cblock); i++) 30 { 31 key[i] &= 0xfe; 32 key[i] |= 1^parity_char(key[i]); 33 } 34 35 return; 36} 37 38/* 39 * des_check_key_parity: returns true iff key has the correct des parity. 40 * See des_fix_key_parity for the definition of 41 * correct des parity. 42 */ 43int
| 25{ 26 int i; 27 for (i=0; i<sizeof(mit_des_cblock); i++) 28 { 29 key[i] &= 0xfe; 30 key[i] |= 1^parity_char(key[i]); 31 } 32 33 return; 34} 35 36/* 37 * des_check_key_parity: returns true iff key has the correct des parity. 38 * See des_fix_key_parity for the definition of 39 * correct des parity. 40 */ 41int
|
44mit_des_check_key_parity(key) 45 register mit_des_cblock key;
| 42mit_des_check_key_parity(mit_des_cblock key)
|
46{ 47 int i; 48 49 for (i=0; i<sizeof(mit_des_cblock); i++) 50 { 51 if((key[i] & 1) == parity_char(0xfe&key[i])) 52 { 53 return 0; 54 } 55 } 56 57 return(1); 58} 59
| 43{ 44 int i; 45 46 for (i=0; i<sizeof(mit_des_cblock); i++) 47 { 48 if((key[i] & 1) == parity_char(0xfe&key[i])) 49 { 50 return 0; 51 } 52 } 53 54 return(1); 55} 56
|