Skip to content

Commit

Permalink
Remove KEM (#89)
Browse files Browse the repository at this point in the history
  • Loading branch information
kigawas authored Aug 29, 2019
1 parent 66b7f6f commit 767aebd
Show file tree
Hide file tree
Showing 5 changed files with 8 additions and 8 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ Returns: **Buffer**
static fromHex(hex: string): PrivateKey;
constructor(secret?: Buffer);
toHex(): string;
encapsulateKEM(pub: PublicKey): Buffer;
encapsulate(pub: PublicKey): Buffer;
multiply(pub: PublicKey): Buffer;
equals(other: PrivateKey): boolean;
```
Expand All @@ -72,7 +72,7 @@ readonly publicKey: PublicKey;
static fromHex(hex: string): PublicKey;
constructor(buffer: Buffer);
toHex(compressed?: boolean): string;
decapsulateKEM(priv: PrivateKey): Buffer;
decapsulate(priv: PrivateKey): Buffer;
equals(other: PublicKey): boolean;
```

Expand Down
4 changes: 2 additions & 2 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { aesDecrypt, aesEncrypt, decodeHex, getValidSecret, remove0x } from "./u
export function encrypt(receiverPubhex: string, msg: Buffer): Buffer {
const disposableKey = new PrivateKey();
const receiverPubkey = PublicKey.fromHex(receiverPubhex);
const aesKey = disposableKey.encapsulateKEM(receiverPubkey);
const aesKey = disposableKey.encapsulate(receiverPubkey);
const encrypted = aesEncrypt(aesKey, msg);
return Buffer.concat([disposableKey.publicKey.uncompressed, encrypted]);
}
Expand All @@ -13,7 +13,7 @@ export function decrypt(receiverPrvhex: string, msg: Buffer): Buffer {
const receiverPrvkey = PrivateKey.fromHex(receiverPrvhex);
const senderPubkey = new PublicKey(msg.slice(0, 65));
const encrypted = msg.slice(65);
const aesKey = senderPubkey.decapsulateKEM(receiverPrvkey);
const aesKey = senderPubkey.decapsulate(receiverPrvkey);
return aesDecrypt(aesKey, encrypted);
}

Expand Down
2 changes: 1 addition & 1 deletion src/keys/PrivateKey.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ export default class PrivateKey {
return `0x${this.secret.toString("hex")}`;
}

public encapsulateKEM(pub: PublicKey): Buffer {
public encapsulate(pub: PublicKey): Buffer {
const master = Buffer.concat([
this.publicKey.uncompressed,
this.multiply(pub),
Expand Down
2 changes: 1 addition & 1 deletion src/keys/PublicKey.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ export default class PublicKey {
}
}

public decapsulateKEM(priv: PrivateKey): Buffer {
public decapsulate(priv: PrivateKey): Buffer {
const master = Buffer.concat([
this.uncompressed,
priv.multiply(this),
Expand Down
4 changes: 2 additions & 2 deletions src/tests/crypt.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -111,8 +111,8 @@ describe("test keys", () => {
const k2 = new PrivateKey(three);
expect(k1.multiply(k2.publicKey).equals(k2.multiply(k1.publicKey))).to.be.equal(true);

const derived = k1.encapsulateKEM(k2.publicKey);
const anotherDerived = k1.publicKey.decapsulateKEM(k2);
const derived = k1.encapsulate(k2.publicKey);
const anotherDerived = k1.publicKey.decapsulate(k2);
const knownDerived = Buffer.from(decodeHex(
"6f982d63e8590c9d9b5b4c1959ff80315d772edd8f60287c9361d548d5200f82",
));
Expand Down

0 comments on commit 767aebd

Please sign in to comment.