void RC5_32_set_key(key, len, data, rounds)
RC5_32_KEY *key;
int len, rounds;
unsigned char *data;
void RC5_32_encrypt(data, key)
unsigned long *data;
RC5_32_KEY *key;
void RC5_32_decrypt(data, key)
unsigned long *data;
RC5_32_KEY *key;
void RC5_32_ecb_encrypt(in, out, key, enc)
unsigned char *in, *out;
RC5_32_KEY *key;
int enc;
void RC5_32_cbc_encrypt(in, out, length, ks, iv, enc)
unsigned char *in, *out;
long length;
RC5_32_KEY *ks;
unsigned char *iv;
int enc;
void RC5_32_cfb64_encrypt(in, out, length, schedule, ivec, num, enc)
unsigned char *in, *out, *ivec;
long length;
RC5_32_KEY *schedule;
int *num, enc;
void RC5_32_ofb64_encrypt(in, out, length, schedule, ivec, num)
unsigned char *in, *out, *ivec;
long length;
RC5_32_KEY *schedule;
int *num;
typedef struct rc5_key_st { /* Number of rounds */ int rounds; RC5_32_INT data[2*(RC5_16_ROUNDS+1)]; } RC5_32_KEY;
This is an expanded form of the actual key.
RC5 is a symmetric block cipher that can operate on varying word sizes, with a varying number of rounds. This library implements RC5-32, which operates on 32-bit words and takes as a data block an 8-byte block. It uses a variable size key, but 128 bit (16 byte) key would normally be considered good, and is used in this implementation, along with 16 rounds. It can be used in all the modes that DES can be used. This library implements the ecb, cbc, cfb64, and ofb64 modes. For more information on these, see the DES encryption modes overview.
All functions that have in and out for arguments may be passed the same argument for both.
The value RC5_ENCRYPT is passed to specify encryption for the functions that require an encryption/decryption flag. RC5_DECRYPT is passed to specify decryption.
Note that triple-RC5 has not been implemented, but if you really feel that you need the security that a 384-bit key provides, you can follow the template of des_ecb3_enc and replace the des_encrypt() calls to RC5_ENCRYPT. The same goes for triple-RC5 in the other modes.
RC5_32_set_key() converts a len-byte key as passed in data into an RC5_32_KEY. An RC5_32_KEY is an expanded form of the key which is used to perform actual encryption. It can be regenerated from the RC5 key so it only needs to be kept when encryption or decryption is about to occur. Don't save or pass around RC5_32_KEYs since they are CPU architecture dependent, the initial data is not.
You also need to specify the number of rounds you want RC5 to do when using this key; this library supports 8, 12 or 16 rounds. You can use one of the predefined names RC5_8_ROUNDS, RC5_12_ROUNDS, or RC5_16_ROUNDS as the rounds argument. If none of these values are used, your choice will be silently discarded and the value RC5_16_ROUNDS used instead.
To generate a password from a text string, you might use MD5 (or the first 16 bytes of SHA-1 output) to produce a 16 byte message digest that can then be passed directly to RC5_32_set_key().
For reading passwords, you can use des_read_pw_string().
RC5_encrypt() is one of the two RC5 encryption functions that get called by just about every other RC5 routine in the library. You should not use this function except to implement modes of RC5. If you do use it you need to do char-to-long conversion beforehand and the reverse after, to make sure 'non-aligned' memory accesses do not occur. See the c2l and l2c routines in RC5_32_locl.h, for example of such routines. See the des_encrypt() man page for use of these routines in implementing various encryption modes from the underlying function.
RC5_decrypt() is the other RC5 encryption function that gets called by just about every other RC5 routine in the library. You should not use this function except to implement modes of RC5; see the warning about RC5_ENCRYPT above.
data is a pointer to 2 unsigned longs and key is the RC5_32_KEY to use.
RC5_32_ecb_encrypt() (Electronic Code Book) encrypts/decrypts in into out using the key given by key. Encryption or decryption is indicated by enc, which can have the values RC5_ENCRYPT or RC5_DECRYPT. in and out must be pointers to 8-byte character arrays.
RC5_32_cbc_encrypt() (Cipher Block Chaining mode) encrypts/decrypts in into out using the key given by ks. Encryption or decryption is indicated by enc, which can have the values RC5_ENCRYPT or RC5_DECRYPT. in and out must be pointers to character arrays that are a multiple of 8 bytes in length, same length for both, given by the argument length. iv is the initialization vector. This function updates iv after each call so that it can be passed to the next call to RC5_32_cbc_encrypt().
RC5_32_cfb64_encrypt() (Cipher Feedback mode with 64-bit feedback) encrypts/decrypts in into out using the key given by schedule. Encryption or decryption is indicated by enc, which can have the values RC5_ENCRYPT or RC5_DECRYPT. in and out must be pointers to character arrays which can be of arbitrary length, given by the argument length. ivec is the initialisation vector. This function updates ivec after each call so that it can be passed to the next call to RC5_32_cfb64_encrypt(). num is also updated to indicate how many bytes of the initialization vector we have used.
RC5_32_ofb64_encrypt() (Output Feedback Mode with 64-bit feedback) encrypts/decrypts in into out using the key given by schedule. in and out must be pointers to character arrays which can be of arbitrary length, given by the argument length. ivec is the initialization vector. This function updates ivec after each call so that it can be passed to the next call to RC5_32_cfb64_encrypt(). num is also updated to indicate how many bytes of the initialization vector we have used.
For more information about the specific RC5 modes in this library (ecb, cbc, cfb and ofb), read the section entitled DES encryption modes overview. What is said about DES is directly applicable for RC5.