pubkey-ssh1.c 957 B

123456789101112131415161718192021222324252627282930313233343536373839
  1. /*
  2. * Convenience functions to encrypt and decrypt the standard format
  3. * for SSH-1 private key files. This uses triple-DES in SSH-1 style
  4. * (three separate CBC layers), but the same key is used for the first
  5. * and third layers.CBC mode.
  6. */
  7. #include "ssh.h"
  8. static ssh_cipher *des3_pubkey_cipher(const void *vkey)
  9. {
  10. ssh_cipher *c = ssh_cipher_new(&ssh_3des_ssh1);
  11. uint8_t keys3[24], iv[8];
  12. memcpy(keys3, vkey, 16);
  13. memcpy(keys3 + 16, vkey, 8);
  14. ssh_cipher_setkey(c, keys3);
  15. smemclr(keys3, sizeof(keys3));
  16. memset(iv, 0, 8);
  17. ssh_cipher_setiv(c, iv);
  18. return c;
  19. }
  20. void des3_decrypt_pubkey(const void *vkey, void *vblk, int len)
  21. {
  22. ssh_cipher *c = des3_pubkey_cipher(vkey);
  23. ssh_cipher_decrypt(c, vblk, len);
  24. ssh_cipher_free(c);
  25. }
  26. void des3_encrypt_pubkey(const void *vkey, void *vblk, int len)
  27. {
  28. ssh_cipher *c = des3_pubkey_cipher(vkey);
  29. ssh_cipher_encrypt(c, vblk, len);
  30. ssh_cipher_free(c);
  31. }