# lpc-rsa
[LPC2xxx related tools running on the host]

RSA key extractor. More...

RSA key extractor.

To use the Public key cryptography routines in the crypto library, you need RSA keys. The ssh-keygen program can generate you an RSA key pair, or you may have received a public key generated by a third party. However, the RSA routines in the crypto library can not work with SSH format keyfiles, they have to be transformed into a different format first. This program does just that.
It reads an SSH format RSA keyfile from the standard input and generates a C file that contains the keys as constant data, in the format that the RSA routines in the library can use. That C file is printed on the standard output. If there's an error the program prints an error message on the standard error.
If you start the program without any command line switches, it will print a usage message and exit.

## Usage

First you need an RSA key. The program can process RSA keys generated by the SSH package's `ssh-keygen` program. If you want to generate your own key (that is, your own private key/public key pair), then you have to run the `ssh-keygen` program:

    ssh-keygen -b key_length -t rsa -f key_file

The `key_length` is the length of the key, in bits. The minimum is 768. The value 1024 is common but 2048 bit long keys are getting popular. The `key_file` argument is the name of the file where you want your key to be stored. Two files are generated by the program, `key_file` and `key_file.pub` of which the former contains your private key and the latter contains the public key. (Note that the private key file actually contains both the private and the public keys) These files look something like this:
`key_file`:

    -----BEGIN RSA PRIVATE KEY-----
    MIICXAIBAAKBgQDBgRtt0/8Xx+QysgZIJDKhem8ZIdMmLUXOtsRNX0QpEiW43uvn
    dFxZJ0fIIbXo9akZhwKd8OiNuOf22FyNBTyb4sIsTgFTntHIa5QMa2vegjjEvFPA
    F50zZ5T2I+3zpsz/I9hPtObGQwfA0ylziSHc86lTOCEJCxMbOCRIOa7KSwIBIwKB
    gDzQzhsz/7cETwieWb7mzhV+QCx4WE3TttqRNmF1tlYNBIqPNDLMzJEMWGN4Tx1U
    hZpPANKNiuq2dMnsOlg02Ig2c5S2oMuT3fxOJn9DUe2w+JlX0zcOM66TE/Ak6q68
    l5Qw83LlkD+rwq/3rLeKIuhtHbU+uo/9No1kyeZe1+A7AkEA/nrg4u0ND+0Mh6PV
    aivxYuSMjQRVgg0kLkZqBDz75k2U0He95nfhEgK6qRJUa8KpDLC1DVxDKryCHhVS
    KbQ1GQJBAMKo/eAr7VtQ9jEYohPG4Y8l8y8ju2hf+wg9p00jV2huks7lmJbpvYLf
    Yed9NDdNORdrjAYWEwB6eh8vdigF4wMCQQDoqtw9MID4njdXcTgmjpONncJVC0bd
    Tdfvy1mdeZXZ4IgPDmR68ULOo2jVGBKrqqkwLIhGusERIWEFj9YXgDCLAkEAliqX
    9hNCEz50xsncHeKQvuLC6dm8dRbXmKSXAP4BmbRin5sskaz/6J2x7RdxbH1mjmjo
    XHdtvopeNVB/uHmR3QJBAM8KaCsomBTERjK7/hpnWXaiCMBo5qFwBhVKNRi0KkHt
    xeeqBo7d19h6FhmtvrzYc+39SH3wTEnWG/xWqam6+fs=
    -----END RSA PRIVATE KEY-----

`key_file.pub`:

    ssh-rsa AAAAB3NzaC1yc2EAAAABIwAAAIEAwYEbbdP/F8fkMrIGSCQyoXpvGSHT
    Ji1FzrbETV9EKRIluN7r53RcWSdHyCG16PWpGYcCnfDojbjn9thcjQU8m+LCLE4B
    U57RyGuUDGtr3oI4xLxTwBedM2eU9iPt86bM/yPYT7TmxkMHwNMpc4kh3POpUzgh
    CQsTGzgkSDmuyks= user@hostname

When you want to transform a keyfile into a format usable by the RSA functions of the crypto library, you have to invoke the `lpc-rsa` program, the one of which the documentation you're now reading:
`lpc-rsa options < key_file > mykeys.c`
That is, the program reads a keyfile generated by `ssh-keygen` on the standard input and generates a C file on the standard output. The C file will contain the RSA key(s) in a format that's usable by the RSA functions in the library.

## Options

- `-private
  -public
  -both
  ` One and only one of the above three options must be given. It makes the program to extract the public key, the private key or both keys, respectively. If, and only if you specified `-public`, then the program accepts a public key file on the input (but it still accepts the private key file as well). For the other two cases you must pass the private key file to the program. Using the public key file might be necessary if the keys are generated by a third party, in which case naturally you only have access the public key.

- `-stem identifier`
  The extracted key(s) are stored in structures. This option sets the name stem for the structures. The default is `rsa`. The structure(s) defined in the C file will be
  `const BC_RSA_PUBLIC_KEY stem_public_key;
  const BC_RSA_PRIVATE_KEY stem_private_key;`
  for the public and/or private key, respectively.

## Exit code

0 : success
1 : command line error
2 : key file error