mirror of
https://github.com/openpgpjs/openpgpjs.git
synced 2025-11-24 14:35:51 +00:00
Pass curve object instead of oid to checkPublicPointEnconding
This commit is contained in:
parent
89ce97a3e2
commit
698305c0ed
@ -131,7 +131,7 @@ export async function encrypt(oid, kdfParams, data, Q, fingerprint) {
|
||||
const m = pkcs5.encode(data);
|
||||
|
||||
const curve = new CurveWithOID(oid);
|
||||
checkPublicPointEnconding(oid, Q);
|
||||
checkPublicPointEnconding(curve, Q);
|
||||
const { publicKey, sharedKey } = await genPublicEphemeralKey(curve, Q);
|
||||
const param = buildEcdhParam(enums.publicKey.ecdh, oid, kdfParams, fingerprint);
|
||||
const { keySize } = getCipherParams(kdfParams.cipher);
|
||||
@ -194,8 +194,8 @@ async function genPrivateEphemeralKey(curve, V, Q, d) {
|
||||
*/
|
||||
export async function decrypt(oid, kdfParams, V, C, Q, d, fingerprint) {
|
||||
const curve = new CurveWithOID(oid);
|
||||
checkPublicPointEnconding(oid, Q);
|
||||
checkPublicPointEnconding(oid, V);
|
||||
checkPublicPointEnconding(curve, Q);
|
||||
checkPublicPointEnconding(curve, V);
|
||||
const { sharedKey } = await genPrivateEphemeralKey(curve, V, Q, d);
|
||||
const param = buildEcdhParam(enums.publicKey.ecdh, oid, kdfParams, fingerprint);
|
||||
const { keySize } = getCipherParams(kdfParams.cipher);
|
||||
|
||||
@ -46,7 +46,7 @@ const nodeCrypto = util.getNodeCrypto();
|
||||
*/
|
||||
export async function sign(oid, hashAlgo, message, publicKey, privateKey, hashed) {
|
||||
const curve = new CurveWithOID(oid);
|
||||
checkPublicPointEnconding(oid, publicKey);
|
||||
checkPublicPointEnconding(curve, publicKey);
|
||||
if (message && !util.isStream(message)) {
|
||||
const keyPair = { publicKey, privateKey };
|
||||
switch (curve.type) {
|
||||
@ -93,7 +93,7 @@ export async function sign(oid, hashAlgo, message, publicKey, privateKey, hashed
|
||||
*/
|
||||
export async function verify(oid, hashAlgo, signature, message, publicKey, hashed) {
|
||||
const curve = new CurveWithOID(oid);
|
||||
checkPublicPointEnconding(oid, publicKey);
|
||||
checkPublicPointEnconding(curve, publicKey);
|
||||
// See https://github.com/openpgpjs/openpgpjs/pull/948.
|
||||
// NB: the impact was more likely limited to Brainpool curves, since thanks
|
||||
// to WebCrypto availability, NIST curve should not have been affected.
|
||||
|
||||
@ -25,7 +25,7 @@ import nacl from '@openpgp/tweetnacl';
|
||||
import util from '../../../util';
|
||||
import enums from '../../../enums';
|
||||
import hash from '../../hash';
|
||||
import { checkPublicPointEnconding } from './oid_curves';
|
||||
import { CurveWithOID, checkPublicPointEnconding } from './oid_curves';
|
||||
|
||||
/**
|
||||
* Sign a message using the provided legacy EdDSA key
|
||||
@ -42,7 +42,8 @@ import { checkPublicPointEnconding } from './oid_curves';
|
||||
* @async
|
||||
*/
|
||||
export async function sign(oid, hashAlgo, message, publicKey, privateKey, hashed) {
|
||||
checkPublicPointEnconding(oid, publicKey);
|
||||
const curve = new CurveWithOID(oid);
|
||||
checkPublicPointEnconding(curve, publicKey);
|
||||
if (hash.getHashByteLength(hashAlgo) < hash.getHashByteLength(enums.hash.sha256)) {
|
||||
// see https://tools.ietf.org/id/draft-ietf-openpgp-rfc4880bis-10.html#section-15-7.2
|
||||
throw new Error('Hash algorithm too weak for EdDSA.');
|
||||
@ -69,7 +70,8 @@ export async function sign(oid, hashAlgo, message, publicKey, privateKey, hashed
|
||||
* @async
|
||||
*/
|
||||
export async function verify(oid, hashAlgo, { r, s }, m, publicKey, hashed) {
|
||||
checkPublicPointEnconding(oid, publicKey);
|
||||
const curve = new CurveWithOID(oid);
|
||||
checkPublicPointEnconding(curve, publicKey);
|
||||
if (hash.getHashByteLength(hashAlgo) < hash.getHashByteLength(enums.hash.sha256)) {
|
||||
throw new Error('Hash algorithm too weak for EdDSA.');
|
||||
}
|
||||
|
||||
@ -282,9 +282,8 @@ async function validateStandardParams(algo, oid, Q, d) {
|
||||
* Check whether the public point has a valid encoding.
|
||||
* NB: this function does not check e.g. whether the point belongs to the curve.
|
||||
*/
|
||||
function checkPublicPointEnconding(oid, V) {
|
||||
const curveName = oid.getName();
|
||||
const { payloadSize, wireFormatLeadingByte } = curves[curveName];
|
||||
function checkPublicPointEnconding(curve, V) {
|
||||
const { payloadSize, wireFormatLeadingByte, name: curveName } = curve;
|
||||
|
||||
const pointSize = (curveName === enums.curve.curve25519Legacy || curveName === enums.curve.ed25519Legacy) ? payloadSize : payloadSize * 2;
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user