/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
/* curve 25519 https://www.rfc-editor.org/rfc/rfc7748.txt */
#ifdef FREEBL_NO_DEPEND
#include "../stubs.h"
#endif
#include "ecl-priv.h"
#include "secitem.h"
#include "secerr.h"
#include "secport.h"
#include <stdlib.h>
#include <stdio.h>
/*
* point validation is not necessary in general. But this checks a point (px)
* against some known bad values.
*/
SECStatus
ec_Curve25519_pt_validate(
const SECItem *px)
{
PRUint8 *p;
PRUint64 i;
PRUint8 forbiddenValues[
12 ][
32 ] = {
{
0 x00,
0 x00,
0 x00,
0 x00,
0 x00,
0 x00,
0 x00,
0 x00,
0 x00,
0 x00,
0 x00,
0 x00,
0 x00,
0 x00,
0 x00,
0 x00,
0 x00,
0 x00,
0 x00,
0 x00,
0 x00,
0 x00,
0 x00,
0 x00,
0 x00,
0 x00,
0 x00,
0 x00,
0 x00,
0 x00,
0 x00,
0 x00 },
{
0 x01,
0 x00,
0 x00,
0 x00,
0 x00,
0 x00,
0 x00,
0 x00,
0 x00,
0 x00,
0 x00,
0 x00,
0 x00,
0 x00,
0 x00,
0 x00,
0 x00,
0 x00,
0 x00,
0 x00,
0 x00,
0 x00,
0 x00,
0 x00,
0 x00,
0 x00,
0 x00,
0 x00,
0 x00,
0 x00,
0 x00,
0 x00 },
{
0 xe0,
0 xeb,
0 x7a,
0 x7c,
0 x3b,
0 x41,
0 xb8,
0 xae,
0 x16,
0 x56,
0 xe3,
0 xfa,
0 xf1,
0 x9f,
0 xc4,
0 x6a,
0 xda,
0 x09,
0 x8d,
0 xeb,
0 x9c,
0 x32,
0 xb1,
0 xfd,
0 x86,
0 x62,
0 x05,
0 x16,
0 x5f,
0 x49,
0 xb8,
0 x00 },
{
0 x5f,
0 x9c,
0 x95,
0 xbc,
0 xa3,
0 x50,
0 x8c,
0 x24,
0 xb1,
0 xd0,
0 xb1,
0 x55,
0 x9c,
0 x83,
0 xef,
0 x5b,
0 x04,
0 x44,
0 x5c,
0 xc4,
0 x58,
0 x1c,
0 x8e,
0 x86,
0 xd8,
0 x22,
0 x4e,
0 xdd,
0 xd0,
0 x9f,
0 x11,
0 x57 },
{
0 xec,
0 xff,
0 xff,
0 xff,
0 xff,
0 xff,
0 xff,
0 xff,
0 xff,
0 xff,
0 xff,
0 xff,
0 xff,
0 xff,
0 xff,
0 xff,
0 xff,
0 xff,
0 xff,
0 xff,
0 xff,
0 xff,
0 xff,
0 xff,
0 xff,
0 xff,
0 xff,
0 xff,
0 xff,
0 xff,
0 xff,
0 x7f },
{
0 xed,
0 xff,
0 xff,
0 xff,
0 xff,
0 xff,
0 xff,
0 xff,
0 xff,
0 xff,
0 xff,
0 xff,
0 xff,
0 xff,
0 xff,
0 xff,
0 xff,
0 xff,
0 xff,
0 xff,
0 xff,
0 xff,
0 xff,
0 xff,
0 xff,
0 xff,
0 xff,
0 xff,
0 xff,
0 xff,
0 xff,
0 x7f },
{
0 xee,
0 xff,
0 xff,
0 xff,
0 xff,
0 xff,
0 xff,
0 xff,
0 xff,
0 xff,
0 xff,
0 xff,
0 xff,
0 xff,
0 xff,
0 xff,
0 xff,
0 xff,
0 xff,
0 xff,
0 xff,
0 xff,
0 xff,
0 xff,
0 xff,
0 xff,
0 xff,
0 xff,
0 xff,
0 xff,
0 xff,
0 x7f },
{
0 xcd,
0 xeb,
0 x7a,
0 x7c,
0 x3b,
0 x41,
0 xb8,
0 xae,
0 x16,
0 x56,
0 xe3,
0 xfa,
0 xf1,
0 x9f,
0 xc4,
0 x6a,
0 xda,
0 x09,
0 x8d,
0 xeb,
0 x9c,
0 x32,
0 xb1,
0 xfd,
0 x86,
0 x62,
0 x05,
0 x16,
0 x5f,
0 x49,
0 xb8,
0 x80 },
{
0 x4c,
0 x9c,
0 x95,
0 xbc,
0 xa3,
0 x50,
0 x8c,
0 x24,
0 xb1,
0 xd0,
0 xb1,
0 x55,
0 x9c,
0 x83,
0 xef,
0 x5b,
0 x04,
0 x44,
0 x5c,
0 xc4,
0 x58,
0 x1c,
0 x8e,
0 x86,
0 xd8,
0 x22,
0 x4e,
0 xdd,
0 xd0,
0 x9f,
0 x11,
0 xd7 },
{
0 xd9,
0 xff,
0 xff,
0 xff,
0 xff,
0 xff,
0 xff,
0 xff,
0 xff,
0 xff,
0 xff,
0 xff,
0 xff,
0 xff,
0 xff,
0 xff,
0 xff,
0 xff,
0 xff,
0 xff,
0 xff,
0 xff,
0 xff,
0 xff,
0 xff,
0 xff,
0 xff,
0 xff,
0 xff,
0 xff,
0 xff,
0 xff },
{
0 xda,
0 xff,
0 xff,
0 xff,
0 xff,
0 xff,
0 xff,
0 xff,
0 xff,
0 xff,
0 xff,
0 xff,
0 xff,
0 xff,
0 xff,
0 xff,
0 xff,
0 xff,
0 xff,
0 xff,
0 xff,
0 xff,
0 xff,
0 xff,
0 xff,
0 xff,
0 xff,
0 xff,
0 xff,
0 xff,
0 xff,
0 xff },
{
0 xdb,
0 xff,
0 xff,
0 xff,
0 xff,
0 xff,
0 xff,
0 xff,
0 xff,
0 xff,
0 xff,
0 xff,
0 xff,
0 xff,
0 xff,
0 xff,
0 xff,
0 xff,
0 xff,
0 xff,
0 xff,
0 xff,
0 xff,
0 xff,
0 xff,
0 xff,
0 xff,
0 xff,
0 xff,
0 xff,
0 xff,
0 xff },
};
if (px->len ==
32 ) {
p = px->data;
}
else {
return SECFailure;
}
for (i =
0 ; i < PR_ARRAY_SIZE(forbiddenValues); ++i) {
if (NSS_SecureMemcmp(p, forbiddenValues[i], px->len) ==
0 ) {
return SECFailure;
}
}
return SECSuccess;
}
/*
* scalar validation is not necessary.
*/
SECStatus
ec_Curve25519_scalar_validate(
const SECItem *scalar)
{
if (!scalar || !scalar->data) {
PORT_SetError(SEC_ERROR_INVALID_ARGS);
return SECFailure;
}
if (scalar->len !=
32 ) {
PORT_SetError(SEC_ERROR_BAD_KEY);
return SECFailure;
}
return SECSuccess;
}
/*
* Scalar multiplication for Curve25519.
* If P == NULL, the base point is used.
* Returns X = k*P
*/
SECStatus
ec_Curve25519_pt_mul(SECItem *X, SECItem *k, SECItem *P)
{
PRUint8 *px;
PRUint8 basePoint[
32 ] = {
9 };
if (!P) {
px = basePoint;
}
else {
PORT_Assert(P->len ==
32 );
if (P->len !=
32 ) {
return SECFailure;
}
px = P->data;
}
if (k->len !=
32 ) {
return SECFailure;
}
SECStatus rv = ec_Curve25519_mul(X->data, k->data, px);
if (NSS_SecureMemcmpZero(X->data, X->len) ==
0 ) {
return SECFailure;
}
return rv;
}
Messung V0.5 in Prozent C=97 H=88 G=92
¤ Dauer der Verarbeitung: 0.9 Sekunden
(vorverarbeitet am 2026-06-06)
¤
*© Formatika GbR, Deutschland