@hpke/cose 0.0.0-stage → 0.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +69 -2
- package/esm/mod.d.ts +16 -0
- package/esm/mod.d.ts.map +1 -0
- package/esm/mod.js +11 -0
- package/esm/package.json +3 -0
- package/esm/src/alg.d.ts +60 -0
- package/esm/src/alg.d.ts.map +1 -0
- package/esm/src/alg.js +96 -0
- package/esm/src/cbor/decoder.d.ts +4 -0
- package/esm/src/cbor/decoder.d.ts.map +1 -0
- package/esm/src/cbor/decoder.js +148 -0
- package/esm/src/cbor/encoder.d.ts +6 -0
- package/esm/src/cbor/encoder.d.ts.map +1 -0
- package/esm/src/cbor/encoder.js +109 -0
- package/esm/src/cbor/types.d.ts +8 -0
- package/esm/src/cbor/types.d.ts.map +1 -0
- package/esm/src/cbor/types.js +1 -0
- package/esm/src/contentAesGcm.d.ts +3 -0
- package/esm/src/contentAesGcm.d.ts.map +1 -0
- package/esm/src/contentAesGcm.js +30 -0
- package/esm/src/coseKey.d.ts +56 -0
- package/esm/src/coseKey.d.ts.map +1 -0
- package/esm/src/coseKey.js +185 -0
- package/esm/src/encrypt.d.ts +155 -0
- package/esm/src/encrypt.d.ts.map +1 -0
- package/esm/src/encrypt.js +317 -0
- package/esm/src/encrypt0.d.ts +91 -0
- package/esm/src/encrypt0.d.ts.map +1 -0
- package/esm/src/encrypt0.js +203 -0
- package/esm/src/errors.d.ts +5 -0
- package/esm/src/errors.d.ts.map +1 -0
- package/esm/src/errors.js +7 -0
- package/esm/src/hpke0.d.ts +8 -0
- package/esm/src/hpke0.d.ts.map +1 -0
- package/esm/src/hpke0.js +23 -0
- package/esm/src/hpke1.d.ts +8 -0
- package/esm/src/hpke1.d.ts.map +1 -0
- package/esm/src/hpke1.js +23 -0
- package/esm/src/hpke2.d.ts +8 -0
- package/esm/src/hpke2.d.ts.map +1 -0
- package/esm/src/hpke2.js +23 -0
- package/esm/src/hpke3.d.ts +8 -0
- package/esm/src/hpke3.d.ts.map +1 -0
- package/esm/src/hpke3.js +23 -0
- package/esm/src/hpke4.d.ts +8 -0
- package/esm/src/hpke4.d.ts.map +1 -0
- package/esm/src/hpke4.js +39 -0
- package/esm/src/hpke5.d.ts +8 -0
- package/esm/src/hpke5.d.ts.map +1 -0
- package/esm/src/hpke5.js +24 -0
- package/esm/src/hpke6.d.ts +8 -0
- package/esm/src/hpke6.d.ts.map +1 -0
- package/esm/src/hpke6.js +40 -0
- package/esm/src/hpke7.d.ts +8 -0
- package/esm/src/hpke7.d.ts.map +1 -0
- package/esm/src/hpke7.js +23 -0
- package/esm/src/structures.d.ts +41 -0
- package/esm/src/structures.d.ts.map +1 -0
- package/esm/src/structures.js +63 -0
- package/package.json +48 -3
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"hpke1.d.ts","sourceRoot":"","sources":["../../src/src/hpke1.ts"],"names":[],"mappings":"AAOA,OAAO,EAAE,KAAK,UAAU,EAAe,MAAM,UAAU,CAAC;AAExD,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,eAAe,CAAC;AAElD,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,cAAc,CAAC;AAGhD,sEAAsE;AACtE,wBAAgB,WAAW,IAAI,YAAY,CAO1C;AAED,+DAA+D;AAC/D,wBAAgB,aAAa,CAAC,UAAU,EAAE,UAAU,GAAG,WAAW,CAYjE"}
|
package/esm/src/hpke1.js
ADDED
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { Aes256Gcm, CipherSuite, DhkemP384HkdfSha384, HkdfSha384, } from "@hpke/core";
|
|
2
|
+
import { CoseHpkeAlg } from "./alg.js";
|
|
3
|
+
import { aesGcmContentCrypto } from "./contentAesGcm.js";
|
|
4
|
+
import { CoseEncrypt0Impl } from "./encrypt0.js";
|
|
5
|
+
import { CoseEncryptImpl } from "./encrypt.js";
|
|
6
|
+
/** DHKEM(P-384), HKDF-SHA384, AES-256-GCM — Integrated Encryption. */
|
|
7
|
+
export function createHpke1() {
|
|
8
|
+
const suite = new CipherSuite({
|
|
9
|
+
kem: new DhkemP384HkdfSha384(),
|
|
10
|
+
kdf: new HkdfSha384(),
|
|
11
|
+
aead: new Aes256Gcm(),
|
|
12
|
+
});
|
|
13
|
+
return new CoseEncrypt0Impl(suite, CoseHpkeAlg.HPKE_1);
|
|
14
|
+
}
|
|
15
|
+
/** DHKEM(P-384), HKDF-SHA384, AES-256-GCM — Key Encryption. */
|
|
16
|
+
export function createHpke1Ke(contentAlg) {
|
|
17
|
+
const suite = new CipherSuite({
|
|
18
|
+
kem: new DhkemP384HkdfSha384(),
|
|
19
|
+
kdf: new HkdfSha384(),
|
|
20
|
+
aead: new Aes256Gcm(),
|
|
21
|
+
});
|
|
22
|
+
return new CoseEncryptImpl(suite, CoseHpkeAlg.HPKE_1_KE, contentAlg, aesGcmContentCrypto);
|
|
23
|
+
}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { type ContentAlg } from "./alg.js";
|
|
2
|
+
import type { CoseEncrypt0 } from "./encrypt0.js";
|
|
3
|
+
import type { CoseEncrypt } from "./encrypt.js";
|
|
4
|
+
/** DHKEM(P-521), HKDF-SHA512, AES-256-GCM — Integrated Encryption. */
|
|
5
|
+
export declare function createHpke2(): CoseEncrypt0;
|
|
6
|
+
/** DHKEM(P-521), HKDF-SHA512, AES-256-GCM — Key Encryption. */
|
|
7
|
+
export declare function createHpke2Ke(contentAlg: ContentAlg): CoseEncrypt;
|
|
8
|
+
//# sourceMappingURL=hpke2.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"hpke2.d.ts","sourceRoot":"","sources":["../../src/src/hpke2.ts"],"names":[],"mappings":"AAOA,OAAO,EAAE,KAAK,UAAU,EAAe,MAAM,UAAU,CAAC;AAExD,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,eAAe,CAAC;AAElD,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,cAAc,CAAC;AAGhD,sEAAsE;AACtE,wBAAgB,WAAW,IAAI,YAAY,CAO1C;AAED,+DAA+D;AAC/D,wBAAgB,aAAa,CAAC,UAAU,EAAE,UAAU,GAAG,WAAW,CAYjE"}
|
package/esm/src/hpke2.js
ADDED
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { Aes256Gcm, CipherSuite, DhkemP521HkdfSha512, HkdfSha512, } from "@hpke/core";
|
|
2
|
+
import { CoseHpkeAlg } from "./alg.js";
|
|
3
|
+
import { aesGcmContentCrypto } from "./contentAesGcm.js";
|
|
4
|
+
import { CoseEncrypt0Impl } from "./encrypt0.js";
|
|
5
|
+
import { CoseEncryptImpl } from "./encrypt.js";
|
|
6
|
+
/** DHKEM(P-521), HKDF-SHA512, AES-256-GCM — Integrated Encryption. */
|
|
7
|
+
export function createHpke2() {
|
|
8
|
+
const suite = new CipherSuite({
|
|
9
|
+
kem: new DhkemP521HkdfSha512(),
|
|
10
|
+
kdf: new HkdfSha512(),
|
|
11
|
+
aead: new Aes256Gcm(),
|
|
12
|
+
});
|
|
13
|
+
return new CoseEncrypt0Impl(suite, CoseHpkeAlg.HPKE_2);
|
|
14
|
+
}
|
|
15
|
+
/** DHKEM(P-521), HKDF-SHA512, AES-256-GCM — Key Encryption. */
|
|
16
|
+
export function createHpke2Ke(contentAlg) {
|
|
17
|
+
const suite = new CipherSuite({
|
|
18
|
+
kem: new DhkemP521HkdfSha512(),
|
|
19
|
+
kdf: new HkdfSha512(),
|
|
20
|
+
aead: new Aes256Gcm(),
|
|
21
|
+
});
|
|
22
|
+
return new CoseEncryptImpl(suite, CoseHpkeAlg.HPKE_2_KE, contentAlg, aesGcmContentCrypto);
|
|
23
|
+
}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { type ContentAlg } from "./alg.js";
|
|
2
|
+
import type { CoseEncrypt0 } from "./encrypt0.js";
|
|
3
|
+
import type { CoseEncrypt } from "./encrypt.js";
|
|
4
|
+
/** DHKEM(X25519), HKDF-SHA256, AES-128-GCM — Integrated Encryption. */
|
|
5
|
+
export declare function createHpke3(): CoseEncrypt0;
|
|
6
|
+
/** DHKEM(X25519), HKDF-SHA256, AES-128-GCM — Key Encryption. */
|
|
7
|
+
export declare function createHpke3Ke(contentAlg: ContentAlg): CoseEncrypt;
|
|
8
|
+
//# sourceMappingURL=hpke3.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"hpke3.d.ts","sourceRoot":"","sources":["../../src/src/hpke3.ts"],"names":[],"mappings":"AAOA,OAAO,EAAE,KAAK,UAAU,EAAe,MAAM,UAAU,CAAC;AAExD,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,eAAe,CAAC;AAElD,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,cAAc,CAAC;AAGhD,uEAAuE;AACvE,wBAAgB,WAAW,IAAI,YAAY,CAO1C;AAED,gEAAgE;AAChE,wBAAgB,aAAa,CAAC,UAAU,EAAE,UAAU,GAAG,WAAW,CAYjE"}
|
package/esm/src/hpke3.js
ADDED
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { Aes128Gcm, CipherSuite, DhkemX25519HkdfSha256, HkdfSha256, } from "@hpke/core";
|
|
2
|
+
import { CoseHpkeAlg } from "./alg.js";
|
|
3
|
+
import { aesGcmContentCrypto } from "./contentAesGcm.js";
|
|
4
|
+
import { CoseEncrypt0Impl } from "./encrypt0.js";
|
|
5
|
+
import { CoseEncryptImpl } from "./encrypt.js";
|
|
6
|
+
/** DHKEM(X25519), HKDF-SHA256, AES-128-GCM — Integrated Encryption. */
|
|
7
|
+
export function createHpke3() {
|
|
8
|
+
const suite = new CipherSuite({
|
|
9
|
+
kem: new DhkemX25519HkdfSha256(),
|
|
10
|
+
kdf: new HkdfSha256(),
|
|
11
|
+
aead: new Aes128Gcm(),
|
|
12
|
+
});
|
|
13
|
+
return new CoseEncrypt0Impl(suite, CoseHpkeAlg.HPKE_3);
|
|
14
|
+
}
|
|
15
|
+
/** DHKEM(X25519), HKDF-SHA256, AES-128-GCM — Key Encryption. */
|
|
16
|
+
export function createHpke3Ke(contentAlg) {
|
|
17
|
+
const suite = new CipherSuite({
|
|
18
|
+
kem: new DhkemX25519HkdfSha256(),
|
|
19
|
+
kdf: new HkdfSha256(),
|
|
20
|
+
aead: new Aes128Gcm(),
|
|
21
|
+
});
|
|
22
|
+
return new CoseEncryptImpl(suite, CoseHpkeAlg.HPKE_3_KE, contentAlg, aesGcmContentCrypto);
|
|
23
|
+
}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { ContentAlg } from "./alg.js";
|
|
2
|
+
import type { CoseEncrypt0 } from "./encrypt0.js";
|
|
3
|
+
import type { CoseEncrypt } from "./encrypt.js";
|
|
4
|
+
/** DHKEM(X25519), HKDF-SHA256, ChaCha20Poly1305 — Integrated Encryption. */
|
|
5
|
+
export declare function createHpke4(): CoseEncrypt0;
|
|
6
|
+
/** DHKEM(X25519), HKDF-SHA256, ChaCha20Poly1305 — Key Encryption. */
|
|
7
|
+
export declare function createHpke4Ke(contentAlg: ContentAlg): CoseEncrypt;
|
|
8
|
+
//# sourceMappingURL=hpke4.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"hpke4.d.ts","sourceRoot":"","sources":["../../src/src/hpke4.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,UAAU,EAAe,MAAM,UAAU,CAAC;AAEnD,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,eAAe,CAAC;AAElD,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,cAAc,CAAC;AAgBhD,4EAA4E;AAC5E,wBAAgB,WAAW,IAAI,YAAY,CAO1C;AAED,qEAAqE;AACrE,wBAAgB,aAAa,CAAC,UAAU,EAAE,UAAU,GAAG,WAAW,CAUjE"}
|
package/esm/src/hpke4.js
ADDED
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import { CipherSuite, DhkemX25519HkdfSha256, HkdfSha256 } from "@hpke/core";
|
|
2
|
+
import { Chacha20Poly1305 } from "@hpke/chacha20poly1305";
|
|
3
|
+
import { ContentAlg, CoseHpkeAlg } from "./alg.js";
|
|
4
|
+
import { aesGcmContentCrypto } from "./contentAesGcm.js";
|
|
5
|
+
import { CoseEncrypt0Impl } from "./encrypt0.js";
|
|
6
|
+
import { CoseEncryptImpl } from "./encrypt.js";
|
|
7
|
+
const chacha20ContentCrypto = {
|
|
8
|
+
async seal(key, nonce, plaintext, aad) {
|
|
9
|
+
const chacha = new Chacha20Poly1305();
|
|
10
|
+
const ctx = chacha.createEncryptionContext(key);
|
|
11
|
+
return new Uint8Array(await ctx.seal(nonce, plaintext, aad));
|
|
12
|
+
},
|
|
13
|
+
async open(key, nonce, ciphertext, aad) {
|
|
14
|
+
const chacha = new Chacha20Poly1305();
|
|
15
|
+
const ctx = chacha.createEncryptionContext(key);
|
|
16
|
+
return new Uint8Array(await ctx.open(nonce, ciphertext, aad));
|
|
17
|
+
},
|
|
18
|
+
};
|
|
19
|
+
/** DHKEM(X25519), HKDF-SHA256, ChaCha20Poly1305 — Integrated Encryption. */
|
|
20
|
+
export function createHpke4() {
|
|
21
|
+
const suite = new CipherSuite({
|
|
22
|
+
kem: new DhkemX25519HkdfSha256(),
|
|
23
|
+
kdf: new HkdfSha256(),
|
|
24
|
+
aead: new Chacha20Poly1305(),
|
|
25
|
+
});
|
|
26
|
+
return new CoseEncrypt0Impl(suite, CoseHpkeAlg.HPKE_4);
|
|
27
|
+
}
|
|
28
|
+
/** DHKEM(X25519), HKDF-SHA256, ChaCha20Poly1305 — Key Encryption. */
|
|
29
|
+
export function createHpke4Ke(contentAlg) {
|
|
30
|
+
const suite = new CipherSuite({
|
|
31
|
+
kem: new DhkemX25519HkdfSha256(),
|
|
32
|
+
kdf: new HkdfSha256(),
|
|
33
|
+
aead: new Chacha20Poly1305(),
|
|
34
|
+
});
|
|
35
|
+
const cc = contentAlg === ContentAlg.CHACHA20POLY1305
|
|
36
|
+
? chacha20ContentCrypto
|
|
37
|
+
: aesGcmContentCrypto;
|
|
38
|
+
return new CoseEncryptImpl(suite, CoseHpkeAlg.HPKE_4_KE, contentAlg, cc);
|
|
39
|
+
}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { type ContentAlg } from "./alg.js";
|
|
2
|
+
import type { CoseEncrypt0 } from "./encrypt0.js";
|
|
3
|
+
import type { CoseEncrypt } from "./encrypt.js";
|
|
4
|
+
/** DHKEM(X448), HKDF-SHA512, AES-256-GCM — Integrated Encryption. */
|
|
5
|
+
export declare function createHpke5(): CoseEncrypt0;
|
|
6
|
+
/** DHKEM(X448), HKDF-SHA512, AES-256-GCM — Key Encryption. */
|
|
7
|
+
export declare function createHpke5Ke(contentAlg: ContentAlg): CoseEncrypt;
|
|
8
|
+
//# sourceMappingURL=hpke5.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"hpke5.d.ts","sourceRoot":"","sources":["../../src/src/hpke5.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,KAAK,UAAU,EAAe,MAAM,UAAU,CAAC;AAExD,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,eAAe,CAAC;AAElD,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,cAAc,CAAC;AAGhD,qEAAqE;AACrE,wBAAgB,WAAW,IAAI,YAAY,CAO1C;AAED,8DAA8D;AAC9D,wBAAgB,aAAa,CAAC,UAAU,EAAE,UAAU,GAAG,WAAW,CAYjE"}
|
package/esm/src/hpke5.js
ADDED
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { Aes256Gcm, CipherSuite, HkdfSha512 } from "@hpke/core";
|
|
2
|
+
import { DhkemX448HkdfSha512 } from "@hpke/dhkem-x448";
|
|
3
|
+
import { CoseHpkeAlg } from "./alg.js";
|
|
4
|
+
import { aesGcmContentCrypto } from "./contentAesGcm.js";
|
|
5
|
+
import { CoseEncrypt0Impl } from "./encrypt0.js";
|
|
6
|
+
import { CoseEncryptImpl } from "./encrypt.js";
|
|
7
|
+
/** DHKEM(X448), HKDF-SHA512, AES-256-GCM — Integrated Encryption. */
|
|
8
|
+
export function createHpke5() {
|
|
9
|
+
const suite = new CipherSuite({
|
|
10
|
+
kem: new DhkemX448HkdfSha512(),
|
|
11
|
+
kdf: new HkdfSha512(),
|
|
12
|
+
aead: new Aes256Gcm(),
|
|
13
|
+
});
|
|
14
|
+
return new CoseEncrypt0Impl(suite, CoseHpkeAlg.HPKE_5);
|
|
15
|
+
}
|
|
16
|
+
/** DHKEM(X448), HKDF-SHA512, AES-256-GCM — Key Encryption. */
|
|
17
|
+
export function createHpke5Ke(contentAlg) {
|
|
18
|
+
const suite = new CipherSuite({
|
|
19
|
+
kem: new DhkemX448HkdfSha512(),
|
|
20
|
+
kdf: new HkdfSha512(),
|
|
21
|
+
aead: new Aes256Gcm(),
|
|
22
|
+
});
|
|
23
|
+
return new CoseEncryptImpl(suite, CoseHpkeAlg.HPKE_5_KE, contentAlg, aesGcmContentCrypto);
|
|
24
|
+
}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { ContentAlg } from "./alg.js";
|
|
2
|
+
import type { CoseEncrypt0 } from "./encrypt0.js";
|
|
3
|
+
import type { CoseEncrypt } from "./encrypt.js";
|
|
4
|
+
/** DHKEM(X448), HKDF-SHA512, ChaCha20Poly1305 — Integrated Encryption. */
|
|
5
|
+
export declare function createHpke6(): CoseEncrypt0;
|
|
6
|
+
/** DHKEM(X448), HKDF-SHA512, ChaCha20Poly1305 — Key Encryption. */
|
|
7
|
+
export declare function createHpke6Ke(contentAlg: ContentAlg): CoseEncrypt;
|
|
8
|
+
//# sourceMappingURL=hpke6.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"hpke6.d.ts","sourceRoot":"","sources":["../../src/src/hpke6.ts"],"names":[],"mappings":"AAIA,OAAO,EAAE,UAAU,EAAe,MAAM,UAAU,CAAC;AAEnD,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,eAAe,CAAC;AAElD,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,cAAc,CAAC;AAgBhD,0EAA0E;AAC1E,wBAAgB,WAAW,IAAI,YAAY,CAO1C;AAED,mEAAmE;AACnE,wBAAgB,aAAa,CAAC,UAAU,EAAE,UAAU,GAAG,WAAW,CAUjE"}
|
package/esm/src/hpke6.js
ADDED
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import { CipherSuite, HkdfSha512 } from "@hpke/core";
|
|
2
|
+
import { DhkemX448HkdfSha512 } from "@hpke/dhkem-x448";
|
|
3
|
+
import { Chacha20Poly1305 } from "@hpke/chacha20poly1305";
|
|
4
|
+
import { ContentAlg, CoseHpkeAlg } from "./alg.js";
|
|
5
|
+
import { aesGcmContentCrypto } from "./contentAesGcm.js";
|
|
6
|
+
import { CoseEncrypt0Impl } from "./encrypt0.js";
|
|
7
|
+
import { CoseEncryptImpl } from "./encrypt.js";
|
|
8
|
+
const chacha20ContentCrypto = {
|
|
9
|
+
async seal(key, nonce, plaintext, aad) {
|
|
10
|
+
const chacha = new Chacha20Poly1305();
|
|
11
|
+
const ctx = chacha.createEncryptionContext(key);
|
|
12
|
+
return new Uint8Array(await ctx.seal(nonce, plaintext, aad));
|
|
13
|
+
},
|
|
14
|
+
async open(key, nonce, ciphertext, aad) {
|
|
15
|
+
const chacha = new Chacha20Poly1305();
|
|
16
|
+
const ctx = chacha.createEncryptionContext(key);
|
|
17
|
+
return new Uint8Array(await ctx.open(nonce, ciphertext, aad));
|
|
18
|
+
},
|
|
19
|
+
};
|
|
20
|
+
/** DHKEM(X448), HKDF-SHA512, ChaCha20Poly1305 — Integrated Encryption. */
|
|
21
|
+
export function createHpke6() {
|
|
22
|
+
const suite = new CipherSuite({
|
|
23
|
+
kem: new DhkemX448HkdfSha512(),
|
|
24
|
+
kdf: new HkdfSha512(),
|
|
25
|
+
aead: new Chacha20Poly1305(),
|
|
26
|
+
});
|
|
27
|
+
return new CoseEncrypt0Impl(suite, CoseHpkeAlg.HPKE_6);
|
|
28
|
+
}
|
|
29
|
+
/** DHKEM(X448), HKDF-SHA512, ChaCha20Poly1305 — Key Encryption. */
|
|
30
|
+
export function createHpke6Ke(contentAlg) {
|
|
31
|
+
const suite = new CipherSuite({
|
|
32
|
+
kem: new DhkemX448HkdfSha512(),
|
|
33
|
+
kdf: new HkdfSha512(),
|
|
34
|
+
aead: new Chacha20Poly1305(),
|
|
35
|
+
});
|
|
36
|
+
const cc = contentAlg === ContentAlg.CHACHA20POLY1305
|
|
37
|
+
? chacha20ContentCrypto
|
|
38
|
+
: aesGcmContentCrypto;
|
|
39
|
+
return new CoseEncryptImpl(suite, CoseHpkeAlg.HPKE_6_KE, contentAlg, cc);
|
|
40
|
+
}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { type ContentAlg } from "./alg.js";
|
|
2
|
+
import type { CoseEncrypt0 } from "./encrypt0.js";
|
|
3
|
+
import type { CoseEncrypt } from "./encrypt.js";
|
|
4
|
+
/** DHKEM(P-256), HKDF-SHA256, AES-256-GCM — Integrated Encryption. */
|
|
5
|
+
export declare function createHpke7(): CoseEncrypt0;
|
|
6
|
+
/** DHKEM(P-256), HKDF-SHA256, AES-256-GCM — Key Encryption. */
|
|
7
|
+
export declare function createHpke7Ke(contentAlg: ContentAlg): CoseEncrypt;
|
|
8
|
+
//# sourceMappingURL=hpke7.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"hpke7.d.ts","sourceRoot":"","sources":["../../src/src/hpke7.ts"],"names":[],"mappings":"AAOA,OAAO,EAAE,KAAK,UAAU,EAAe,MAAM,UAAU,CAAC;AAExD,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,eAAe,CAAC;AAElD,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,cAAc,CAAC;AAGhD,sEAAsE;AACtE,wBAAgB,WAAW,IAAI,YAAY,CAO1C;AAED,+DAA+D;AAC/D,wBAAgB,aAAa,CAAC,UAAU,EAAE,UAAU,GAAG,WAAW,CAYjE"}
|
package/esm/src/hpke7.js
ADDED
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { Aes256Gcm, CipherSuite, DhkemP256HkdfSha256, HkdfSha256, } from "@hpke/core";
|
|
2
|
+
import { CoseHpkeAlg } from "./alg.js";
|
|
3
|
+
import { aesGcmContentCrypto } from "./contentAesGcm.js";
|
|
4
|
+
import { CoseEncrypt0Impl } from "./encrypt0.js";
|
|
5
|
+
import { CoseEncryptImpl } from "./encrypt.js";
|
|
6
|
+
/** DHKEM(P-256), HKDF-SHA256, AES-256-GCM — Integrated Encryption. */
|
|
7
|
+
export function createHpke7() {
|
|
8
|
+
const suite = new CipherSuite({
|
|
9
|
+
kem: new DhkemP256HkdfSha256(),
|
|
10
|
+
kdf: new HkdfSha256(),
|
|
11
|
+
aead: new Aes256Gcm(),
|
|
12
|
+
});
|
|
13
|
+
return new CoseEncrypt0Impl(suite, CoseHpkeAlg.HPKE_7);
|
|
14
|
+
}
|
|
15
|
+
/** DHKEM(P-256), HKDF-SHA256, AES-256-GCM — Key Encryption. */
|
|
16
|
+
export function createHpke7Ke(contentAlg) {
|
|
17
|
+
const suite = new CipherSuite({
|
|
18
|
+
kem: new DhkemP256HkdfSha256(),
|
|
19
|
+
kdf: new HkdfSha256(),
|
|
20
|
+
aead: new Aes256Gcm(),
|
|
21
|
+
});
|
|
22
|
+
return new CoseEncryptImpl(suite, CoseHpkeAlg.HPKE_7_KE, contentAlg, aesGcmContentCrypto);
|
|
23
|
+
}
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
/** COSE header label constants. */
|
|
2
|
+
export declare const HeaderLabel: {
|
|
3
|
+
readonly ALG: 1;
|
|
4
|
+
readonly KID: 4;
|
|
5
|
+
readonly IV: 5;
|
|
6
|
+
readonly EK: -4;
|
|
7
|
+
readonly PSK_ID: -5;
|
|
8
|
+
};
|
|
9
|
+
/**
|
|
10
|
+
* Build Enc_structure for Integrated Encryption (COSE_Encrypt0) AAD.
|
|
11
|
+
*
|
|
12
|
+
* Enc_structure = [
|
|
13
|
+
* "Encrypt0", // context
|
|
14
|
+
* protected_header_bytes, // serialized protected header
|
|
15
|
+
* external_aad // external additional authenticated data
|
|
16
|
+
* ]
|
|
17
|
+
*/
|
|
18
|
+
export declare function buildEncStructure(protectedHeader: Uint8Array, externalAad: Uint8Array): Uint8Array;
|
|
19
|
+
/**
|
|
20
|
+
* Build Enc_structure for Key Encryption (COSE_Encrypt) AAD.
|
|
21
|
+
*
|
|
22
|
+
* Enc_structure = [
|
|
23
|
+
* "Encrypt",
|
|
24
|
+
* protected_header_bytes,
|
|
25
|
+
* external_aad
|
|
26
|
+
* ]
|
|
27
|
+
*/
|
|
28
|
+
export declare function buildEncStructureEncrypt(protectedHeader: Uint8Array, externalAad: Uint8Array): Uint8Array;
|
|
29
|
+
/**
|
|
30
|
+
* Build the HPKE info parameter for Key Encryption recipients
|
|
31
|
+
* using the Recipient_structure.
|
|
32
|
+
*
|
|
33
|
+
* Recipient_structure = [
|
|
34
|
+
* "HPKE Recipient", // context
|
|
35
|
+
* next_layer_alg, // content encryption algorithm (e.g. 1 for A128GCM)
|
|
36
|
+
* recipient_protected_header, // serialized recipient protected header
|
|
37
|
+
* recipient_extra_info // additional info for key derivation
|
|
38
|
+
* ]
|
|
39
|
+
*/
|
|
40
|
+
export declare function buildRecipientStructure(nextLayerAlg: number, recipientProtectedHeader: Uint8Array, recipientExtraInfo: Uint8Array): Uint8Array;
|
|
41
|
+
//# sourceMappingURL=structures.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"structures.d.ts","sourceRoot":"","sources":["../../src/src/structures.ts"],"names":[],"mappings":"AAGA,mCAAmC;AACnC,eAAO,MAAM,WAAW;;;;;;CAMd,CAAC;AAEX;;;;;;;;GAQG;AACH,wBAAgB,iBAAiB,CAC/B,eAAe,EAAE,UAAU,EAC3B,WAAW,EAAE,UAAU,GACtB,UAAU,CAOZ;AAED;;;;;;;;GAQG;AACH,wBAAgB,wBAAwB,CACtC,eAAe,EAAE,UAAU,EAC3B,WAAW,EAAE,UAAU,GACtB,UAAU,CAOZ;AAED;;;;;;;;;;GAUG;AACH,wBAAgB,uBAAuB,CACrC,YAAY,EAAE,MAAM,EACpB,wBAAwB,EAAE,UAAU,EACpC,kBAAkB,EAAE,UAAU,GAC7B,UAAU,CAQZ"}
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
import { encode } from "./cbor/encoder.js";
|
|
2
|
+
/** COSE header label constants. */
|
|
3
|
+
export const HeaderLabel = {
|
|
4
|
+
ALG: 1,
|
|
5
|
+
KID: 4,
|
|
6
|
+
IV: 5,
|
|
7
|
+
EK: -4,
|
|
8
|
+
PSK_ID: -5,
|
|
9
|
+
};
|
|
10
|
+
/**
|
|
11
|
+
* Build Enc_structure for Integrated Encryption (COSE_Encrypt0) AAD.
|
|
12
|
+
*
|
|
13
|
+
* Enc_structure = [
|
|
14
|
+
* "Encrypt0", // context
|
|
15
|
+
* protected_header_bytes, // serialized protected header
|
|
16
|
+
* external_aad // external additional authenticated data
|
|
17
|
+
* ]
|
|
18
|
+
*/
|
|
19
|
+
export function buildEncStructure(protectedHeader, externalAad) {
|
|
20
|
+
const structure = [
|
|
21
|
+
"Encrypt0",
|
|
22
|
+
protectedHeader,
|
|
23
|
+
externalAad,
|
|
24
|
+
];
|
|
25
|
+
return encode(structure);
|
|
26
|
+
}
|
|
27
|
+
/**
|
|
28
|
+
* Build Enc_structure for Key Encryption (COSE_Encrypt) AAD.
|
|
29
|
+
*
|
|
30
|
+
* Enc_structure = [
|
|
31
|
+
* "Encrypt",
|
|
32
|
+
* protected_header_bytes,
|
|
33
|
+
* external_aad
|
|
34
|
+
* ]
|
|
35
|
+
*/
|
|
36
|
+
export function buildEncStructureEncrypt(protectedHeader, externalAad) {
|
|
37
|
+
const structure = [
|
|
38
|
+
"Encrypt",
|
|
39
|
+
protectedHeader,
|
|
40
|
+
externalAad,
|
|
41
|
+
];
|
|
42
|
+
return encode(structure);
|
|
43
|
+
}
|
|
44
|
+
/**
|
|
45
|
+
* Build the HPKE info parameter for Key Encryption recipients
|
|
46
|
+
* using the Recipient_structure.
|
|
47
|
+
*
|
|
48
|
+
* Recipient_structure = [
|
|
49
|
+
* "HPKE Recipient", // context
|
|
50
|
+
* next_layer_alg, // content encryption algorithm (e.g. 1 for A128GCM)
|
|
51
|
+
* recipient_protected_header, // serialized recipient protected header
|
|
52
|
+
* recipient_extra_info // additional info for key derivation
|
|
53
|
+
* ]
|
|
54
|
+
*/
|
|
55
|
+
export function buildRecipientStructure(nextLayerAlg, recipientProtectedHeader, recipientExtraInfo) {
|
|
56
|
+
const structure = [
|
|
57
|
+
"HPKE Recipient",
|
|
58
|
+
nextLayerAlg,
|
|
59
|
+
recipientProtectedHeader,
|
|
60
|
+
recipientExtraInfo,
|
|
61
|
+
];
|
|
62
|
+
return encode(structure);
|
|
63
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,51 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@hpke/cose",
|
|
3
|
-
"version": "0.0.
|
|
4
|
-
"
|
|
5
|
-
"
|
|
3
|
+
"version": "0.0.1",
|
|
4
|
+
"description": "COSE-HPKE (draft-ietf-cose-hpke) encryption for COSE_Encrypt0 and COSE_Encrypt",
|
|
5
|
+
"keywords": [
|
|
6
|
+
"hpke",
|
|
7
|
+
"cose",
|
|
8
|
+
"rfc9180",
|
|
9
|
+
"encryption",
|
|
10
|
+
"security"
|
|
11
|
+
],
|
|
12
|
+
"author": "Ajitomi Daisuke",
|
|
13
|
+
"homepage": "https://github.com/dajiaji/hpke-js/tree/main/packages/cose#readme",
|
|
14
|
+
"repository": {
|
|
15
|
+
"type": "git",
|
|
16
|
+
"url": "git+https://github.com/dajiaji/hpke-js.git"
|
|
17
|
+
},
|
|
18
|
+
"license": "MIT",
|
|
19
|
+
"bugs": {
|
|
20
|
+
"url": "https://github.com/dajiaji/hpke-js/issues"
|
|
21
|
+
},
|
|
22
|
+
"main": "./esm/mod.js",
|
|
23
|
+
"module": "./esm/mod.js",
|
|
24
|
+
"types": "./esm/mod.d.ts",
|
|
25
|
+
"exports": {
|
|
26
|
+
".": {
|
|
27
|
+
"import": "./esm/mod.js",
|
|
28
|
+
"types": "./esm/mod.d.ts"
|
|
29
|
+
},
|
|
30
|
+
"./package.json": "./package.json"
|
|
31
|
+
},
|
|
32
|
+
"funding": {
|
|
33
|
+
"type": "github",
|
|
34
|
+
"url": "https://github.com/sponsors/dajiaji"
|
|
35
|
+
},
|
|
36
|
+
"sideEffects": false,
|
|
37
|
+
"engines": {
|
|
38
|
+
"node": ">=20.0.0"
|
|
39
|
+
},
|
|
40
|
+
"dependencies": {
|
|
41
|
+
"@hpke/chacha20poly1305": "^1.8.0",
|
|
42
|
+
"@hpke/core": "^1.9.0",
|
|
43
|
+
"@hpke/dhkem-x448": "^1.8.0"
|
|
44
|
+
},
|
|
45
|
+
"devDependencies": {
|
|
46
|
+
"@types/node": "^20.9.0",
|
|
47
|
+
"@deno/shim-deno": "~0.18.0",
|
|
48
|
+
"picocolors": "^1.0.0"
|
|
49
|
+
},
|
|
50
|
+
"_generatedBy": "dnt@dev"
|
|
6
51
|
}
|