@@ -55,22 +55,19 @@ class GOSTDecrypt extends Operation {
55
55
type : "argSelector" ,
56
56
value : [
57
57
{
58
- name : "GOST 28147 (Magma, 1989)" ,
59
- off : [ 5 ] ,
58
+ name : "GOST 28147 (1989)" ,
60
59
on : [ 6 ]
61
60
} ,
61
+ {
62
+ name : "GOST R 34.12 (Magma, 2015)" ,
63
+ off : [ 5 ]
64
+ } ,
62
65
{
63
66
name : "GOST R 34.12 (Kuznyechik, 2015)" ,
64
- on : [ 5 ] ,
65
- off : [ 6 ]
67
+ off : [ 5 ]
66
68
}
67
69
]
68
70
} ,
69
- {
70
- name : "Block length" ,
71
- type : "option" ,
72
- value : [ "64" , "128" ]
73
- } ,
74
71
{
75
72
name : "sBox" ,
76
73
type : "option" ,
@@ -100,14 +97,30 @@ class GOSTDecrypt extends Operation {
100
97
* @returns {string }
101
98
*/
102
99
async run ( input , args ) {
103
- const [ keyObj , ivObj , inputType , outputType , version , length , sBox , blockMode , keyMeshing , padding ] = args ;
100
+ const [ keyObj , ivObj , inputType , outputType , version , sBox , blockMode , keyMeshing , padding ] = args ;
104
101
105
102
const key = toHexFast ( Utils . convertToByteArray ( keyObj . string , keyObj . option ) ) ;
106
103
const iv = toHexFast ( Utils . convertToByteArray ( ivObj . string , ivObj . option ) ) ;
107
104
input = inputType === "Hex" ? input : toHexFast ( Utils . strToArrayBuffer ( input ) ) ;
108
105
109
- const versionNum = version === "GOST 28147 (Magma, 1989)" ? 1989 : 2015 ;
110
- const blockLength = versionNum === 1989 ? 64 : parseInt ( length , 10 ) ;
106
+ let blockLength , versionNum ;
107
+ switch ( version ) {
108
+ case "GOST 28147 (1989)" :
109
+ versionNum = 1989 ;
110
+ blockLength = 64 ;
111
+ break ;
112
+ case "GOST R 34.12 (Magma, 2015)" :
113
+ versionNum = 2015 ;
114
+ blockLength = 64 ;
115
+ break ;
116
+ case "GOST R 34.12 (Kuznyechik, 2015)" :
117
+ versionNum = 2015 ;
118
+ blockLength = 128 ;
119
+ break ;
120
+ default :
121
+ throw new OperationError ( `Unknown algorithm version: ${ version } ` ) ;
122
+ }
123
+
111
124
const sBoxVal = versionNum === 1989 ? sBox : null ;
112
125
113
126
const algorithm = {
0 commit comments