xref: /plan9/sys/src/cmd/auth/lib/keyfmt.c (revision ff8c3af2f44d95267f67219afa20ba82ff6cf7e4)
1 #include <u.h>
2 #include <libc.h>
3 #include "authcmdlib.h"
4 
5 /*
6  * print a key in des standard form
7  */
8 int
9 keyfmt(Fmt *f)
10 {
11 	uchar key[8];
12 	char buf[32];
13 	uchar *k;
14 	int i;
15 
16 	k = va_arg(f->args, uchar*);
17 	key[0] = 0;
18 	for(i = 0; i < 7; i++){
19 		key[i] |= k[i] >> i;
20 		key[i] &= ~1;
21 		key[i+1] = k[i] << (7 - i);
22 	}
23 	key[7] &= ~1;
24 	sprint(buf, "%.3uo %.3uo %.3uo %.3uo %.3uo %.3uo %.3uo %.3uo",
25 		key[0], key[1], key[2], key[3], key[4], key[5], key[6], key[7]);
26 	fmtstrcpy(f, buf);
27 	return 0;
28 }
29