mirror of
https://github.com/RIOT-OS/RIOT.git
synced 2024-12-29 04:50:03 +01:00
Merge pull request #5908 from mtausig/ciphers_doc
ciphers: Documented return values of init functions
This commit is contained in:
commit
1eae646de7
@ -259,7 +259,7 @@ int tripledes_init(cipher_context_t *context, const uint8_t *key,
|
|||||||
// Make sure that context is large enough. If this is not the case,
|
// Make sure that context is large enough. If this is not the case,
|
||||||
// you should build with -DTHREEDES
|
// you should build with -DTHREEDES
|
||||||
if(CIPHER_MAX_CONTEXT_SIZE < THREEDES_MAX_KEY_SIZE) {
|
if(CIPHER_MAX_CONTEXT_SIZE < THREEDES_MAX_KEY_SIZE) {
|
||||||
return 0;
|
return CIPHER_ERR_BAD_CONTEXT_SIZE;
|
||||||
}
|
}
|
||||||
|
|
||||||
//key must be at least 24 Bytes long
|
//key must be at least 24 Bytes long
|
||||||
@ -275,7 +275,7 @@ int tripledes_init(cipher_context_t *context, const uint8_t *key,
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return 1;
|
return CIPHER_INIT_SUCCESS;
|
||||||
}
|
}
|
||||||
|
|
||||||
int tripledes_encrypt(const cipher_context_t *context, const uint8_t *plain, uint8_t *crypt)
|
int tripledes_encrypt(const cipher_context_t *context, const uint8_t *plain, uint8_t *crypt)
|
||||||
|
@ -727,7 +727,7 @@ int aes_init(cipher_context_t *context, const uint8_t *key, uint8_t keySize)
|
|||||||
// Make sure that context is large enough. If this is not the case,
|
// Make sure that context is large enough. If this is not the case,
|
||||||
// you should build with -DAES
|
// you should build with -DAES
|
||||||
if(CIPHER_MAX_CONTEXT_SIZE < AES_KEY_SIZE) {
|
if(CIPHER_MAX_CONTEXT_SIZE < AES_KEY_SIZE) {
|
||||||
return 0;
|
return CIPHER_ERR_BAD_CONTEXT_SIZE;
|
||||||
}
|
}
|
||||||
|
|
||||||
//key must be at least CIPHERS_MAX_KEY_SIZE Bytes long
|
//key must be at least CIPHERS_MAX_KEY_SIZE Bytes long
|
||||||
@ -743,7 +743,7 @@ int aes_init(cipher_context_t *context, const uint8_t *key, uint8_t keySize)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return 1;
|
return CIPHER_INIT_SUCCESS;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -483,7 +483,7 @@ int twofish_init(cipher_context_t *context, const uint8_t *key,
|
|||||||
// Make sure that context is large enough. If this is not the case,
|
// Make sure that context is large enough. If this is not the case,
|
||||||
// you should build with -DTWOFISH.
|
// you should build with -DTWOFISH.
|
||||||
if(CIPHER_MAX_CONTEXT_SIZE < TWOFISH_CONTEXT_SIZE) {
|
if(CIPHER_MAX_CONTEXT_SIZE < TWOFISH_CONTEXT_SIZE) {
|
||||||
return 0;
|
return CIPHER_ERR_BAD_CONTEXT_SIZE;
|
||||||
}
|
}
|
||||||
|
|
||||||
//key must be at least CIPHERS_MAX_KEY_SIZE Bytes long
|
//key must be at least CIPHERS_MAX_KEY_SIZE Bytes long
|
||||||
@ -499,7 +499,7 @@ int twofish_init(cipher_context_t *context, const uint8_t *key,
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return 1;
|
return CIPHER_INIT_SUCCESS;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -85,8 +85,9 @@ static const uint32_t bigbyte[24] = {
|
|||||||
* @param keySize the size of the key
|
* @param keySize the size of the key
|
||||||
|
|
||||||
*
|
*
|
||||||
* @return Whether initialization was successful. The command may be
|
* @return CIPHER_INIT_SUCCESS if the initialization was successful.
|
||||||
* unsuccessful if the key size is not valid.
|
* The command may be unsuccessful if the key size is not valid.
|
||||||
|
* CIPHER_ERR_BAD_CONTEXT_SIZE if CIPHER_MAX_CONTEXT_SIZE has not been defined (which means that the cipher has not been included in the build)
|
||||||
*/
|
*/
|
||||||
int tripledes_init(cipher_context_t *context, const uint8_t* key, uint8_t keySize);
|
int tripledes_init(cipher_context_t *context, const uint8_t* key, uint8_t keySize);
|
||||||
|
|
||||||
|
@ -80,8 +80,9 @@ typedef struct {
|
|||||||
* @param keySize the size of the key
|
* @param keySize the size of the key
|
||||||
* @param key a pointer to the key
|
* @param key a pointer to the key
|
||||||
*
|
*
|
||||||
* @return Whether initialization was successful. The command may be
|
* @return CIPHER_INIT_SUCCESS if the initialization was successful.
|
||||||
* unsuccessful if the key size is not valid.
|
* The command may be unsuccessful if the key size is not valid.
|
||||||
|
* CIPHER_ERR_BAD_CONTEXT_SIZE if CIPHER_MAX_CONTEXT_SIZE has not been defined (which means that the cipher has not been included in the build)
|
||||||
*/
|
*/
|
||||||
int aes_init(cipher_context_t *context, const uint8_t *key, uint8_t keySize);
|
int aes_init(cipher_context_t *context, const uint8_t *key, uint8_t keySize);
|
||||||
|
|
||||||
|
@ -61,13 +61,16 @@ extern "C" {
|
|||||||
#define CIPHER_MAX_CONTEXT_SIZE 1
|
#define CIPHER_MAX_CONTEXT_SIZE 1
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
/**
|
/* return codes */
|
||||||
* error codes
|
|
||||||
*/
|
|
||||||
#define CIPHER_ERR_INVALID_KEY_SIZE -3
|
#define CIPHER_ERR_INVALID_KEY_SIZE -3
|
||||||
#define CIPHER_ERR_INVALID_LENGTH -4
|
#define CIPHER_ERR_INVALID_LENGTH -4
|
||||||
#define CIPHER_ERR_ENC_FAILED -5
|
#define CIPHER_ERR_ENC_FAILED -5
|
||||||
#define CIPHER_ERR_DEC_FAILED -6
|
#define CIPHER_ERR_DEC_FAILED -6
|
||||||
|
/** Is returned by the cipher_init functions, if the coresponding alogirithm has not been included in the build */
|
||||||
|
#define CIPHER_ERR_BAD_CONTEXT_SIZE 0
|
||||||
|
/** Returned by cipher_init upon succesful initialization of a cipher. */
|
||||||
|
#define CIPHER_INIT_SUCCESS 1
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief the context for cipher-operations
|
* @brief the context for cipher-operations
|
||||||
@ -126,6 +129,10 @@ typedef struct {
|
|||||||
* @param cipher_id cipher algorithm id
|
* @param cipher_id cipher algorithm id
|
||||||
* @param key encryption key to use
|
* @param key encryption key to use
|
||||||
* @param key_size length of the encryption key
|
* @param key_size length of the encryption key
|
||||||
|
*
|
||||||
|
* @return CIPHER_INIT_SUCCESS if the initialization was successful.
|
||||||
|
* The command may be unsuccessful if the key size is not valid.
|
||||||
|
* CIPHER_ERR_BAD_CONTEXT_SIZE if CIPHER_MAX_CONTEXT_SIZE has not been defined (which means that the cipher has not been included in the build)
|
||||||
*/
|
*/
|
||||||
int cipher_init(cipher_t* cipher, cipher_id_t cipher_id, const uint8_t* key,
|
int cipher_init(cipher_t* cipher, cipher_id_t cipher_id, const uint8_t* key,
|
||||||
uint8_t key_size);
|
uint8_t key_size);
|
||||||
|
@ -222,8 +222,9 @@ typedef struct {
|
|||||||
* @param key_size key size in bytes
|
* @param key_size key size in bytes
|
||||||
* @param key pointer to the key
|
* @param key pointer to the key
|
||||||
*
|
*
|
||||||
* @return Whether initialization was successful. The command may be
|
* @return CIPHER_INIT_SUCCESS if the initialization was successful.
|
||||||
* unsuccessful if the key size is not valid.
|
* The command may be unsuccessful if the key size is not valid.
|
||||||
|
* CIPHER_ERR_BAD_CONTEXT_SIZE if CIPHER_MAX_CONTEXT_SIZE has not been defined (which means that the cipher has not been included in the build)
|
||||||
*/
|
*/
|
||||||
int twofish_init(cipher_context_t *context, const uint8_t *key, uint8_t key_size);
|
int twofish_init(cipher_context_t *context, const uint8_t *key, uint8_t key_size);
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user