Nebula
Nebula
rc5.h 文件参考
+ rc5.h 的引用(Include)关系图:
+ 此图展示该文件直接或间接的被哪些文件引用了:

struct  rc5UserKey
 Definition of RC5 user key object. 更多...
 
struct  rc5CBCAlg
 Definition of the RC5 CBC algorithm object. 更多...
 

宏定义

#define RC5_FIRST_VERSION   1
 
#define RC5_WORD   unsigned int
 
#define W   (32)
 
#define WW   (W / 8)
 
#define ROT_MASK   (W - 1)
 
#define BB   ((2 * W) / 8) /* Bytes per block */
 
#define SHL(x, s)   ((RC5_WORD)((x)<<((s)&ROT_MASK)))
 
#define SHR(x, s, w)   ((RC5_WORD)((x)>>((w)-((s)&ROT_MASK))))
 
#define ROTL(x, s, w)   ((RC5_WORD)(SHL((x),(s))|SHR((x),(s),(w))))
 
#define SHL1(x, s, w)   ((RC5_WORD)((x)<<((w)-((s)&ROT_MASK))))
 
#define SHR1(x, s)   ((RC5_WORD)((x)>>((s)&ROT_MASK)))
 
#define ROTR(x, s, w)   ((RC5_WORD)(SHR1((x),(s))|SHL1((x),(s),(w))))
 
#define P16   0xb7e1
 
#define Q16   0x9e37
 
#define P32   0xb7e15163
 
#define Q32   0x9e3779b9
 
#define P64   0xb7e151628aed2a6b
 
#define Q64   0x9e3779b97f4a7c15
 
#define Pw   P32 /* Select 32 bit word size */
 
#define Qw   Q32
 

类型定义

typedef struct rc5UserKey rc5UserKey
 Definition of RC5 user key object. 更多...
 
typedef struct rc5CBCAlg rc5CBCAlg
 Definition of the RC5 CBC algorithm object. 更多...
 

函数

rc5UserKeyRC5_Key_Create ()
 Allocate and initialize an RC5 user key. 更多...
 
void RC5_Key_Destroy (rc5UserKey *pKey)
 Zero and free an RC5 user key. 更多...
 
int RC5_Key_Set (rc5UserKey *pKey, int keyLength, unsigned char *keyBytes)
 Set the value of an RC5 user key. 更多...
 
void RC5_Key_Expand (int b, unsigned char *K, int R, RC5_WORD *S)
 Expand an RC5 user key. 更多...
 
void RC5_Block_Encrypt (RC5_WORD *S, int R, unsigned char *in, unsigned char *out)
 encryption of a single input block 更多...
 
void RC5_Block_Decrypt (RC5_WORD *S, int R, unsigned char *in, unsigned char *out)
 
rc5CBCAlgRC5_CBC_Create (int Pad, int R, int Version, int bb, unsigned char *I)
 Allocate and initialize the RC5 CBC algorithm object. 更多...
 
void RC5_CBC_Destroy (rc5CBCAlg *pAlg)
 Zero and free an RC5 algorithm object. 更多...
 
int RC5_CBC_SetIV (rc5CBCAlg *pAlg, unsigned char *I)
 Setup a new initialization vector for a CBC operation and reset the CBC object. 更多...
 
int RC5_CBC_Encrypt_Init (rc5CBCAlg *pAlg, rc5UserKey *pKey)
 Binding a key to a cipher object. 更多...
 
int RC5_CBC_Encrypt_Update (rc5CBCAlg *pAlg, int N, unsigned char *P, int *pCipherLen, int maxCipherLen, unsigned char *C)
 Encrypt a buffer of plaintext. 更多...
 
int RC5_CBC_Encrypt_Final (rc5CBCAlg *pAlg, int *pCipherLen, int maxCipherLen, unsigned char *C)
 Produce the final block of ciphertext including any padding, and then reset the algorithm object. 更多...
 
int RC5_CBC_Decrypt_Init (rc5CBCAlg *pAlg, rc5UserKey *pKey)
 
int RC5_CBC_Decrypt_Update (rc5CBCAlg *pAlg, int N, unsigned char *C, int *plainLen, unsigned char *P)
 

宏定义说明

#define BB   ((2 * W) / 8) /* Bytes per block */
#define P16   0xb7e1

