feat: review some code
This commit is contained in:
@@ -344,14 +344,14 @@ size_t additional_input_length;
|
||||
// 主要函数
|
||||
int ChaCha20_DRBG_Instantiate_function(uint8_t *personalization_string,
|
||||
char *state);
|
||||
char *ChaCha20_DRBG_Reseed_function(int state_handle,
|
||||
const char *ChaCha20_DRBG_Reseed_function(int state_handle,
|
||||
uint8_t *additional_input);
|
||||
void ChaCha20_DRBG_Update(const uint8_t *provided_data, uint8_t *V,
|
||||
uint8_t *Key);
|
||||
char *ChaCha20_DRBG_Generate_function(int state_handle,
|
||||
int requested_no_of_bits,
|
||||
uint8_t *additional_input,
|
||||
uint8_t **returned_bits);
|
||||
const char *ChaCha20_DRBG_Generate_function(int state_handle,
|
||||
int requested_no_of_bits,
|
||||
uint8_t *additional_input,
|
||||
uint8_t **returned_bits);
|
||||
|
||||
// 算法函数
|
||||
void ChaCha20_DRBG_Instantiate_algorithm(uint8_t *entropy_input, int nonce,
|
||||
@@ -362,11 +362,11 @@ void ChaCha20_DRBG_Reseed_algorithm(uint8_t *V, uint8_t *Key,
|
||||
int *reseed_counter, int *reseed_time,
|
||||
uint8_t *entropy_input,
|
||||
uint8_t *additional_input);
|
||||
char *ChaCha20_DRBG_Generate_algorithm(uint8_t *V, uint8_t *Key,
|
||||
int *reseed_counter,
|
||||
int requested_number_of_bits,
|
||||
uint8_t *additional_input,
|
||||
uint8_t **returned_bits);
|
||||
const char *ChaCha20_DRBG_Generate_algorithm(uint8_t *V, uint8_t *Key,
|
||||
int *reseed_counter,
|
||||
int requested_number_of_bits,
|
||||
uint8_t *additional_input,
|
||||
uint8_t **returned_bits);
|
||||
|
||||
// 派生函数
|
||||
uint8_t *ChaCha20_df(uint8_t *V, uint8_t *input_string,
|
||||
@@ -391,8 +391,7 @@ int Find_state_space() {
|
||||
}
|
||||
|
||||
void increment_nonce(uint8_t *nonce) {
|
||||
int i = 0;
|
||||
for (i; i < NONCELEN; i++) {
|
||||
for (int i = 0; i < NONCELEN; i++) {
|
||||
nonce[i]++;
|
||||
if (nonce[i] != 0) { // 检查是否有溢出
|
||||
break; // 如果没有溢出,则不需要进位
|
||||
@@ -436,7 +435,7 @@ int ChaCha20_DRBG_Instantiate_function(uint8_t *personalization_string,
|
||||
return state_handle;
|
||||
}
|
||||
|
||||
char *ChaCha20_DRBG_Reseed_function(int state_handle,
|
||||
const char *ChaCha20_DRBG_Reseed_function(int state_handle,
|
||||
uint8_t *additional_input) {
|
||||
// Check for the validity of state_handle.
|
||||
if (!drbg_states[state_handle].used) {
|
||||
@@ -490,14 +489,14 @@ void ChaCha20_DRBG_Update(const uint8_t *provided_data, uint8_t *Key,
|
||||
memcpy(V, temp + KEYLEN, COUNTERLEN);
|
||||
}
|
||||
|
||||
char *ChaCha20_DRBG_Generate_function(int state_handle,
|
||||
const char *ChaCha20_DRBG_Generate_function(int state_handle,
|
||||
int requested_no_of_bits,
|
||||
uint8_t *additional_input,
|
||||
uint8_t **returned_bits) {
|
||||
uint8_t *V;
|
||||
uint8_t *Key;
|
||||
int reseed_counter, reseed_time;
|
||||
char *status;
|
||||
const char *status;
|
||||
|
||||
// Check the validity of state_handle
|
||||
if (!drbg_states[state_handle].V || !drbg_states[state_handle].Key) {
|
||||
@@ -562,10 +561,9 @@ void ChaCha20_DRBG_Instantiate_algorithm(uint8_t *entropy_input, int nonce,
|
||||
size_t personalization_string_len = strlen((char *)personalization_string);
|
||||
size_t seed_material_size =
|
||||
entropy_input_len + sizeof(nonce) + personalization_string_len;
|
||||
uint8_t *seed_material = malloc(seed_material_size);
|
||||
uint8_t *seed_material = (uint8_t *)malloc(seed_material_size);
|
||||
uint8_t *requested_bits;
|
||||
time_t timep;
|
||||
int i = 0;
|
||||
|
||||
memcpy(seed_material, entropy_input, entropy_input_len);
|
||||
memcpy(seed_material + entropy_input_len, &nonce, sizeof(nonce));
|
||||
@@ -592,7 +590,7 @@ void ChaCha20_DRBG_Reseed_algorithm(uint8_t *V, uint8_t *Key,
|
||||
// 1. seed_material = entropy_input || additional_input.
|
||||
size_t seed_material_size =
|
||||
min_entropy_input_length + additional_input_length;
|
||||
uint8_t *seed_material = malloc(seed_material_size);
|
||||
uint8_t *seed_material = (uint8_t *)malloc(seed_material_size);
|
||||
memcpy(seed_material, entropy_input, min_entropy_input_length);
|
||||
memcpy(seed_material + min_entropy_input_length, additional_input,
|
||||
additional_input_length);
|
||||
@@ -612,7 +610,7 @@ void ChaCha20_DRBG_Reseed_algorithm(uint8_t *V, uint8_t *Key,
|
||||
*reseed_time = time(&timep);
|
||||
}
|
||||
|
||||
char *ChaCha20_DRBG_Generate_algorithm(uint8_t *V, uint8_t *Key,
|
||||
const char *ChaCha20_DRBG_Generate_algorithm(uint8_t *V, uint8_t *Key,
|
||||
int *reseed_counter,
|
||||
int requested_number_of_bits,
|
||||
uint8_t *additional_input,
|
||||
@@ -665,7 +663,7 @@ uint8_t *ChaCha20_df(uint8_t *V, uint8_t *input_string,
|
||||
// Pad S with zeros, if necessary.
|
||||
int S_actual_size = S_init_size; // Taken the 0x80 into account
|
||||
while (S_actual_size % OUTLEN != 0) {
|
||||
S = realloc(S, S_actual_size + 1); // Increase size by one byte
|
||||
S = (uint8_t *)realloc(S, S_actual_size + 1); // Increase size by one byte
|
||||
S[S_actual_size++] =
|
||||
0x00; // Add a zero at current end, and increase actual size by one
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user