version 1.4, 2000/06/19 14:02:58 |
version 1.5, 2000/06/19 14:24:07 |
|
|
} |
} |
|
|
int |
int |
tcfs_decrypt_key (char *u, char *pwd, unsigned char *t, unsigned char *tk, |
tcfs_decrypt_key (char *pwd, u_char *t, u_char *tk, int tklen) |
unsigned int flag) |
|
{ |
{ |
int i = 0; |
int i = 0, len; |
char pass[_PASSWORD_LEN], *cypher; |
char pass[_PASSWORD_LEN], *cypher; |
char tcfskey[2*KEYSIZE], iv[8]; |
char tcfskey[2*KEYSIZE], iv[8]; |
blf_ctx ctx; |
blf_ctx ctx; |
int keysize = (flag == GROUPKEY) ? GKEYSIZE : KEYSIZE; |
|
|
|
if (!tk) |
if (!tk) |
return 0; |
return 0; |
|
|
strcpy (pass, pwd); |
strlcpy (pass, pwd, sizeof(pass)); |
|
|
if (uudecode ((char *)t, tcfskey, sizeof(tcfskey)) == -1) { |
len = uudecode ((char *)t, tcfskey, sizeof(tcfskey)); |
|
if (len == -1) { |
fprintf(stderr, "tcfs_decrypt_key: uudecode failed\n"); |
fprintf(stderr, "tcfs_decrypt_key: uudecode failed\n"); |
return 0; |
return 0; |
|
} else if (len != tklen) { |
|
fprintf(stderr, "tcfs_decrypt_key: uudecode wrong length\n"); |
|
return 0; |
} |
} |
|
|
while (strlen (pass) < 8) { |
while (strlen (pass) < 8) { |
|
|
|
|
blf_key(&ctx, pass, strlen(pass)); |
blf_key(&ctx, pass, strlen(pass)); |
memset(iv, 0, sizeof(iv)); |
memset(iv, 0, sizeof(iv)); |
blf_cbc_decrypt(&ctx, iv, tcfskey, keysize); |
blf_cbc_decrypt(&ctx, iv, tcfskey, tklen); |
|
|
memset (pass, 0, strlen (pass)); |
memset (pass, 0, strlen (pass)); |
memset (&ctx, 0, sizeof(ctx)); |
memset (&ctx, 0, sizeof(ctx)); |
|
|
memcpy (tk, tcfskey, keysize); |
memcpy (tk, tcfskey, tklen); |
return 1; |
return 1; |
} |
} |
|
|
int |
int |
tcfs_encrypt_key (char *u, char *pw, unsigned char *key, unsigned char *ek, |
tcfs_encrypt_key (char *pw, u_char *key, int klen, u_char *ek, int eklen) |
unsigned int flag) |
|
{ |
{ |
int i = 0; |
int i = 0; |
char pass[_PASSWORD_LEN], iv[8]; |
char pass[_PASSWORD_LEN], iv[8]; |
blf_ctx ctx; |
blf_ctx ctx; |
int keysize = (flag == GROUPKEY) ? GKEYSIZE : KEYSIZE; |
|
int uulen = (flag == GROUPKEY) ? UUGKEYSIZE : UUKEYSIZE; |
|
int res; |
int res; |
|
|
if (!ek) |
if (!ek) |
return 0; |
return 0; |
|
|
strcpy (pass, pw); |
strlcpy (pass, pw, sizeof(pass)); |
|
|
while (strlen(pass) < 8) { |
while (strlen(pass) < 8) { |
char tmp[_PASSWORD_LEN]; |
char tmp[_PASSWORD_LEN]; |
|
|
|
|
blf_key(&ctx, pass, strlen(pass)); |
blf_key(&ctx, pass, strlen(pass)); |
memset(iv, 0, sizeof(iv)); |
memset(iv, 0, sizeof(iv)); |
blf_cbc_encrypt(&ctx, iv, key, keysize); |
blf_cbc_encrypt(&ctx, iv, key, klen); |
|
|
memset(&ctx, 0, sizeof(ctx)); |
memset(&ctx, 0, sizeof(ctx)); |
|
|
res = uuencode (key, keysize, ek, uulen + 1); |
res = uuencode (key, klen, ek, eklen); |
if (res != uulen) { |
if (res != eklen - 1) { |
fprintf(stderr, "tcfs_encrypt_key: uuencode length wrong\n"); |
fprintf(stderr, "tcfs_encrypt_key: uuencode length wrong\n"); |
return (0); |
return (0); |
} |
} |