Two constants, Pw and Qw, are defined for any word size W by the expressions: Pw=Odd((e-2)*2**W) Qw=Odd((phi-1)*2**W) e是自然对数的底(2.71828...),phi是黄金比例(1.61803...),2**W是2的W 此方,Odd(x)等于x如果x是奇数或等于x+1如果x是偶数。W等于16,32和64,Pw和 where e is the base of the natural logarithm (2.71828 ...), and phi is the golden ratio (1.61803 ...), and 2**W is 2 raised to the power of W, and Odd(x) is equal to x if x is odd, or equal to x plus one if x is even. For W equal to 16, 32, and 64, the Pw and Qw constants are the following hexadecimal values:

#define P32   0xb7e15163
#define P64   0xb7e151628aed2a6b
#define Pw   P32 /* Select 32 bit word size */
#define Q16   0x9e37
#define Q32   0x9e3779b9
#define Q64   0x9e3779b97f4a7c15
#define Qw   Q32
#define RC5_FIRST_VERSION   1
#define RC5_WORD   unsigned int
#define ROT_MASK   (W - 1)
#define ROTL (   x,
  s,
 
)    ((RC5_WORD)(SHL((x),(s))|SHR((x),(s),(w))))
#define ROTR (   x,
  s,
 
)    ((RC5_WORD)(SHR1((x),(s))|SHL1((x),(s),(w))))
#define SHL (   x,
 
)    ((RC5_WORD)((x)<<((s)&ROT_MASK)))
#define SHL1 (   x,
  s,
 
)    ((RC5_WORD)((x)<<((w)-((s)&ROT_MASK))))
#define SHR (   x,
  s,
 
)    ((RC5_WORD)((x)>>((w)-((s)&ROT_MASK))))
#define SHR1 (   x,
 
)    ((RC5_WORD)((x)>>((s)&ROT_MASK)))
#define W   (32)
#define WW   (W / 8)

类型定义说明

typedef struct rc5CBCAlg rc5CBCAlg

Definition of the RC5 CBC algorithm object.

注解
The cipher object needs to keep track of the padding mode, the number of rounds, the expanded key, the initialization vector, the CBC chaining block, and an input buffer.
typedef struct rc5UserKey rc5UserKey

Definition of RC5 user key object.

注解
Like most block ciphers, RC5 expands a small user key into a table of internal keys. The byte length of the user key is one of the parameters of the cipher, so the RC5 user key object must be able to hold variable length keys. The basic operations on a key are to create, destroy and set. To avoid exposing key material to other parts of an application, the destroy operation zeros the memory allocated for the key before releasing it to the memory manager. A general key object may support other operations such as generating a new random key and deriving a key from key-agreement information.

函数说明

void RC5_Block_Decrypt ( RC5_WORD S,
int  R,
unsigned char *  in,
unsigned char *  out 
)

+ 这是这个函数的调用关系图:

void RC5_Block_Encrypt ( RC5_WORD S,
int  R,
unsigned char *  in,
unsigned char *  out 
)

encryption of a single input block

参数
S
R
in
out

+ 这是这个函数的调用关系图:

rc5CBCAlg* RC5_CBC_Create ( int  Pad,
int  R,
int  Version,
int  bb,
unsigned char *  I 
)

Allocate and initialize the RC5 CBC algorithm object.

注解
To create a cipher algorithm object, the parameters must be checked and then space allocated for the expanded key table. The expanded key is initialized using the method described earlier. Finally, the state variables (padding mode, number of rounds, and the input buffer) are set to their initial values.
参数
Pad1 = RC5-CBC-Pad, 0 = RC5-CBC.
RNumber of rounds.
VersionRC5 version number.
bbBytes per RC5 block == IV len.
ICBC IV, bb bytes long.
返回
Return 0 if problems.
int RC5_CBC_Decrypt_Init ( rc5CBCAlg pAlg,
rc5UserKey pKey 
)

+ 函数调用图:

int RC5_CBC_Decrypt_Update ( rc5CBCAlg pAlg,
int  N,
unsigned char *  C,
int *  plainLen,
unsigned char *  P 
)

+ 函数调用图:

void RC5_CBC_Destroy ( rc5CBCAlg pAlg)

Zero and free an RC5 algorithm object.

注解
Destroying the cipher object is the inverse of creating it with care being take to zero memory before returning it to the memory manager.
参数
pAlgRC5 CBC algorithm object
int RC5_CBC_Encrypt_Final ( rc5CBCAlg pAlg,
int *  pCipherLen,
int  maxCipherLen,
unsigned char *  C 
)

Produce the final block of ciphertext including any padding, and then reset the algorithm object.

