monorepo 버전 준비
## @strpc 기존 RPC를 package화 ### @strpc/express express의 middleware + router 결함 ## @sammo 게임 전체 - server, client - gateway_server, gateway_client
This commit is contained in:
@@ -0,0 +1,48 @@
|
||||
import { AES_GCM_Decrypt, AES_GCM_Encrypt } from "./AES.js";
|
||||
import { deriveKey } from "./ECDHe.js";
|
||||
import type { ECDHe_P384_KeyPair, ECDHe_P384_LiteKeyPair, ECDHe_P384_PublicKey, ECDHe_P384_PublicKeyInfo } from "./RawTypes.js";
|
||||
|
||||
export type EncryptedItem = {
|
||||
ct: Uint8Array;
|
||||
}
|
||||
|
||||
const keySizeBit = 256;
|
||||
|
||||
export async function ECDHe_AES_GCM_Encrypt(other: ECDHe_P384_PublicKeyInfo, me: ECDHe_P384_LiteKeyPair | ECDHe_P384_KeyPair, iv: BufferSource, msg: BufferSource, aad?: BufferSource): Promise<ArrayBuffer>;
|
||||
export async function ECDHe_AES_GCM_Encrypt(other: ECDHe_P384_PublicKey, me: ECDHe_P384_KeyPair, iv: BufferSource, msg: BufferSource, aad?: BufferSource): Promise<ArrayBuffer>;
|
||||
export async function ECDHe_AES_GCM_Encrypt(other: ECDHe_P384_PublicKeyInfo, me: ECDHe_P384_LiteKeyPair, iv: BufferSource, msg: BufferSource, aad?: BufferSource): Promise<ArrayBuffer>;
|
||||
|
||||
export async function ECDHe_AES_GCM_Encrypt(other: ECDHe_P384_PublicKeyInfo | ECDHe_P384_PublicKey, me: ECDHe_P384_KeyPair | ECDHe_P384_LiteKeyPair, iv: BufferSource, msg: BufferSource, aad?: BufferSource): Promise<ArrayBuffer>{
|
||||
let key: ArrayBuffer;
|
||||
if('publicInfo' in me){
|
||||
key = await deriveKey(other, me, keySizeBit);
|
||||
}
|
||||
else if('publicKey' in other){
|
||||
key = await deriveKey(other, me, keySizeBit);
|
||||
}
|
||||
else{
|
||||
throw new Error("Invalid argument: may be trying to do ECDH, not ECDHe.");
|
||||
}
|
||||
|
||||
return AES_GCM_Encrypt(key, iv, msg, aad);
|
||||
}
|
||||
|
||||
export async function ECDHe_AES_GCM_Decrypt(other: ECDHe_P384_PublicKeyInfo, me: ECDHe_P384_LiteKeyPair | ECDHe_P384_KeyPair, iv: BufferSource, ciphertext: BufferSource, aad?: BufferSource): Promise<ArrayBuffer>;
|
||||
export async function ECDHe_AES_GCM_Decrypt(other: ECDHe_P384_PublicKey, me: ECDHe_P384_KeyPair, iv: BufferSource, ciphertext: BufferSource, aad?: BufferSource): Promise<ArrayBuffer>;
|
||||
export async function ECDHe_AES_GCM_Decrypt(other: ECDHe_P384_PublicKeyInfo, me: ECDHe_P384_LiteKeyPair, iv: BufferSource, ciphertext: BufferSource, aad?: BufferSource): Promise<ArrayBuffer>;
|
||||
|
||||
|
||||
export async function ECDHe_AES_GCM_Decrypt(other: ECDHe_P384_PublicKeyInfo | ECDHe_P384_PublicKey, me: ECDHe_P384_KeyPair | ECDHe_P384_LiteKeyPair, iv: BufferSource, ciphertext: BufferSource, aad?: BufferSource): Promise<ArrayBuffer>{
|
||||
let key: ArrayBuffer;
|
||||
if('publicInfo' in me){
|
||||
key = await deriveKey(other, me, keySizeBit);
|
||||
}
|
||||
else if('publicKey' in other){
|
||||
key = await deriveKey(other, me, keySizeBit);
|
||||
}
|
||||
else{
|
||||
throw new Error("Invalid argument: may be trying to do ECDH, not ECDHe.");
|
||||
}
|
||||
|
||||
return AES_GCM_Decrypt(key, iv, ciphertext, aad);
|
||||
}
|
||||
Reference in New Issue
Block a user