Updates for linter

This commit is contained in:
Dan Flack 2024-09-21 11:47:01 +02:00
parent 84ce8e6f30
commit 0f16fa0ce1

View file

@ -12,7 +12,16 @@ import Sm3 from "crypto-api/src/hasher/sm3.mjs";
import {toHex} from "crypto-api/src/encoder/hex.mjs"; import {toHex} from "crypto-api/src/encoder/hex.mjs";
import r from "jsrsasign"; import r from "jsrsasign";
/**
* SM2 Class for encryption and decryption operations
*/
export class SM2 { export class SM2 {
/**
* Constructor for SM2 class; sets up with the curve and the output format as specified in user args
*
* @param {*} curve
* @param {*} format
*/
constructor(curve, format) { constructor(curve, format) {
this.ecParams = null; this.ecParams = null;
this.rng = new r.SecureRandom(); this.rng = new r.SecureRandom();
@ -20,15 +29,15 @@ export class SM2 {
For any additional curve definitions utilized by SM2, add another block like the below for that curve, then add the curve name to the Curve selection dropdown For any additional curve definitions utilized by SM2, add another block like the below for that curve, then add the curve name to the Curve selection dropdown
*/ */
r.crypto.ECParameterDB.regist( r.crypto.ECParameterDB.regist(
'sm2p256v1', // name / p = 2**256 - 2**224 - 2**96 + 2**64 - 1 "sm2p256v1", // name / p = 2**256 - 2**224 - 2**96 + 2**64 - 1
256, 256,
'FFFFFFFEFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF00000000FFFFFFFFFFFFFFFF', // p "FFFFFFFEFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF00000000FFFFFFFFFFFFFFFF", // p
'FFFFFFFEFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF00000000FFFFFFFFFFFFFFFC', // a "FFFFFFFEFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF00000000FFFFFFFFFFFFFFFC", // a
'28E9FA9E9D9F5E344D5A9E4BCF6509A7F39789F515AB8F92DDBCBD414D940E93', // b "28E9FA9E9D9F5E344D5A9E4BCF6509A7F39789F515AB8F92DDBCBD414D940E93", // b
'FFFFFFFEFFFFFFFFFFFFFFFFFFFFFFFF7203DF6B21C6052B53BBF40939D54123', // n "FFFFFFFEFFFFFFFFFFFFFFFFFFFFFFFF7203DF6B21C6052B53BBF40939D54123", // n
'1', // h "1", // h
'32C4AE2C1F1981195F9904466A39C9948FE30BBFF2660BE1715A4589334C74C7', // gx "32C4AE2C1F1981195F9904466A39C9948FE30BBFF2660BE1715A4589334C74C7", // gx
'BC3736A2F4F6779C59BDCEE36B692153D0A9877CC62A474002DF32E52139F0A0', // gy "BC3736A2F4F6779C59BDCEE36B692153D0A9877CC62A474002DF32E52139F0A0", // gy
[] []
) // alias ) // alias
this.ecParams = r.crypto.ECParameterDB.getByName(curve); this.ecParams = r.crypto.ECParameterDB.getByName(curve);
@ -38,9 +47,9 @@ export class SM2 {
/** /**
* Set the public key coordinates for the SM2 class * Set the public key coordinates for the SM2 class
* *
* @param {string} publicKeyX * @param {string} publicKeyX
* @param {string} publicKeyY * @param {string} publicKeyY
*/ */
setPublicKey(publicKeyX, publicKeyY) { setPublicKey(publicKeyX, publicKeyY) {
/* /*
@ -56,17 +65,17 @@ export class SM2 {
/** /**
* Set the private key value for the SM2 class * Set the private key value for the SM2 class
* *
* @param {string} privateKey * @param {string} privateKey
*/ */
setPrivateKey(privateKeyHex) { setPrivateKey(privateKeyHex) {
this.privateKey = new r.BigInteger(privateKeyHex, 16); this.privateKey = new r.BigInteger(privateKeyHex, 16);
} }
/** /**
* Main encryption function; takes user input, processes encryption and returns the result in hex (with the components arranged as configured by the user args) * Main encryption function; takes user input, processes encryption and returns the result in hex (with the components arranged as configured by the user args)
* *
* @param {*} input * @param {*} input
* @returns {string} * @returns {string}
*/ */
encrypt(input) { encrypt(input) {
@ -111,8 +120,8 @@ export class SM2 {
} }
/** /**
* Function to decrypt an SM2 encrypted message * Function to decrypt an SM2 encrypted message
* *
* @param {*} input * @param {*} input
*/ */
decrypt(input) { decrypt(input) {
var c1X = input.slice(0, 64); var c1X = input.slice(0, 64);