Skip to content

Commit

Permalink
incluindo estrutura de pastas para adotar o chacha e o salsa
Browse files Browse the repository at this point in the history
  • Loading branch information
antonioconselheiro committed Feb 26, 2024
1 parent 543e50b commit cfdd960
Show file tree
Hide file tree
Showing 22 changed files with 82 additions and 20 deletions.
Empty file modified docs/ciphers/jest-html-reporters-attach/test-report/index.js
100644 → 100755
Empty file.
Empty file modified docs/ciphers/jest-html-reporters-attach/test-report/result.js
100644 → 100755
Empty file.
8 changes: 4 additions & 4 deletions packages/ciphers/aes/cbc/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@ import { bytesToUtf8, hexToBytes, utf8ToBytes } from '@noble/ciphers/utils';
import { cbc } from '@noble/ciphers/webcrypto/aes';
import { randomBytes } from '@noble/hashes/utils';
import { base64 } from '@scure/base';
import { TInitializationVectorParams, getInitializationVector } from '../initialization-vector';
import { kdf } from '../kdf';
import { OpenSSLSerializer } from '../openssl-serializer';
import { getSalt } from '../salt';
import { TInitializationVectorParams, getInitializationVector } from '../../initialization-vector';
import { kdf } from '../../kdf';
import { OpenSSLSerializer } from '../../openssl-serializer';
import { getSalt } from '../../salt';

