SSH Interface


SILC SSH Library provides SSH2 public key and private key support for applications. The SILC SSH Library has been integrated to the SILC Crypto Toolkit allowing easy use of the SSH keys through the SILC PKCS API. The interface provides also a low level API to directly manipulate the SSH keys.

The library supports creation of new SSH2 key pairs, encryption, decryption, signatures and verification. Both RSA and DSS SSH2 keys are supported. The library supports the standard SSH2 public key file format defined in RFC 4716 and the OpenSSH public key file format. The private key file format support includes OpenSSH private key files. The signature format is compliant with the SSH2 protocol.


 SilcPublicKey public_key;
 SilcPrivateKey private_key;
 SilcSshPublicKey ssh_pubkey;
 SilcSshPrivateKey ssh_privkey;

 // Generate new SSH2 key pair, RSA algorithm, 2048 bits
 silc_ssh_generate_key("rsa", 2048, rng, "",
                       &public_key, &private_key);

 // Add (optional) headers to the key before saving to a file
 ssh_pubkey = silc_pkcs_public_key_get_pkcs(SILC_PKCS_SSH2, public_key);
 silc_ssh_public_key_set_type(ssh_pubkey, SILC_SSH_KEY_SSH2);
 silc_ssh_public_key_add_field(ssh_pubkey, "Comment", "My own key");

 // Rest of the operations use standard SILC PKCS API

 // Save new key pair to file
 silc_pkcs_save_public_key("", public_key, SILC_PKCS_FILE_BASE64);
 silc_pkcs_save_private_key("privkey.prv", private_key, passphrase,
                            passphrase_len, SILC_PKCS_FILE_BASE64, rng);

 // Load SSH2 key pair
 silc_pkcs_load_public_key("", SILC_PKCS_SSH2, &public_key);
 silc_pkcs_load_private_key("privkey.prv", passphrase, passphrase_len,
                            SILC_PKCS_SSH2, &public_key);

 // Free public and private key. Frees automatically the underlaying SSH keys.