注解
This step handles the last block of plaintext. For RC5-CBC, this step just performs error checking to ensure that the plaintext length was indeed a multiple of the block length. For RC5-CBC-Pad, padding bytes are added to the plaintext. The pad bytes are all the same and are set to a byte that represents the number of bytes of padding. For example if there are eight bytes of padding, the bytes will all have the hexadecimal value 0x08. There will be between one and BB padding bytes, inclusive.
参数
pAlgCipher algorithm object.
pCipherLenGets byte len of C.
maxCipherLenLen of C buffer.
CCiphertext buffer.
返回
Return zero if problems.

+ 函数调用图:

int RC5_CBC_Encrypt_Init ( rc5CBCAlg pAlg,
rc5UserKey pKey 
)

Binding a key to a cipher object.

注解
Initialize the encryption object with the given key. After this routine, the caller frees the key object. The IV for this CBC object can be changed by calling the SetIV routine. The only way to change the key is to destroy the CBC object and create a new one. The operation that binds a key to a cipher object performs the key expansion. Key expansion could be an operation on keys, but that would not work correctly for ciphers that modify the expanded key as they operate. After expanding the key, this operation must initialize the CBC chain block from the initialization vector and prepare the input buffer to receive the first character.
参数
pAlgRC5 CBC algorithm object
pKeyuser key
返回
Return zero if problems.

+ 函数调用图:

int RC5_CBC_Encrypt_Update ( rc5CBCAlg pAlg,
int  N,
unsigned char *  P,
int *  pCipherLen,
int  maxCipherLen,
unsigned char *  C 
)

Encrypt a buffer of plaintext.

注解
The plaintext and ciphertext buffers can be the same. The byte len of the ciphertext is put in *pCipherLen. Call this multiple times passing successive parts of a large message. After the last part has been passed to Update, call Final. The encryption process described here uses the Init-Update-Final paradigm. The update operation can be performed on a sequence of message parts in order to incrementally produce the ciphertext. After the last part is processed, the Final operation is called to pick up any plaintext bytes or padding that are buffered inside the cipher object.
参数
pAlgCipher algorithm object.
NByte length of P.
PPlaintext buffer.
pCipherLenGets byte len of C.
maxCipherLenSize of C.
CCiphertext buffer.
返回
Return zero if problems like output buffer too small.

+ 函数调用图:

int RC5_CBC_SetIV ( rc5CBCAlg pAlg,
unsigned char *  I 
)

Setup a new initialization vector for a CBC operation and reset the CBC object.

注解
This can be called after Final without needing to call Init or Create again. For CBC cipher objects, the state of the algorithm depends on the expanded key, the CBC chain block, and any internally buffered input. Often the same key is used with many messages that each have a unique initialization vector. To avoid the overhead of creating a new cipher object, it makes more sense to provide an operation that allows the caller to change the initialization vector for an existing cipher object.
参数
pAlgRC5 CBC algorithm object
ICBC Initialization vector, BB bytes.
返回
Return zero if problems.

+ 这是这个函数的调用关系图:

rc5UserKey* RC5_Key_Create ( )

Allocate and initialize an RC5 user key.

注解
To create a key, the memory for the key object must be allocated and initialized. The C code below assumes that a function called "malloc" will return a block of uninitialized memory from the heap, or zero indicating an error.
返回
Return 0 if problems.
void RC5_Key_Destroy ( rc5UserKey pKey)

Zero and free an RC5 user key.

注解
To destroy a key, the memory must be zeroed and released to the memory manager. The C code below assumes that a function called "free" will return a block of memory to the heap.
参数
pKeyuser key
void RC5_Key_Expand ( int  b,
unsigned char *  K,
int  R,
RC5_WORD S 
)

Expand an RC5 user key.

注解
The key expansion routine converts the b-byte secret key, K, into an expanded key, S, which is a sequence of T = 2*(R+1) words. The expansion algorithm uses two constants that are derived from the constants, e, and phi. These are used to initialize S, which is then modified using K.
参数
bByte length of secret key
KSecret key
RNumber of rounds
SExpanded key buffer, 2*(R+1) words

+ 这是这个函数的调用关系图:

int RC5_Key_Set ( rc5UserKey pKey,
int  keyLength,
unsigned char *  keyBytes 
)

Set the value of an RC5 user key.

注解
Setting the key object makes a copy of the secret key into a block of memory allocated from the heap. Copy the key bytes so the caller can zero and free the original.
参数
pKeyuser key
keyLengthuser key length
keyBytesuser key bytes
返回
Return zero if problems