Skip to content

Commit

Permalink
Adding support for BGV (SEAL 4.0.0) (#126)
Browse files Browse the repository at this point in the history
* Adding support for BGV

* change test var names

* Fix failing tests

* working tests

* add more tests

* update lock file
  • Loading branch information
s0l0ist authored Mar 19, 2022
1 parent e200b74 commit ab6b9a0
Show file tree
Hide file tree
Showing 37 changed files with 7,756 additions and 6,019 deletions.
8 changes: 8 additions & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,14 @@
See [Microsoft's Change log](https://github.com/microsoft/SEAL/blob/master/CHANGES.md)
for more details on each SEAL version change.

## Version 5.0.0

Feat:

- Updated to SEAL 4.0.0
- Added tests for the new `BGV` scheme type
- Added missing public getter `EncryptionParameters.paramsId`

## Version 4.6.4

Feat:
Expand Down
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "node-seal",
"version": "4.6.4",
"version": "5.0.0",
"description": "Homomorphic Encryption for TypeScript or JavaScript using Microsoft SEAL",
"repository": {
"type": "git",
Expand Down Expand Up @@ -96,4 +96,4 @@
"ts-jest": "^27.1.3",
"typescript": "^4.6.2"
}
}
}
2 changes: 1 addition & 1 deletion scripts/seal-build-js.sh
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ emcc \
-Wall \
-flto \
-O2 \
libseal-3.7.a \
libseal-4.0.a \
--bind \
-o "${FILE_NAME}" \
-s WASM=0 \
Expand Down
2 changes: 1 addition & 1 deletion scripts/seal-build-wasm.sh
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ emcc \
-Wall \
-flto \
-O3 \
libseal-3.7.a \
libseal-4.0.a \
--bind \
-o "${FILE_NAME}" \
-s WASM=1 \
Expand Down
71 changes: 70 additions & 1 deletion src/__tests__/encryption-parameters.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ describe('EncryptionParameters', () => {
expect(encParms).toHaveProperty('polyModulusDegree')
expect(encParms).toHaveProperty('coeffModulus')
expect(encParms).toHaveProperty('plainModulus')
expect(encParms).toHaveProperty('parmsId')
expect(encParms).toHaveProperty('save')
expect(encParms).toHaveProperty('saveArray')
expect(encParms).toHaveProperty('load')
Expand Down Expand Up @@ -81,7 +82,13 @@ describe('EncryptionParameters', () => {
expect(spyOn).toHaveBeenCalledWith(4096)
expect(encParms.polyModulusDegree).toEqual(4096)
})

test('It should set the poly modulus degree (bgv)', () => {
const encParms = seal.EncryptionParameters(seal.SchemeType.bgv)
const spyOn = jest.spyOn(encParms, 'setPolyModulusDegree')
encParms.setPolyModulusDegree(4096)
expect(spyOn).toHaveBeenCalledWith(4096)
expect(encParms.polyModulusDegree).toEqual(4096)
})
test('It should fail to set the coeff modulus (none)', () => {
const encParms = seal.EncryptionParameters()
const coeffModulus = seal.CoeffModulus.BFVDefault(
Expand Down Expand Up @@ -111,6 +118,25 @@ describe('EncryptionParameters', () => {
])
)
})
test('It should set the coeff modulus (bgv)', () => {
const encParms = seal.EncryptionParameters(seal.SchemeType.bgv)
const coeffModulus = seal.CoeffModulus.BFVDefault(
4096,
seal.SecurityLevel.tc128
)
const spyOn = jest.spyOn(encParms, 'setCoeffModulus')
encParms.setCoeffModulus(coeffModulus)
expect(spyOn).toHaveBeenCalledWith(coeffModulus)
const coeffModArray = encParms.coeffModulus
expect(coeffModArray.constructor).toBe(BigUint64Array)
expect(coeffModArray).toEqual(
BigUint64Array.from([
BigInt('68719403009'),
BigInt('68719230977'),
BigInt('137438822401')
])
)
})
test('It should set the coeff modulus (ckks)', () => {
const encParms = seal.EncryptionParameters(seal.SchemeType.ckks)
const coeffModulus = seal.CoeffModulus.Create(
Expand Down Expand Up @@ -146,6 +172,15 @@ describe('EncryptionParameters', () => {
expect(typeof encParms.plainModulus.value).toBe('bigint')
expect(encParms.plainModulus.value).toBe(BigInt('786433'))
})
test('It should set the plain modulus (bgv)', () => {
const encParms = seal.EncryptionParameters(seal.SchemeType.bgv)
const plainModulus = seal.Modulus(BigInt('786433'))
const spyOn = jest.spyOn(encParms, 'setPlainModulus')
encParms.setPlainModulus(plainModulus)
expect(spyOn).toHaveBeenCalledWith(plainModulus)
expect(typeof encParms.plainModulus.value).toBe('bigint')
expect(encParms.plainModulus.value).toBe(BigInt('786433'))
})
test('It should return the scheme (none)', () => {
const encParms = seal.EncryptionParameters()
expect(encParms.scheme).toEqual(seal.SchemeType.none)
Expand All @@ -160,6 +195,11 @@ describe('EncryptionParameters', () => {
encParms.setPolyModulusDegree(4096)
expect(encParms.polyModulusDegree).toEqual(4096)
})
test('It should return the poly modulus degree (bgv)', () => {
const encParms = seal.EncryptionParameters(seal.SchemeType.bgv)
encParms.setPolyModulusDegree(4096)
expect(encParms.polyModulusDegree).toEqual(4096)
})
test('It should return the poly modulus degree (ckks)', () => {
const encParms = seal.EncryptionParameters(seal.SchemeType.ckks)
encParms.setPolyModulusDegree(4096)
Expand Down Expand Up @@ -189,6 +229,21 @@ describe('EncryptionParameters', () => {
])
)
})
test('It should return the coeff modulus (bgv)', () => {
const encParms = seal.EncryptionParameters(seal.SchemeType.bgv)
encParms.setCoeffModulus(
seal.CoeffModulus.BFVDefault(4096, seal.SecurityLevel.tc128)
)
const coeffModArray = encParms.coeffModulus
expect(coeffModArray.constructor).toBe(BigUint64Array)
expect(coeffModArray).toEqual(
BigUint64Array.from([
BigInt('68719403009'),
BigInt('68719230977'),
BigInt('137438822401')
])
)
})
test('It should return the coeff modulus (ckks)', () => {
const encParms = seal.EncryptionParameters(seal.SchemeType.ckks)
encParms.setCoeffModulus(
Expand All @@ -215,6 +270,11 @@ describe('EncryptionParameters', () => {
encParms.setPlainModulus(seal.Modulus(BigInt('786433')))
expect(encParms.plainModulus.value).toBe(BigInt(786433))
})
test('It should return the plain modulus (bgv)', () => {
const encParms = seal.EncryptionParameters(seal.SchemeType.bgv)
encParms.setPlainModulus(seal.Modulus(BigInt('786433')))
expect(encParms.plainModulus.value).toBe(BigInt(786433))
})
test('It should fail to return the plain modulus (ckks)', () => {
const encParms = seal.EncryptionParameters(seal.SchemeType.ckks)
expect(() =>
Expand Down Expand Up @@ -252,6 +312,15 @@ describe('EncryptionParameters', () => {
expect(spyOn).toHaveBeenCalled()
expect(array.constructor).toBe(Uint8Array)
})
test('It should return a parms id type', () => {
const encParms = seal.EncryptionParameters(seal.SchemeType.bfv)
const parms = encParms.parmsId
const values = parms.values
expect(values.constructor).toBe(BigUint64Array)
values.forEach(x => {
expect(typeof x).toBe('bigint')
})
})
test('It should load from a string', () => {
const encParms = seal.EncryptionParameters()
const str = encParms.save()
Expand Down
Loading

0 comments on commit ab6b9a0

Please sign in to comment.