pubkey-ppk.c 787 B

123456789101112131415161718192021222324252627282930
  1. /*
  2. * Convenience functions to encrypt and decrypt PuTTY's own .PPK
  3. * format for SSH-2 private key files, which uses 256-bit AES in CBC
  4. * mode.
  5. */
  6. #include "ssh.h"
  7. static ssh_cipher *aes256_pubkey_cipher(const void *key, const void *iv)
  8. {
  9. ssh_cipher *cipher = ssh_cipher_new(&ssh_aes256_cbc);
  10. ssh_cipher_setkey(cipher, key);
  11. ssh_cipher_setiv(cipher, iv);
  12. return cipher;
  13. }
  14. void aes256_encrypt_pubkey(const void *key, const void *iv, void *blk, int len)
  15. {
  16. ssh_cipher *c = aes256_pubkey_cipher(key, iv);
  17. ssh_cipher_encrypt(c, blk, len);
  18. ssh_cipher_free(c);
  19. }
  20. void aes256_decrypt_pubkey(const void *key, const void *iv, void *blk, int len)
  21. {
  22. ssh_cipher *c = aes256_pubkey_cipher(key, iv);
  23. ssh_cipher_decrypt(c, blk, len);
  24. ssh_cipher_free(c);
  25. }