xcrypt.c (175965) | xcrypt.c (189087) |
---|---|
1/* 2 * Sun RPC is a product of Sun Microsystems, Inc. and is provided for 3 * unrestricted use provided that this legend is included on all tape 4 * media and as a part of the software program in whole or part. Users 5 * may copy or modify Sun RPC without charge, but are not authorized 6 * to license or distribute it to anyone else except as part of a product or 7 * program developed by the user. 8 * --- 19 unchanged lines hidden (view full) --- 28 */ 29/* 30 * Hex encryption/decryption and utility routines 31 * 32 * Copyright (C) 1986, Sun Microsystems, Inc. 33 */ 34 35#include <sys/cdefs.h> | 1/* 2 * Sun RPC is a product of Sun Microsystems, Inc. and is provided for 3 * unrestricted use provided that this legend is included on all tape 4 * media and as a part of the software program in whole or part. Users 5 * may copy or modify Sun RPC without charge, but are not authorized 6 * to license or distribute it to anyone else except as part of a product or 7 * program developed by the user. 8 * --- 19 unchanged lines hidden (view full) --- 28 */ 29/* 30 * Hex encryption/decryption and utility routines 31 * 32 * Copyright (C) 1986, Sun Microsystems, Inc. 33 */ 34 35#include <sys/cdefs.h> |
36__FBSDID("$FreeBSD: head/lib/librpcsvc/xcrypt.c 175965 2008-02-04 07:56:36Z matteo $"); | 36__FBSDID("$FreeBSD: head/lib/librpcsvc/xcrypt.c 189087 2009-02-26 20:32:11Z ed $"); |
37 38#include <stdio.h> 39#include <stdlib.h> 40#include <string.h> 41#include <rpc/des_crypt.h> 42 43static char hex[16] = { 44 '0', '1', '2', '3', '4', '5', '6', '7', --- 6 unchanged lines hidden (view full) --- 51void passwd2des( char *, char * ); 52 53/* 54 * Encrypt a secret key given passwd 55 * The secret key is passed and returned in hex notation. 56 * Its length must be a multiple of 16 hex digits (64 bits). 57 */ 58int | 37 38#include <stdio.h> 39#include <stdlib.h> 40#include <string.h> 41#include <rpc/des_crypt.h> 42 43static char hex[16] = { 44 '0', '1', '2', '3', '4', '5', '6', '7', --- 6 unchanged lines hidden (view full) --- 51void passwd2des( char *, char * ); 52 53/* 54 * Encrypt a secret key given passwd 55 * The secret key is passed and returned in hex notation. 56 * Its length must be a multiple of 16 hex digits (64 bits). 57 */ 58int |
59xencrypt(secret, passwd) 60 char *secret; 61 char *passwd; | 59xencrypt(char *secret, char *passwd) |
62{ 63 char key[8]; 64 char ivec[8]; 65 char *buf; 66 int err; 67 int len; 68 69 len = strlen(secret) / 2; --- 16 unchanged lines hidden (view full) --- 86} 87 88/* 89 * Decrypt secret key using passwd 90 * The secret key is passed and returned in hex notation. 91 * Once again, the length is a multiple of 16 hex digits 92 */ 93int | 60{ 61 char key[8]; 62 char ivec[8]; 63 char *buf; 64 int err; 65 int len; 66 67 len = strlen(secret) / 2; --- 16 unchanged lines hidden (view full) --- 84} 85 86/* 87 * Decrypt secret key using passwd 88 * The secret key is passed and returned in hex notation. 89 * Once again, the length is a multiple of 16 hex digits 90 */ 91int |
94xdecrypt(secret, passwd) 95 char *secret; 96 char *passwd; | 92xdecrypt(char *secret, char *passwd) |
97{ 98 char key[8]; 99 char ivec[8]; 100 char *buf; 101 int err; 102 int len; 103 104 len = strlen(secret) / 2; --- 15 unchanged lines hidden (view full) --- 120 return (1); 121} 122 123 124/* 125 * Turn password into DES key 126 */ 127void | 93{ 94 char key[8]; 95 char ivec[8]; 96 char *buf; 97 int err; 98 int len; 99 100 len = strlen(secret) / 2; --- 15 unchanged lines hidden (view full) --- 116 return (1); 117} 118 119 120/* 121 * Turn password into DES key 122 */ 123void |
128passwd2des(pw, key) 129 char *pw; 130 char *key; | 124passwd2des(char *pw, char *key) |
131{ 132 int i; 133 134 bzero(key, 8); 135 for (i = 0; *pw; i = (i+1)%8) { 136 key[i] ^= *pw++ << 1; 137 } 138 des_setparity(key); 139} 140 141 142 143/* 144 * Hex to binary conversion 145 */ 146static void | 125{ 126 int i; 127 128 bzero(key, 8); 129 for (i = 0; *pw; i = (i+1)%8) { 130 key[i] ^= *pw++ << 1; 131 } 132 des_setparity(key); 133} 134 135 136 137/* 138 * Hex to binary conversion 139 */ 140static void |
147hex2bin(len, hexnum, binnum) 148 int len; 149 char *hexnum; 150 char *binnum; | 141hex2bin(int len, char *hexnum, char *binnum) |
151{ 152 int i; 153 154 for (i = 0; i < len; i++) { 155 *binnum++ = 16 * hexval(hexnum[2*i]) + hexval(hexnum[2*i+1]); 156 } 157} 158 159/* 160 * Binary to hex conversion 161 */ 162static void | 142{ 143 int i; 144 145 for (i = 0; i < len; i++) { 146 *binnum++ = 16 * hexval(hexnum[2*i]) + hexval(hexnum[2*i+1]); 147 } 148} 149 150/* 151 * Binary to hex conversion 152 */ 153static void |
163bin2hex(len, binnum, hexnum) 164 int len; 165 unsigned char *binnum; 166 char *hexnum; | 154bin2hex(int len, unsigned char *binnum, char *hexnum) |
167{ 168 int i; 169 unsigned val; 170 171 for (i = 0; i < len; i++) { 172 val = binnum[i]; 173 hexnum[i*2] = hex[val >> 4]; 174 hexnum[i*2+1] = hex[val & 0xf]; 175 } 176 hexnum[len*2] = 0; 177} 178 179static char | 155{ 156 int i; 157 unsigned val; 158 159 for (i = 0; i < len; i++) { 160 val = binnum[i]; 161 hexnum[i*2] = hex[val >> 4]; 162 hexnum[i*2+1] = hex[val & 0xf]; 163 } 164 hexnum[len*2] = 0; 165} 166 167static char |
180hexval(c) 181 char c; | 168hexval(char c) |
182{ 183 if (c >= '0' && c <= '9') { 184 return (c - '0'); 185 } else if (c >= 'a' && c <= 'z') { 186 return (c - 'a' + 10); 187 } else if (c >= 'A' && c <= 'Z') { 188 return (c - 'A' + 10); 189 } else { 190 return (-1); 191 } 192} | 169{ 170 if (c >= '0' && c <= '9') { 171 return (c - '0'); 172 } else if (c >= 'a' && c <= 'z') { 173 return (c - 'a' + 10); 174 } else if (c >= 'A' && c <= 'Z') { 175 return (c - 'A' + 10); 176 } else { 177 return (-1); 178 } 179} |