Research
Security News
Threat Actor Exposes Playbook for Exploiting npm to Build Blockchain-Powered Botnets
A threat actor's playbook for exploiting the npm ecosystem was exposed on the dark web, detailing how to build a blockchain-powered botnet.
The adler-32 npm package is used for computing Adler-32 checksums. Adler-32 is a checksum algorithm which was designed to be a fast but not cryptographically secure alternative to CRC32. The algorithm is used in the zlib compression library. The adler-32 package provides functionality to calculate Adler-32 checksums for given inputs, which can be useful for error-checking or simple data integrity verification.
Calculate Adler-32 checksum from a string
This feature allows you to calculate the Adler-32 checksum of a given string. The 'str' method takes a string as input and returns the checksum as a number.
const adler32 = require('adler-32');
const checksum = adler32.str('Hello World');
console.log(checksum);
Calculate Adler-32 checksum from a buffer
This feature allows you to calculate the Adler-32 checksum of a given buffer. The 'buf' method takes a Node.js Buffer as input and returns the checksum as a number.
const adler32 = require('adler-32');
const buffer = Buffer.from('Hello World');
const checksum = adler32.buf(buffer);
console.log(checksum);
Calculate Adler-32 checksum and return result in hex format
This feature allows you to calculate the Adler-32 checksum of a given string and return the result in hexadecimal format. The second argument to the 'str' method is a boolean indicating whether the output should be in hex format.
const adler32 = require('adler-32');
const checksum = adler32.str('Hello World', true);
console.log(checksum);
The 'crc' npm package is used to calculate Cyclic Redundancy Check (CRC) of input data. It supports various CRC algorithms, including CRC32. It is similar to adler-32 in that it provides checksums for data integrity, but it offers a wider range of algorithms and is typically used when a more robust error-detection is required.
The 'crc32' package provides a simple and fast way to calculate CRC32 checksums for strings and buffers. It is similar to adler-32 in its simplicity and focus on CRC32, but it does not offer Adler-32 checksums.
The 'hash.js' package is a collection of hash functions implemented in pure JavaScript. It includes various cryptographic hash functions like SHA-1, SHA-256, and more. While it is more comprehensive and secure than adler-32, it is also more complex and may be slower due to the cryptographic nature of the algorithms.
Signed ADLER-32 algorithm implementation in JS (for the browser and nodejs). Emphasis on correctness and performance.
In nodejs:
npm install adler-32
In the browser:
<script lang="javascript" src="adler32.js"></script>
The browser exposes a variable ADLER32
ADLER32.buf(byte array or buffer)
assumes the argument is a set of 8 bit
unsigned integers (e.g. nodejs Buffer
or simple array of ints)
ADLER32.bstr(binary string)
interprets the argument as a binary string where
the i
-th byte is str.charCodeAt(i)
ADLER32.str(string)
interprets the argument as a standard JS string
make test
will run the nodejs-based test. To run the in-browser tests, run a
local server and go to the ctest
directory. To update the browser artifacts,
run make ctest
.
To generate the bits file, use the adler32
function from python zlib:
>>> from zlib import adler32
>>> x="foo bar baz٪☃🍣"
>>> adler32(x)
1543572022
>>> adler32(x+x)
-2076896149
>>> adler32(x+x+x)
2023497376
make perf
will run algorithmic performance tests (which should justify certain
decisions in the code).
js-crc has more performance notes
Bit twiddling is much faster than taking the mod on Safari and older Firefoxes.
Instead of taking the literal mod 65521, it is faster to keep it in the integers
by bit-shifting: 65536 ~ 15 mod 65521
so for nonnegative integer a
:
a = (a >>> 16) * 65536 + (a & 65535) [equality]
a ~ (a >>> 16) * 15 + (a & 65535) mod 65521
The mod is taken at the very end, since the intermediate result may exceed 65521
The magic numbers were chosen so as to not overflow a 31-bit integer:
F[n_] := Reduce[x*(x + 1)*n/2 + (x + 1)*(65521) < (2^31 - 1) && x > 0, x, Integers]
F[255] (* bstr: x \[Element] Integers && 1 <= x <= 3854 *)
F[127] (* ascii: x \[Element] Integers && 1 <= x <= 5321 *)
Subtract up to 4 elements for the unicode case.
Please consult the attached LICENSE file for details. All rights not explicitly granted by the Apache 2.0 license are reserved by the Original Author.
FAQs
Pure-JS ADLER-32
The npm package adler-32 receives a total of 2,338,263 weekly downloads. As such, adler-32 popularity was classified as popular.
We found that adler-32 demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Research
Security News
A threat actor's playbook for exploiting the npm ecosystem was exposed on the dark web, detailing how to build a blockchain-powered botnet.
Security News
NVD’s backlog surpasses 20,000 CVEs as analysis slows and NIST announces new system updates to address ongoing delays.
Security News
Research
A malicious npm package disguised as a WhatsApp client is exploiting authentication flows with a remote kill switch to exfiltrate data and destroy files.