pubkey-pem.c 944 B

123456789101112131415161718192021222324252627282930313233
  1. /*
  2. * Convenience functions to encrypt and decrypt OpenSSH PEM format for
  3. * SSH-2 private key files. This uses triple-DES in SSH-2 style (one
  4. * CBC layer), with three distinct keys, and an IV also generated from
  5. * the passphrase.
  6. */
  7. #include "ssh.h"
  8. static ssh_cipher *des3_pubkey_ossh_cipher(const void *vkey, const void *viv)
  9. {
  10. ssh_cipher *c = ssh_cipher_new(&ssh_3des_ssh2);
  11. ssh_cipher_setkey(c, vkey);
  12. ssh_cipher_setiv(c, viv);
  13. return c;
  14. }
  15. void des3_decrypt_pubkey_ossh(const void *vkey, const void *viv,
  16. void *vblk, int len)
  17. {
  18. ssh_cipher *c = des3_pubkey_ossh_cipher(vkey, viv);
  19. ssh_cipher_decrypt(c, vblk, len);
  20. ssh_cipher_free(c);
  21. }
  22. void des3_encrypt_pubkey_ossh(const void *vkey, const void *viv,
  23. void *vblk, int len)
  24. {
  25. ssh_cipher *c = des3_pubkey_ossh_cipher(vkey, viv);
  26. ssh_cipher_encrypt(c, vblk, len);
  27. ssh_cipher_free(c);
  28. }