-
Notifications
You must be signed in to change notification settings - Fork 3.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'SM3' of https://github.com/n1073645/CyberChef into n107…
…3645-SM3
- Loading branch information
Showing
7 changed files
with
100 additions
and
14 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -319,6 +319,7 @@ | |
"SHA1", | ||
"SHA2", | ||
"SHA3", | ||
"SM3", | ||
"Keccak", | ||
"Shake", | ||
"RIPEMD", | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
/** | ||
* @author n1073645 [n1073645@gmail.com] | ||
* @copyright Crown Copyright 2020 | ||
* @license Apache-2.0 | ||
*/ | ||
|
||
import Operation from "../Operation.mjs"; | ||
import Utils from "../Utils.mjs"; | ||
import Sm3 from "crypto-api/src/hasher/sm3"; | ||
import {toHex} from "crypto-api/src/encoder/hex"; | ||
|
||
/** | ||
* SM3 operation | ||
*/ | ||
class SM3 extends Operation { | ||
|
||
/** | ||
* SM3 constructor | ||
*/ | ||
constructor() { | ||
super(); | ||
|
||
this.name = "SM3"; | ||
this.module = "Crypto"; | ||
this.description = "SM3 is a cryptographic hash function used in the Chinese National Standard. SM3 is mainly used in digital signatures, message authentication codes, and pseudorandom number generators. The message digest algorithm consists, by default, of 64 rounds and length of 256."; | ||
this.infoURL = "https://wikipedia.org/wiki/SM3_(hash_function)"; | ||
this.inputType = "ArrayBuffer"; | ||
this.outputType = "string"; | ||
this.args = [ | ||
{ | ||
name: "Length", | ||
type: "number", | ||
value: 256 | ||
}, | ||
{ | ||
name: "Rounds", | ||
type: "number", | ||
value: 64 | ||
} | ||
]; | ||
} | ||
|
||
/** | ||
* @param {ArrayBuffer} input | ||
* @param {Object[]} args | ||
* @returns {string} | ||
*/ | ||
run(input, args) { | ||
const msg = Utils.arrayBufferToStr(input, false); | ||
const hasher = new Sm3({length: args[0], rounds: args[1]}); | ||
hasher.update(msg); | ||
return toHex(hasher.finalize()); | ||
} | ||
} | ||
|
||
export default SM3; |