setkey.c (784bddbc5bca158d2fb57eed7c5e4ceebd49ff8b) setkey.c (b3aaa0cc21c63d388230c7ef2a80abd631ff20d5)
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 *

--- 70 unchanged lines hidden (view full) ---

79
80/*
81 * Set the modulus for all our Diffie-Hellman operations
82 */
83void
84setmodulus(modx)
85 char *modx;
86{
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 *

--- 70 unchanged lines hidden (view full) ---

79
80/*
81 * Set the modulus for all our Diffie-Hellman operations
82 */
83void
84setmodulus(modx)
85 char *modx;
86{
87 MODULUS = xtom(modx);
87 MODULUS = mp_xtom(modx);
88}
89
90/*
91 * Set the secretkey key for this uid
92 */
93keystatus
94pk_setkey(uid, skey)
95 uid_t uid;

--- 97 unchanged lines hidden (view full) ---

193 bzero((char *)&xpublic, sizeof(xpublic));
194 if (!getpublickey(remote_name, xpublic)) {
195 if (nodefaultkeys || !getpublickey("nobody", xpublic))
196 return (KEY_UNKNOWN);
197 }
198 }
199
200 if (!readcache(xpublic, xsecret, &deskey)) {
88}
89
90/*
91 * Set the secretkey key for this uid
92 */
93keystatus
94pk_setkey(uid, skey)
95 uid_t uid;

--- 97 unchanged lines hidden (view full) ---

193 bzero((char *)&xpublic, sizeof(xpublic));
194 if (!getpublickey(remote_name, xpublic)) {
195 if (nodefaultkeys || !getpublickey("nobody", xpublic))
196 return (KEY_UNKNOWN);
197 }
198 }
199
200 if (!readcache(xpublic, xsecret, &deskey)) {
201 public = xtom(xpublic);
202 secret = xtom(xsecret);
201 public = mp_xtom(xpublic);
202 secret = mp_xtom(xsecret);
203 /* Sanity Check on public and private keys */
204 if ((public == NULL) || (secret == NULL))
205 return (KEY_SYSTEMERR);
206
203 /* Sanity Check on public and private keys */
204 if ((public == NULL) || (secret == NULL))
205 return (KEY_SYSTEMERR);
206
207 common = itom(0);
208 pow(public, secret, MODULUS, common);
207 common = mp_itom(0);
208 mp_pow(public, secret, MODULUS, common);
209 extractdeskey(common, &deskey);
210 writecache(xpublic, xsecret, &deskey);
209 extractdeskey(common, &deskey);
210 writecache(xpublic, xsecret, &deskey);
211 mfree(secret);
212 mfree(public);
213 mfree(common);
211 mp_mfree(secret);
212 mp_mfree(public);
213 mp_mfree(common);
214 }
215 err = ecb_crypt((char *)&deskey, (char *)key, sizeof (des_block),
216 DES_HW | mode);
217 if (DES_FAILED(err)) {
218 return (KEY_SYSTEMERR);
219 }
220 return (KEY_SUCCESS);
221}

--- 21 unchanged lines hidden (view full) ---

243 return (KEY_NOSECRET);
244
245 if (!getsecretkey("nobody", xsecret, zero) ||
246 xsecret[0] == 0)
247 return (KEY_NOSECRET);
248 }
249
250 if (!readcache(xpublic, xsecret, &result->cryptkeyres_u.deskey)) {
214 }
215 err = ecb_crypt((char *)&deskey, (char *)key, sizeof (des_block),
216 DES_HW | mode);
217 if (DES_FAILED(err)) {
218 return (KEY_SYSTEMERR);
219 }
220 return (KEY_SUCCESS);
221}

--- 21 unchanged lines hidden (view full) ---

243 return (KEY_NOSECRET);
244
245 if (!getsecretkey("nobody", xsecret, zero) ||
246 xsecret[0] == 0)
247 return (KEY_NOSECRET);
248 }
249
250 if (!readcache(xpublic, xsecret, &result->cryptkeyres_u.deskey)) {
251 public = xtom(xpublic);
252 secret = xtom(xsecret);
251 public = mp_xtom(xpublic);
252 secret = mp_xtom(xsecret);
253 /* Sanity Check on public and private keys */
254 if ((public == NULL) || (secret == NULL))
255 return (KEY_SYSTEMERR);
256
253 /* Sanity Check on public and private keys */
254 if ((public == NULL) || (secret == NULL))
255 return (KEY_SYSTEMERR);
256
257 common = itom(0);
258 pow(public, secret, MODULUS, common);
257 common = mp_itom(0);
258 mp_pow(public, secret, MODULUS, common);
259 extractdeskey(common, &result->cryptkeyres_u.deskey);
260 writecache(xpublic, xsecret, &result->cryptkeyres_u.deskey);
259 extractdeskey(common, &result->cryptkeyres_u.deskey);
260 writecache(xpublic, xsecret, &result->cryptkeyres_u.deskey);
261 mfree(secret);
262 mfree(public);
263 mfree(common);
261 mp_mfree(secret);
262 mp_mfree(public);
263 mp_mfree(common);
264 }
265
266 return (KEY_SUCCESS);
267}
268
269/*
270 * Choose middle 64 bits of the common key to use as our des key, possibly
271 * overwriting the lower order bits by setting parity.

--- 4 unchanged lines hidden (view full) ---

276 des_block *deskey;
277{
278 MINT *a;
279 short r;
280 int i;
281 short base = (1 << 8);
282 char *k;
283
264 }
265
266 return (KEY_SUCCESS);
267}
268
269/*
270 * Choose middle 64 bits of the common key to use as our des key, possibly
271 * overwriting the lower order bits by setting parity.

--- 4 unchanged lines hidden (view full) ---

276 des_block *deskey;
277{
278 MINT *a;
279 short r;
280 int i;
281 short base = (1 << 8);
282 char *k;
283
284 a = itom(0);
284 a = mp_itom(0);
285#ifdef SOLARIS_MP
286 _mp_move(ck, a);
287#else
285#ifdef SOLARIS_MP
286 _mp_move(ck, a);
287#else
288 move(ck, a);
288 mp_move(ck, a);
289#endif
290 for (i = 0; i < ((KEYSIZE - 64) / 2) / 8; i++) {
289#endif
290 for (i = 0; i < ((KEYSIZE - 64) / 2) / 8; i++) {
291 sdiv(a, base, a, &r);
291 mp_sdiv(a, base, a, &r);
292 }
293 k = deskey->c;
294 for (i = 0; i < 8; i++) {
292 }
293 k = deskey->c;
294 for (i = 0; i < 8; i++) {
295 sdiv(a, base, a, &r);
295 mp_sdiv(a, base, a, &r);
296 *k++ = r;
297 }
296 *k++ = r;
297 }
298 mfree(a);
298 mp_mfree(a);
299 des_setparity((char *)deskey);
300}
301
302/*
303 * Key storage management
304 */
305
306#define KEY_ONLY 0

--- 244 unchanged lines hidden ---
299 des_setparity((char *)deskey);
300}
301
302/*
303 * Key storage management
304 */
305
306#define KEY_ONLY 0

--- 244 unchanged lines hidden ---