Skip to content

Commit

Permalink
change to trigger ci
Browse files Browse the repository at this point in the history
  • Loading branch information
benesjan committed Sep 30, 2024
1 parent 4bf6734 commit c107a6e
Show file tree
Hide file tree
Showing 2 changed files with 51 additions and 47 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,10 @@ import {
computeOvskApp,
derivePublicKeyFromSecretKey,
} from '@aztec/circuits.js';
import { Aes128 } from '@aztec/circuits.js/barretenberg';
import { BufferReader, serializeToBuffer } from '@aztec/foundation/serialize';

import { deriveDiffieHellmanAESSecret, derivePoseidonAESSecret } from './shared_secret_derivation.js';
import { decrypt, encrypt } from './encryption_util.js';
import { derivePoseidonAESSecret } from './shared_secret_derivation.js';

// Both the incoming and the outgoing header are 48 bytes../shared_secret_derivation.js
// 32 bytes for the address, and 16 bytes padding to follow PKCS#7
Expand Down Expand Up @@ -208,48 +208,3 @@ export class EncryptedLogPayload {
);
}
}

/**
* Encrypts the plaintext using the secret key and public key
*
* @param plaintext - The plaintext buffer
* @param secret - The secret key used to derive the AES secret
* @param publicKey - Public key used to derived the AES secret
* @param deriveSecret - Function to derive the AES secret from the ephemeral secret key and public key
* @returns The ciphertext
*/
function encrypt(
plaintext: Buffer,
secret: GrumpkinScalar,
publicKey: PublicKey,
deriveSecret: (secret: GrumpkinScalar, publicKey: PublicKey) => Buffer = deriveDiffieHellmanAESSecret,
): Buffer {
const aesSecret = deriveSecret(secret, publicKey);
const key = aesSecret.subarray(0, 16);
const iv = aesSecret.subarray(16, 32);

const aes128 = new Aes128();
return aes128.encryptBufferCBC(plaintext, iv, key);
}

/**
* Decrypts the ciphertext using the secret key and public key
* @param ciphertext - The ciphertext buffer
* @param secret - The secret key used to derive the AES secret
* @param publicKey - The public key used to derive the AES secret
* @param deriveSecret - Function to derive the AES secret from the ephemeral secret key and public key
* @returns
*/
function decrypt(
ciphertext: Buffer,
secret: GrumpkinScalar,
publicKey: PublicKey,
deriveSecret: (secret: GrumpkinScalar, publicKey: PublicKey) => Buffer = deriveDiffieHellmanAESSecret,
): Buffer {
const aesSecret = deriveSecret(secret, publicKey);
const key = aesSecret.subarray(0, 16);
const iv = aesSecret.subarray(16, 32);

const aes128 = new Aes128();
return aes128.decryptBufferCBC(ciphertext, iv, key);
}
49 changes: 49 additions & 0 deletions yarn-project/circuit-types/src/logs/l1_payload/encryption_util.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
import { type GrumpkinScalar, type PublicKey } from '@aztec/circuits.js';
import { Aes128 } from '@aztec/circuits.js/barretenberg';

import { deriveDiffieHellmanAESSecret } from './shared_secret_derivation.js';

/**
* Encrypts the plaintext using the secret key and public key
*
* @param plaintext - The plaintext buffer
* @param secret - The secret key used to derive the AES secret
* @param publicKey - Public key used to derived the AES secret
* @param deriveSecret - Function to derive the AES secret from the ephemeral secret key and public key
* @returns The ciphertext
*/
export function encrypt(
plaintext: Buffer,
secret: GrumpkinScalar,
publicKey: PublicKey,
deriveSecret: (secret: GrumpkinScalar, publicKey: PublicKey) => Buffer = deriveDiffieHellmanAESSecret,
): Buffer {
const aesSecret = deriveSecret(secret, publicKey);
const key = aesSecret.subarray(0, 16);
const iv = aesSecret.subarray(16, 32);

const aes128 = new Aes128();
return aes128.encryptBufferCBC(plaintext, iv, key);
}

/**
* Decrypts the ciphertext using the secret key and public key
* @param ciphertext - The ciphertext buffer
* @param secret - The secret key used to derive the AES secret
* @param publicKey - The public key used to derive the AES secret
* @param deriveSecret - Function to derive the AES secret from the ephemeral secret key and public key
* @returns
*/
export function decrypt(
ciphertext: Buffer,
secret: GrumpkinScalar,
publicKey: PublicKey,
deriveSecret: (secret: GrumpkinScalar, publicKey: PublicKey) => Buffer = deriveDiffieHellmanAESSecret,
): Buffer {
const aesSecret = deriveSecret(secret, publicKey);
const key = aesSecret.subarray(0, 16);
const iv = aesSecret.subarray(16, 32);

const aes128 = new Aes128();
return aes128.decryptBufferCBC(ciphertext, iv, key);
}

0 comments on commit c107a6e

Please sign in to comment.