* This file is part of the openHiTLS project.
*
* openHiTLS is licensed under the Mulan PSL v2.
* You can use this software according to the terms and conditions of the Mulan PSL v2.
* You may obtain a copy of Mulan PSL v2 at:
*
* http://license.coscl.org.cn/MulanPSL2
*
* THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND,
* EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT,
* MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE.
* See the Mulan PSL v2 for more details.
*/
#ifndef ECC_UTILS_H
#define ECC_UTILS_H
#include "hitls_build.h"
#ifdef HITLS_CRYPTO_ECC
#include "crypt_ecc.h"
#include "ecc_local.h"
#include "crypt_errno.h"
#ifdef __cplusplus
extern "C" {
#endif
#define WINDOW_SIZE 5
* Decoded from a 6-bit signed code to obtain the sign and value. The upper five bits are the complement of the value,
* and the least significant bit is the carry (positive) of the next group of numbers.
* Output:
* sign = 0 or 1
* 0 <= value <= 16
*/
inline static void DecodeScalarCode(uint32_t *sign, uint32_t *value, uint32_t code)
{
uint32_t s, v;
s = 0 - (code >> WINDOW_SIZE);
v = (code >> 1) + (code & 1);
v = (~s & v) | (s & (~v + 1));
*sign = s & 1;
*value = v & ((1 << WINDOW_SIZE) - 1);
}
inline static int32_t CheckBnValid(const BN_BigNum *k, uint32_t maxBits)
{
if (BN_Bits(k) > maxBits) {
return CRYPT_ECC_POINT_MUL_ERR_K_LEN;
}
return CRYPT_SUCCESS;
}
#ifdef __cplusplus
}
#endif
#endif
#endif