-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
aeb9f9b
commit 321a163
Showing
3 changed files
with
165 additions
and
145 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
#!/usr/bin/python | ||
# | ||
# Copyright 2023 Google LLC | ||
# | ||
# Licensed under the Apache License, Version 2.0 (the "License"); | ||
# you may not use this file except in compliance with the License. | ||
# You may obtain a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, | ||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
# See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
import tensorflow as tf | ||
import tf_shell | ||
import tempfile | ||
|
||
|
||
class TestShellContext(tf.test.TestCase): | ||
def test_key_save(self): | ||
# Num plaintext bits: 48, noise bits: 65 | ||
# Max plaintext value: 127, est error: 3.840% | ||
context = tf_shell.create_context64( | ||
log_n=11, | ||
main_moduli=[288230376151748609, 18014398509506561], | ||
plaintext_modulus=281474976768001, | ||
scaling_factor=1052673, | ||
) | ||
key_path = tempfile.mkdtemp() # Every trace gets a new key. | ||
key = tf_shell.create_key64(context, key_path + "cached_test_key") | ||
|
||
a = tf.ones([2**11, 2, 3], dtype=tf.float32) * 10 | ||
ea = tf_shell.to_encrypted(a, key, context) | ||
|
||
# Try decrypting with the cached key | ||
cached_key = tf_shell.create_key64(context, key_path + "cached_test_key") | ||
self.assertAllClose(a, tf_shell.to_tensorflow(ea, cached_key)) | ||
|
||
|
||
if __name__ == "__main__": | ||
tf.test.main() |