Skip to content

Commit 82f8bb4

Browse files
committed
removing dependency on buffer.subarray, change default return type to Uint8Array on all platforms
1 parent b9ff19c commit 82f8bb4

File tree

5 files changed

+19
-25
lines changed

5 files changed

+19
-25
lines changed

README.md

+4-6
Original file line numberDiff line numberDiff line change
@@ -70,10 +70,9 @@ Usage
7070
------
7171

7272
All API functions accept `Uint8Array`s, Node/Browserify Buffers, or any
73-
api-compatible byte array objects. Return type defaults to Buffer where
74-
available and Uint8Array otherwise. Return type is configurable with
75-
nacl.setReturnType. If you need to encode or decode strings, use functions
76-
from `nacl.util` namespace.
73+
api-compatible byte array objects. Return type defaults to Uint8Array, but can
74+
be changed to node.js or browserify Buffer using util.setReturnType. If you
75+
need to encode or decode strings, use functions from `nacl.util` namespace.
7776

7877
### Public-key authenticated encryption (box)
7978

@@ -340,8 +339,7 @@ subarray, slice, or both methods as in Uint8Array. When an element is set to a
340339
value outside of 0-255 inclusive, the object must truncate it in the same way
341340
Uint8Array and Node.js Buffers do: `(new constructor([567]))[0] == 1`
342341

343-
Default value is Buffer when Buffer is available, as with Node or Browserify,
344-
and Uint8Array otherwise.
342+
Default is Uint8Array
345343

346344

347345
### Utilities

nacl-fast.js

+5-9
Original file line numberDiff line numberDiff line change
@@ -1368,8 +1368,8 @@ function crypto_scalarmult(q, n, p) {
13681368
x[i+48]=b[i];
13691369
x[i+64]=d[i];
13701370
}
1371-
var x32 = x.subarray(32);
1372-
var x16 = x.subarray(16);
1371+
var x32 = subarray(x, 32);
1372+
var x16 = subarray(x, 16);
13731373
inv25519(x32,x32);
13741374
M(x16,x16,x32);
13751375
pack25519(q,x16);
@@ -1983,7 +1983,7 @@ function crypto_sign(sm, m, n, sk) {
19831983
for (i = 0; i < n; i++) sm[64 + i] = m[i];
19841984
for (i = 0; i < 32; i++) sm[32 + i] = d[32 + i];
19851985

1986-
crypto_hash(r, sm.subarray(32), n+32);
1986+
crypto_hash(r, subarray(sm, 32), n+32);
19871987
reduce(r);
19881988
scalarbase(p, r);
19891989
pack(sm, p);
@@ -2000,7 +2000,7 @@ function crypto_sign(sm, m, n, sk) {
20002000
}
20012001
}
20022002

2003-
modL(sm.subarray(32), x);
2003+
modL(subarray(sm, 32), x);
20042004
return smlen;
20052005
}
20062006

@@ -2059,7 +2059,7 @@ function crypto_sign_open(m, sm, n, pk) {
20592059
reduce(h);
20602060
scalarmult(p, q, h);
20612061

2062-
scalarbase(q, sm.subarray(32));
2062+
scalarbase(q, subarray(sm, 32));
20632063
add(p, q);
20642064
pack(t, p);
20652065

@@ -2434,10 +2434,6 @@ nacl.setPRNG = function(fn) {
24342434
});
24352435
}
24362436
}
2437-
2438-
// Node.js and Browserify default to Buffer
2439-
if (typeof Buffer !== 'undefined')
2440-
nacl.setReturnType(Buffer);
24412437
})();
24422438

24432439
})(typeof module !== 'undefined' && module.exports ? module.exports : (window.nacl = window.nacl || {}));

nacl-fast.min.js

+2-2
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

nacl.js

+7-7
Original file line numberDiff line numberDiff line change
@@ -163,13 +163,13 @@ function crypto_stream_salsa20(c,cpos,d,n,k) {
163163
function crypto_stream(c,cpos,d,n,k) {
164164
var s = new Uint8Array(32);
165165
crypto_core_hsalsa20(s,n,k,sigma);
166-
return crypto_stream_salsa20(c,cpos,d,n.subarray(16),s);
166+
return crypto_stream_salsa20(c,cpos,d,subarray(n,16),s);
167167
}
168168

169169
function crypto_stream_xor(c,cpos,m,mpos,d,n,k) {
170170
var s = new Uint8Array(32);
171171
crypto_core_hsalsa20(s,n,k,sigma);
172-
return crypto_stream_salsa20_xor(c,cpos,m,mpos,d,n.subarray(16),s);
172+
return crypto_stream_salsa20_xor(c,cpos,m,mpos,d,subarray(n,16),s);
173173
}
174174

175175
function add1305(h, c) {
@@ -430,8 +430,8 @@ function crypto_scalarmult(q, n, p) {
430430
x[i+48]=b[i];
431431
x[i+64]=d[i];
432432
}
433-
var x32 = x.subarray(32);
434-
var x16 = x.subarray(16);
433+
var x32 = subarray(x,32);
434+
var x16 = subarray(x,16);
435435
inv25519(x32,x32);
436436
M(x16,x16,x32);
437437
pack25519(q,x16);
@@ -770,7 +770,7 @@ function crypto_sign(sm, m, n, sk) {
770770
for (i = 0; i < n; i++) sm[64 + i] = m[i];
771771
for (i = 0; i < 32; i++) sm[32 + i] = d[32 + i];
772772

773-
crypto_hash(r, sm.subarray(32), n+32);
773+
crypto_hash(r, subarray(sm,32), n+32);
774774
reduce(r);
775775
scalarbase(p, r);
776776
pack(sm, p);
@@ -787,7 +787,7 @@ function crypto_sign(sm, m, n, sk) {
787787
}
788788
}
789789

790-
modL(sm.subarray(32), x);
790+
modL(subarray(sm,32), x);
791791
return smlen;
792792
}
793793

@@ -846,7 +846,7 @@ function crypto_sign_open(m, sm, n, pk) {
846846
reduce(h);
847847
scalarmult(p, q, h);
848848

849-
scalarbase(q, sm.subarray(32));
849+
scalarbase(q, subarray(sm,32));
850850
add(p, q);
851851
pack(t, p);
852852

0 commit comments

Comments
 (0)