class EncryptedURIAESCBCDecrypter extends EncryptedURIDecrypter<TInitializationVectorParams> {
constructor(
Expand Down
8 changes: 4 additions & 4 deletions packages/ciphers/aes/ctr/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@ import { bytesToUtf8, hexToBytes, utf8ToBytes } from '@noble/ciphers/utils';
import { ctr } from '@noble/ciphers/webcrypto/aes';
import { randomBytes } from "@noble/hashes/utils";
import { base64 } from '@scure/base';
import { TInitializationVectorParams, getInitializationVector } from "../initialization-vector";
import { kdf } from '../kdf';
import { OpenSSLSerializer } from "../openssl-serializer";
import { getSalt } from '../salt';
import { TInitializationVectorParams, getInitializationVector } from "../../initialization-vector";
import { kdf } from '../../kdf';
import { OpenSSLSerializer } from "../../openssl-serializer";
import { getSalt } from '../../salt';

class EncryptedURIAESCTRDecrypter extends EncryptedURIDecrypter<TInitializationVectorParams> {
constructor(
Expand Down
6 changes: 3 additions & 3 deletions packages/ciphers/aes/ecb/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@ import { ecb } from '@noble/ciphers/aes';
import { bytesToUtf8, utf8ToBytes } from '@noble/ciphers/utils';
import { randomBytes } from '@noble/hashes/utils';
import { base64 } from '@scure/base';
import { kdf } from '../kdf';
import { OpenSSLSerializer } from '../openssl-serializer';
import { getSalt } from '../salt';
import { kdf } from '../../kdf';
import { OpenSSLSerializer } from '../../openssl-serializer';
import { getSalt } from '../../salt';

class EncryptedURIAESECBDecrypter<T extends TURIParams = TURIParams> extends EncryptedURIDecrypter<T> {
constructor(
Expand Down
8 changes: 4 additions & 4 deletions packages/ciphers/aes/gcm/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@ import { bytesToUtf8, hexToBytes, utf8ToBytes } from '@noble/ciphers/utils';
import { gcm } from '@noble/ciphers/webcrypto/aes';
import { randomBytes } from '@noble/hashes/utils';
import { base64 } from '@scure/base';
import { kdf } from '../kdf';
import { TNumberOnceParams, getNumberOnce } from '../number-once';
import { OpenSSLSerializer } from '../openssl-serializer';
import { getSalt } from '../salt';
import { kdf } from '../../kdf';
import { TNumberOnceParams, getNumberOnce } from '../../number-once';
import { OpenSSLSerializer } from '../../openssl-serializer';
import { getSalt } from '../../salt';

class EncryptedURIAESGCMDecrypter extends EncryptedURIDecrypter<TNumberOnceParams> {
constructor(
Expand Down
8 changes: 4 additions & 4 deletions packages/ciphers/aes/siv/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@ import { siv } from '@noble/ciphers/aes';
import { bytesToUtf8, hexToBytes, utf8ToBytes } from '@noble/ciphers/utils';
import { randomBytes } from '@noble/hashes/utils';
import { base64 } from '@scure/base';
import { kdf } from '../kdf';
import { TNumberOnceParams, getNumberOnce } from '../number-once';
import { OpenSSLSerializer } from '../openssl-serializer';
import { getSalt } from '../salt';
import { kdf } from '../../kdf';
import { TNumberOnceParams, getNumberOnce } from '../../number-once';
import { OpenSSLSerializer } from '../../openssl-serializer';
import { getSalt } from '../../salt';

class EncryptedURIAESSIVDecrypter extends EncryptedURIDecrypter<TNumberOnceParams> {
constructor(
Expand Down
Empty file.
Empty file.
58 changes: 58 additions & 0 deletions packages/ciphers/chacha/chacha8.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
import { EncryptedURIAlgorithm, EncryptedURIDecrypter, EncryptedURIEncrypter, TEncryptedURI, TEncryptedURIResultset } from '@encrypted-uri/core';
import { chacha8 } from '@noble/ciphers/chacha';
import { TNumberOnceParams, getNumberOnce } from '../number-once';
import { hexToBytes, randomBytes, utf8ToBytes } from '@noble/hashes/utils';
import { kdf } from '../kdf';
import { OpenSSLSerializer } from '../openssl-serializer';
import { base64 } from '@scure/base';
import { getSalt } from '../salt';

class EncryptedURIAESSIVDecrypter extends EncryptedURIDecrypter<TNumberOnceParams> {
constructor(
decoded: TEncryptedURI<TNumberOnceParams>,
password: string
) {
super(decoded, password);
}

async decrypt(): Promise<string> {
const nonce = getNumberOnce(this.decoded);
const cipher = base64.decode(this.decoded.cipher);
const params = getSalt(cipher, this.decoded?.params);
const derivatedKey = kdf(this.password, params.salt, this.decoded);
const result = await chacha8(derivatedKey, hexToBytes(nonce))
.decrypt(params.cipher);

return bytesToUtf8(result);
}
}

@EncryptedURIAlgorithm({
algorithm: 'aes/siv',
decrypter: EncryptedURIAESSIVDecrypter
})
// eslint-disable-next-line @typescript-eslint/no-unused-vars
class EncryptedURIAESSIVEncrypter extends EncryptedURIEncrypter<TNumberOnceParams> {

constructor(
params: TEncryptedURIResultset<TNumberOnceParams>
) {
super(params);
}

async encrypt(): Promise<TEncryptedURI<TNumberOnceParams>> {
const numberOnceHex = getNumberOnce(this.params);
const nonce = hexToBytes(numberOnceHex);
const content = utf8ToBytes(this.params.content);
const saltLength = 8;
const salt = randomBytes(saltLength);
const derivatedKey = kdf(this.params.password, salt, this.params);
const cipher = await chacha8(derivatedKey, nonce, content);

return Promise.resolve({
cipher: base64.encode(OpenSSLSerializer.encode(cipher, salt)),
params: { no: numberOnceHex }
});
}
}

Empty file.
Empty file.
4 changes: 4 additions & 0 deletions packages/ciphers/hashes/ripemd160.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
import { ripemd160 } from '@noble/hashes/ripemd160';
import { HashSupport } from './hash-support';

HashSupport.addSupport('ripemd160', ripemd160);
File renamed without changes.
2 changes: 1 addition & 1 deletion packages/ciphers/aes/kdf.ts → packages/ciphers/kdf.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { EncryptedURI, TEncryptedURI, TEncryptedURIResultset, TURIParams } from '@encrypted-uri/core';
import { pbkdf2 } from '@noble/hashes/pbkdf2';
import { HashSupport } from '../hashes/hash-support';
import { HashSupport } from './hashes/hash-support';

export function kdf<T extends TURIParams>(
password: string,
Expand Down
File renamed without changes.
File renamed without changes.
Empty file.
Empty file.
Empty file.
Empty file.
File renamed without changes.

0 comments on commit cfdd960

Please sign in to comment.