2019-03-28 16:46:04 +01:00
/ * *
* @ author mshwed [ m @ ttshwed . com ]
* @ copyright Crown Copyright 2019
* @ license Apache - 2.0
* /
2019-07-09 13:23:59 +02: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 16:46:04 +01:00
/ * *
* Streebog operation
* /
class Streebog extends Operation {
/ * *
* Streebog constructor
* /
constructor ( ) {
super ( ) ;
this . name = "Streebog" ;
2019-07-03 18:23:45 +02: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 16:46:04 +01:00
this . outputType = "string" ;
2019-04-02 05:14:40 +02:00
this . args = [
{
2019-07-03 18:23:45 +02:00
"name" : "Size" ,
2019-04-02 05:14:40 +02:00
"type" : "option" ,
"value" : [ "256" , "512" ]
}
] ;
2019-03-28 16:46:04 +01:00
}
/ * *
2019-07-03 18:23:45 +02:00
* @ param { ArrayBuffer } input
2019-03-28 16:46:04 +01:00
* @ param { Object [ ] } args
* @ returns { string }
* /
run ( input , args ) {
try {
2019-07-03 18:23:45 +02:00
const length = parseInt ( args [ 0 ] , 10 ) ;
const gostDigest = new GostDigest ( {
name : "GOST R 34.11" ,
version : 2012 ,
length : length
} ) ;
return toHexFast ( gostDigest . digest ( input ) ) ;
2019-03-28 16:46:04 +01:00
} catch ( err ) {
2019-07-03 18:23:45 +02:00
throw new OperationError ( err ) ;
2019-03-28 16:46:04 +01:00
}
}
}
export default Streebog ;