@@ -105,8 +105,8 @@ module.exports = {
105105 return lib . crypto_auth_verify ( macArr , keyArr , dataArr ) ;
106106 } ,
107107 crypto_aead_chacha20poly1305_encrypt : function ( data , key , addData ) {
108- var dataArr = stringOrU8 ( data , 'crypto_secretbox_easy ' , 'data' , 0 ) ;
109- var keyArr = stringOrU8 ( key , 'crypto_secretbox_easy ' , 'key' , 1 ) ;
108+ var dataArr = stringOrU8 ( data , 'crypto_aead_chacha20poly1305_encrypt ' , 'data' , 0 ) ;
109+ var keyArr = stringOrU8 ( key , 'crypto_aead_chacha20poly1305_encrypt ' , 'key' , 1 ) ;
110110 var addDataArr = stringOrU8 ( key , 'crypto_aead_chacha20poly1305_encrypt' , 'additional data' , 2 ) ;
111111
112112 var nonceArr = runtime . random . getRandomValues ( constants . crypto_aead_chacha20poly1305_NPUBBYTES ) ;
@@ -133,6 +133,86 @@ module.exports = {
133133 throw new Error ( 'crypto_aead_chacha20poly1305_decrypt: error decrypting box.' ) ;
134134 }
135135 return hexToU8 ( decipher . deciphertext ) ;
136+ } ,
137+ crypto_aead_aes256gcm_is_available : function ( ) {
138+ // AES-256 GCM isn't supported on QEMU's system-x86_64
139+ return false ;
140+ } ,
141+ crypto_aead_aes256gcm_encrypt : function ( data , key , addData ) {
142+ // AES-256 GCM isn't supported on QEMU's system-x86_64
143+ throw new Error ( 'CPU not supported' ) ;
144+ /*var dataArr = stringOrU8(data, 'crypto_aead_aes256gcm_encrypt', 'data', 0);
145+ var keyArr = stringOrU8(key, 'crypto_aead_aes256gcm_encrypt', 'key', 1);
146+ var addDataArr = stringOrU8(key, 'crypto_aead_aes256gcm_encrypt', 'additional data', 2);
147+
148+ var nonceArr = runtime.random.getRandomValues(constants.crypto_aead_aes256gcm_NPUBBYTES);
149+
150+ var cipher = lib.crypto_aead_aes256gcm_encrypt(dataArr, keyArr, nonceArr, addDataArr);
151+ if (!cipher) {
152+ throw new Error('crypto_aead_aes256gcm_encrypt: error creating box.');
153+ }
154+ if (cipher instanceof Error) throw cipher;
155+ return {
156+ ciphertext: hexToU8(cipher.ciphertext),
157+ nonce: nonceArr,
158+ length: cipher.ciphertext_len
159+ };*/
160+ } ,
161+ crypto_aead_aes256gcm_decrypt : function ( cipher , cipherLength , key , nonce , addData ) {
162+ // AES-256 GCM isn't supported on QEMU's system-x86_64
163+ throw new Error ( 'CPU not supported' ) ;
164+ /*var cipherArr = stringOrU8(cipher, 'crypto_aead_aes256gcm_decrypt', 'cipher', 0);
165+ var cipherLen = isNumber(cipherLength, 'crypto_aead_aes256gcm_decrypt', 'cipher length', 1);
166+ var keyArr = stringOrU8(key, 'crypto_aead_aes256gcm_decrypt', 'key', 2);
167+ var nonceArr = stringOrU8(nonce, 'crypto_aead_aes256gcm_decrypt', 'nonce', 3);
168+ var addDataArr = stringOrU8(key, 'crypto_aead_aes256gcm_decrypt', 'additional data', 4);
169+
170+ var decipher = lib.crypto_aead_aes256gcm_decrypt(cipherArr, keyArr, nonceArr, addDataArr, cipherLen);
171+ if (!decipher) {
172+ throw new Error('crypto_aead_aes256gcm_decrypt: error decrypting box.');
173+ }
174+ if (decipher instanceof Error) throw decipher;
175+ return hexToU8(decipher.deciphertext);*/
176+ } ,
177+ crypto_box_easy : function ( data , pk , sk ) {
178+ var dataArr = stringOrU8 ( data , 'crypto_box_easy' , 'data' , 0 ) ;
179+ var pkArr = stringOrU8 ( pk , 'crypto_box_easy' , 'public key' , 1 ) ;
180+ var skArr = stringOrU8 ( sk , 'crypto_box_easy' , 'secret key' , 2 ) ;
181+
182+ var nonceArr = runtime . random . getRandomValues ( constants . crypto_box_NONCEBYTES ) ;
183+
184+ var cipher = lib . crypto_secretbox_easy ( dataArr , pkArr , skArr , nonceArr ) ;
185+ if ( ! cipher ) {
186+ throw new Error ( 'crypto_box_easy: error creating box.' ) ;
187+ }
188+ return {
189+ ciphertext : hexToU8 ( cipher ) ,
190+ nonce : nonceArr
191+ } ;
192+ } ,
193+ crypto_box_open_easy : function ( cipher , pk , sk , nonce ) {
194+ var cipherArr = stringOrU8 ( cipher , 'crypto_box_open_easy' , 'cipher' , 0 ) ;
195+ var pkArr = stringOrU8 ( pk , 'crypto_box_open_easy' , 'public key' , 1 ) ;
196+ var skArr = stringOrU8 ( sk , 'crypto_box_open_easy' , 'secret key' , 1 ) ;
197+ var nonceArr = stringOrU8 ( nonce , 'crypto_box_open_easy' , 'nonce' , 2 ) ;
198+
199+ var decipher = lib . crypto_box_open_easy ( cipherArr , pkArr , skArr , nonceArr ) ;
200+ if ( ! decipher ) {
201+ throw new Error ( 'crypto_box_open_easy: error decrypting box.' ) ;
202+ }
203+ return hexToU8 ( decipher ) ;
204+ } ,
205+ crypto_box_keypair : function ( ) {
206+ var keypair = lib . crypto_box_keypair ( ) ;
207+ if ( typeof keypair === 'string' ) throw new Error ( keypair ) ;
208+ return keypair ;
209+ } ,
210+ crypto_box_seed_keypair : function ( seed ) {
211+ var seedArr = stringOrU8 ( seed , 'crypto_box_seed_keypair' , 'seed' , 0 ) ;
212+
213+ var keypair = lib . crypto_box_seed_keypair ( seedArr ) ;
214+ if ( typeof keypair === 'string' ) throw new Error ( keypair ) ;
215+ return keypair ;
136216 }
137217} ;
138218
0 commit comments