-static EC_POINT * alloc_elem(EC_GROUP *group, const u8 *val, size_t len)
-{
- BIGNUM *x, *y;
- EC_POINT *elem;
-
- x = BN_bin2bn(val, len, NULL);
- y = BN_bin2bn(val + len, len, NULL);
- elem = EC_POINT_new(group);
- if (x == NULL || y == NULL || elem == NULL) {
- BN_free(x);
- BN_free(y);
- EC_POINT_free(elem);
- return NULL;
- }
-
- if (!EC_POINT_set_affine_coordinates_GFp(group, elem, x, y, NULL)) {
- EC_POINT_free(elem);
- elem = NULL;
- }
-
- BN_free(x);
- BN_free(y);
-
- return elem;
-}
-
-
-static void sae_bn_to_bin(const BIGNUM *bn, u8 *bin, size_t len)
-{
- int offset = len - BN_num_bytes(bn);
- os_memset(bin, 0, offset);
- BN_bn2bin(bn, bin + offset);
-}
-
-
-static int sae_ec_point_to_bin(BN_CTX *bnctx, EC_GROUP *group, EC_POINT *point,
- u8 *bin)
-{
- BIGNUM *x, *y;
- int ret = -1;
-
- x = BN_new();
- y = BN_new();
-
- if (x && y &&
- EC_POINT_get_affine_coordinates_GFp(group, point, x, y, bnctx)) {
- sae_bn_to_bin(x, bin, 32);
- sae_bn_to_bin(y, bin + 32, 32);
- ret = 0;
- }
-
- BN_free(x);
- BN_free(y);
- return ret;
-}
-
-