2019-03-28 11:46:04 -04:00
/ * *
* @ author mshwed [ m @ ttshwed . com ]
* @ copyright Crown Copyright 2019
* @ license Apache - 2.0
* /
2019-07-09 12:23:59 +01:00
import Operation from "../Operation.mjs" ;
import OperationError from "../errors/OperationError.mjs" ;
import GostDigest from "../vendor/gost/gostDigest.mjs" ;
import { toHexFast } from "../lib/Hex.mjs" ;
2019-03-28 11:46:04 -04:00
/ * *
* Streebog operation
* /
class Streebog extends Operation {
/ * *
* Streebog constructor
* /
constructor ( ) {
super ( ) ;
this . name = "Streebog" ;
2019-07-03 17:23:45 +01:00
this . module = "Hashing" ;
this . description = "Streebog is a cryptographic hash function defined in the Russian national standard GOST R 34.11-2012 <i>Information Technology \u2013 Cryptographic Information Security \u2013 Hash Function</i>. It was created to replace an obsolete GOST hash function defined in the old standard GOST R 34.11-94, and as an asymmetric reply to SHA-3 competition by the US National Institute of Standards and Technology." ;
this . infoURL = "https://wikipedia.org/wiki/Streebog" ;
this . inputType = "ArrayBuffer" ;
2019-03-28 11:46:04 -04:00
this . outputType = "string" ;
2019-04-01 23:14:40 -04:00
this . args = [
{
2023-07-14 18:37:02 +01:00
"name" : "Digest length" ,
2019-04-01 23:14:40 -04:00
"type" : "option" ,
"value" : [ "256" , "512" ]
}
] ;
2019-03-28 11:46:04 -04:00
}
/ * *
2019-07-03 17:23:45 +01:00
* @ param { ArrayBuffer } input
2019-03-28 11:46:04 -04:00
* @ param { Object [ ] } args
* @ returns { string }
* /
run ( input , args ) {
2023-07-14 18:37:02 +01:00
const [ length ] = args ;
const algorithm = {
version : 2012 ,
mode : "HASH" ,
length : parseInt ( length , 10 )
} ;
2019-03-28 11:46:04 -04:00
try {
2023-07-14 18:37:02 +01:00
const gostDigest = new GostDigest ( algorithm ) ;
2019-07-03 17:23:45 +01:00
return toHexFast ( gostDigest . digest ( input ) ) ;
2019-03-28 11:46:04 -04:00
} catch ( err ) {
2019-07-03 17:23:45 +01:00
throw new OperationError ( err ) ;
2019-03-28 11:46:04 -04:00
}
}
}
export default Streebog ;