Skip to content

Tiny Encryption Algorithm (TEA) for Node.js, in N-API.

License

Notifications You must be signed in to change notification settings

nomagick/tea-napi

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

8 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

tea-napi

Introduction

Tiny Encryption Algorithm (TEA) for Node.js, in N-API.

Numbers in javascript were signed 32bit integers when doing bit-wise operation.

It's a pain to implement the TEA algorighm in pure javascript, and inefficient too.

So I basically copied the C code from Wikipedia and made it a N-API lib.

It does a IN-PLACE encryption/decryption on the Buffer passed in.

Padding

The last several bytes is left untouched if the Buffer was not aligned to TEA_BLOCK_LEN.

Usage

import { teaEncrypt, teaDecrypt, TEA_BLOCK_LEN, TEA_KEY_LEN } from 'tea-napi';

// Default to 32 cycles.
const ITER = 32;

const data = Buffer.alloc(TEA_BLOCK_LEN + 1);

const key = Buffer.alloc(TEA_KEY_LEN);

const encrypted = teaEncrypt(data, key, ITER);

// Same reference, but actually bytes changed.
assert(encrypted === data);

// The last byte, which is not aligned, was left untouched
assert(encrypted[TEA_BLOCK_LEN + 1] === 0);

const decrypted = teaDecrypt(encrypted, key, ITER);

assert(Buffer.compare(decrypted, Buffer.alloc(TEA_BLOCK_LEN + 1)) === 0);

About

Tiny Encryption Algorithm (TEA) for Node.js, in N-API.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published