зеркало из https://github.com/github/putty.git
Expose des_{en,de}crypt_xdmauth in testcrypt.
This allows me to remove another diagnostic main() that I just found lurking at the bottom of sshdes.c, which was there to allow manual untangling of XDM-AUTHORIZATION-1 strings when debugging X forwarding. Now you can ask the same kind of question at the interactive Python prompt, without having to manually compile anything. For example, the query you might previously have asked by building the sshdes test program and running $ ./sshdes 090a0b0c0d0e0f10 0123456789abcd decrypt(090a0b0c0d0e0f10,0123456789abcd) = ab53fd65ae7f4ec3 encrypt(090a0b0c0d0e0f10,0123456789abcd) = 7065d20441f5abe3 you can now run using the standard testcrypt (bearing in mind that the actual library function takes the key argument first): $ python -i test/testcrypt.py >>> from binascii import hexlify as H, unhexlify as U >>> H(des_decrypt_xdmauth(U('0123456789abcd'),U('090a0b0c0d0e0f10'))) 'ab53fd65ae7f4ec3' >>> H(des_encrypt_xdmauth(U('0123456789abcd'),U('090a0b0c0d0e0f10'))) '7065d20441f5abe3'
This commit is contained in:
Родитель
b63846902e
Коммит
be779f988d
55
sshdes.c
55
sshdes.c
|
@ -1135,58 +1135,3 @@ const ssh1_cipheralg ssh1_des = {
|
|||
des_ssh1_encrypt_blk, des_ssh1_decrypt_blk,
|
||||
8, "single-DES CBC"
|
||||
};
|
||||
|
||||
#ifdef TEST_XDM_AUTH
|
||||
|
||||
/*
|
||||
* Small standalone utility which allows encryption and decryption of
|
||||
* single cipher blocks in the XDM-AUTHORIZATION-1 style. Written
|
||||
* during the rework of X authorisation for connection sharing, to
|
||||
* check the corner case when xa1_firstblock matches but the rest of
|
||||
* the authorisation is bogus.
|
||||
*
|
||||
* Just compile this file on its own with the above ifdef symbol
|
||||
* predefined:
|
||||
|
||||
gcc -DTEST_XDM_AUTH -o sshdes sshdes.c
|
||||
|
||||
*/
|
||||
|
||||
#include <stdlib.h>
|
||||
void *safemalloc(size_t n, size_t size) { return calloc(n, size); }
|
||||
void safefree(void *p) { return free(p); }
|
||||
void smemclr(void *p, size_t size) { memset(p, 0, size); }
|
||||
int main(int argc, char **argv)
|
||||
{
|
||||
unsigned char words[2][8];
|
||||
unsigned char out[8];
|
||||
int i, j;
|
||||
|
||||
memset(words, 0, sizeof(words));
|
||||
|
||||
for (i = 0; i < 2; i++) {
|
||||
for (j = 0; j < 8 && argv[i+1][2*j]; j++) {
|
||||
char x[3];
|
||||
unsigned u;
|
||||
x[0] = argv[i+1][2*j];
|
||||
x[1] = argv[i+1][2*j+1];
|
||||
x[2] = 0;
|
||||
sscanf(x, "%02x", &u);
|
||||
words[i][j] = u;
|
||||
}
|
||||
}
|
||||
|
||||
memcpy(out, words[0], 8);
|
||||
des_decrypt_xdmauth(words[1], out, 8);
|
||||
printf("decrypt(%s,%s) = ", argv[1], argv[2]);
|
||||
for (i = 0; i < 8; i++) printf("%02x", out[i]);
|
||||
printf("\n");
|
||||
|
||||
memcpy(out, words[0], 8);
|
||||
des_encrypt_xdmauth(words[1], out, 8);
|
||||
printf("encrypt(%s,%s) = ", argv[1], argv[2]);
|
||||
for (i = 0; i < 8; i++) printf("%02x", out[i]);
|
||||
printf("\n");
|
||||
}
|
||||
|
||||
#endif
|
||||
|
|
26
testcrypt.c
26
testcrypt.c
|
@ -770,6 +770,32 @@ strbuf *rsa_ssh1_decrypt_pkcs1_wrapper(mp_int *input, RSAKey *key)
|
|||
return sb;
|
||||
}
|
||||
|
||||
#define WRAP_des_encrypt_xdmauth ,
|
||||
strbuf *des_encrypt_xdmauth_wrapper(ptrlen key, ptrlen data)
|
||||
{
|
||||
if (key.len != 7)
|
||||
fatal_error("des_encrypt_xdmauth: key must be 7 bytes long");
|
||||
if (data.len % 8 != 0)
|
||||
fatal_error("des_encrypt_xdmauth: data must be a multiple of 8 bytes");
|
||||
strbuf *sb = strbuf_new();
|
||||
put_datapl(sb, data);
|
||||
des_encrypt_xdmauth(key.ptr, sb->u, sb->len);
|
||||
return sb;
|
||||
}
|
||||
|
||||
#define WRAP_des_decrypt_xdmauth ,
|
||||
strbuf *des_decrypt_xdmauth_wrapper(ptrlen key, ptrlen data)
|
||||
{
|
||||
if (key.len != 7)
|
||||
fatal_error("des_decrypt_xdmauth: key must be 7 bytes long");
|
||||
if (data.len % 8 != 0)
|
||||
fatal_error("des_decrypt_xdmauth: data must be a multiple of 8 bytes");
|
||||
strbuf *sb = strbuf_new();
|
||||
put_datapl(sb, data);
|
||||
des_decrypt_xdmauth(key.ptr, sb->u, sb->len);
|
||||
return sb;
|
||||
}
|
||||
|
||||
#define return_void(out, expression) (expression)
|
||||
|
||||
#define VALTYPE_TYPEDEF(n,t,f) \
|
||||
|
|
|
@ -216,6 +216,8 @@ FUNC(int, rsa_ssh1_public_blob_len, val_string_ptrlen)
|
|||
*/
|
||||
FUNC(val_wpoint, ecdsa_public, val_mpint, keyalg)
|
||||
FUNC(val_epoint, eddsa_public, val_mpint, keyalg)
|
||||
FUNC(val_string, des_encrypt_xdmauth, val_string_ptrlen, val_string_ptrlen)
|
||||
FUNC(val_string, des_decrypt_xdmauth, val_string_ptrlen, val_string_ptrlen)
|
||||
|
||||
/*
|
||||
* These functions aren't part of PuTTY's own API, but are additions
|
||||
|
|
Загрузка…
Ссылка в новой задаче