2019-03-28 11:46:04 -04:00
/ * *
* @ author mshwed [ m @ ttshwed . com ]
* @ copyright Crown Copyright 2019
* @ license Apache - 2.0
* /
import Operation from "../Operation" ;
import OperationError from "../errors/OperationError" ;
2019-07-03 17:23:45 +01:00
import GostDigest from "../vendor/gost/gostDigest" ;
import { toHexFast } from "../lib/Hex" ;
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 = [
{
2019-07-03 17:23:45 +01:00
"name" : "Size" ,
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 ) {
try {
2019-07-03 17:23:45 +01: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 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 ;