From 4780c3bf5110cddf0e1a305c0bb0aa6d45199651 Mon Sep 17 00:00:00 2001 From: andresruizfacebook <68402331+andresruizfacebook@users.noreply.github.com> Date: Thu, 20 Aug 2020 14:28:42 -0700 Subject: [PATCH 1/7] Create 2020-08-21-torchcsprng-release-blog.md --- _posts/2020-08-21-torchcsprng-release-blog.md | 67 +++++++++++++++++++ 1 file changed, 67 insertions(+) create mode 100644 _posts/2020-08-21-torchcsprng-release-blog.md diff --git a/_posts/2020-08-21-torchcsprng-release-blog.md b/_posts/2020-08-21-torchcsprng-release-blog.md new file mode 100644 index 000000000000..502c5b502649 --- /dev/null +++ b/_posts/2020-08-21-torchcsprng-release-blog.md @@ -0,0 +1,67 @@ +--- +layout: blog_detail +title: 'PyTorch framework for crypto secure random number generation, torchcsprng, now available' +author: Team PyTorch +--- + +One of the key components of modern cryptography is the pseudorandom number generator. The use of badly designed or inappropriate random number generators can often leave a good cryptosystem vulnerable to attack. Particular care must be taken to use a random number generator that is designed for cryptographic use, rather than a "general-purpose" random number generator which may be fine for some applications but not ones that are required to be cryptographically secure. Additionally, most pseudorandom number generators scale poorly to massively parallel high-performance computation because of their sequential nature. Others don’t satisfy cryptographically secure properties. + +## torchcsprng overview + +Historically, PyTorch had only two pseudorandom number generator implementations: Mersenne Twister for CPU and Nvidia’s cuRAND Philox for CUDA. Despite good performance properties, neither of them are suitable for cryptographic applications. Over the course of the past several months, the PyTorch team developed the torchcsprng extension API. Based on PyTorch dispatch mechanism and operator registration, it allows the users to extend c10::GeneratorImpl and implement their own custom pseudorandom number generator. + +torchcsprng generates a random 128-bit key on the CPU using one of its generators and then runs AES128 in [CTR mode](https://en.wikipedia.org/wiki/Block_cipher_mode_of_operation#Counter_(CTR)) either on CPU or GPU using CUDA. This then generates a random 128-bit state and applies a transformation function to map it to target tensor values. This approach is based on [Parallel Random Numbers: As Easy as 1, 2, 3 (John K. Salmon, Mark A. Moraes, Ron O. Dror, and David E. Shaw, D. E. Shaw Research)](http://www.thesalmons.org/john/random123/papers/random123sc11.pdf). It makes torchcsprng both crypto-secure and parallel on both CPU and CUDA. + +
+ +
+ +Since torchcsprng is a PyTorch extension, it is available on the platforms where PyTorch is available (support for Windows-CUDA will be available in the coming months). + +## Using torchcsprng + +The torchcsprng API is very simple to use and is fully compatible with the PyTorch random infrastructure: + +**Step 1: Install via binary distribution** + +Anaconda: + +`conda install torchcsprng -c pytorch` + +pip: + +`pip install torchcsprng` + +**Step 2: import packages as usual but add csprng** + +`import torch` +`import torchcsprng as csprng` + +**Step 3: Create a cryptographically secure pseudorandom number generator from /dev/urandom:** + +`urandom_gen = csprng.create_random_device_generator('/dev/urandom')` + +and simply use it with the existing PyTorch methods: + +`torch.randn(10, device='cpu', generator=urandom_gen)` + +**Step 4: Test with Cuda** + +One of the advantages of torchcsprng generators is that they can be used with both CPU and CUDA tensors: + +`torch.randn(10, device='cuda', generator=urandom_gen)` + +Another advantage of torchcsprng generators is that they are parallel on CPU unlike the default PyTorch CPU generator. + +## Getting Started + +The easiest way to get started with torchcsprng is by visiting the [GitHub page](https://github.com/pytorch/csprng) where you can find installation and build instructions, and more how-to examples. + +Cheers, +The PyTorch Team + + + + + + From 394cbd79a3a5725c082dd5e27162570ce035de10 Mon Sep 17 00:00:00 2001 From: andresruizfacebook <68402331+andresruizfacebook@users.noreply.github.com> Date: Thu, 20 Aug 2020 14:59:08 -0700 Subject: [PATCH 2/7] Rename 2020-08-21-torchcsprng-release-blog.md to 2020-08-20-torchcsprng-release-blog.md --- ...rng-release-blog.md => 2020-08-20-torchcsprng-release-blog.md} | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename _posts/{2020-08-21-torchcsprng-release-blog.md => 2020-08-20-torchcsprng-release-blog.md} (100%) diff --git a/_posts/2020-08-21-torchcsprng-release-blog.md b/_posts/2020-08-20-torchcsprng-release-blog.md similarity index 100% rename from _posts/2020-08-21-torchcsprng-release-blog.md rename to _posts/2020-08-20-torchcsprng-release-blog.md From 472206b25f9118c1f2ae62aedc31e40f53ea8c2f Mon Sep 17 00:00:00 2001 From: Woo Kim <39344090+wookim3@users.noreply.github.com> Date: Fri, 21 Aug 2020 09:38:43 -0700 Subject: [PATCH 3/7] Update 2020-08-20-torchcsprng-release-blog.md --- _posts/2020-08-20-torchcsprng-release-blog.md | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/_posts/2020-08-20-torchcsprng-release-blog.md b/_posts/2020-08-20-torchcsprng-release-blog.md index 502c5b502649..cf55dbf67355 100644 --- a/_posts/2020-08-20-torchcsprng-release-blog.md +++ b/_posts/2020-08-20-torchcsprng-release-blog.md @@ -4,13 +4,15 @@ title: 'PyTorch framework for crypto secure random number generation, torchcsprn author: Team PyTorch --- +[torchcsprng](https://github.com/pytorch/csprng) is a PyTorch [C++/CUDA extension](https://pytorch.org/tutorials/advanced/cpp_extension.html) that provides [cryptographically secure pseudorandom number generators](https://en.wikipedia.org/wiki/Cryptographically_secure_pseudorandom_number_generator) for PyTorch. + One of the key components of modern cryptography is the pseudorandom number generator. The use of badly designed or inappropriate random number generators can often leave a good cryptosystem vulnerable to attack. Particular care must be taken to use a random number generator that is designed for cryptographic use, rather than a "general-purpose" random number generator which may be fine for some applications but not ones that are required to be cryptographically secure. Additionally, most pseudorandom number generators scale poorly to massively parallel high-performance computation because of their sequential nature. Others don’t satisfy cryptographically secure properties. ## torchcsprng overview Historically, PyTorch had only two pseudorandom number generator implementations: Mersenne Twister for CPU and Nvidia’s cuRAND Philox for CUDA. Despite good performance properties, neither of them are suitable for cryptographic applications. Over the course of the past several months, the PyTorch team developed the torchcsprng extension API. Based on PyTorch dispatch mechanism and operator registration, it allows the users to extend c10::GeneratorImpl and implement their own custom pseudorandom number generator. -torchcsprng generates a random 128-bit key on the CPU using one of its generators and then runs AES128 in [CTR mode](https://en.wikipedia.org/wiki/Block_cipher_mode_of_operation#Counter_(CTR)) either on CPU or GPU using CUDA. This then generates a random 128-bit state and applies a transformation function to map it to target tensor values. This approach is based on [Parallel Random Numbers: As Easy as 1, 2, 3 (John K. Salmon, Mark A. Moraes, Ron O. Dror, and David E. Shaw, D. E. Shaw Research)](http://www.thesalmons.org/john/random123/papers/random123sc11.pdf). It makes torchcsprng both crypto-secure and parallel on both CPU and CUDA. +torchcsprng generates a random 128-bit key on the CPU using one of its generators and then runs AES128 in [CTR mode](https://en.wikipedia.org/wiki/Block_cipher_mode_of_operation#Counter_(CTR)) either on CPU or GPU using CUDA. This then generates a random 128-bit state and applies a transformation function to map it to target tensor values. This approach is based on [Parallel Random Numbers: As Easy as 1, 2, 3 (John K. Salmon, Mark A. Moraes, Ron O. Dror, and David E. Shaw, D. E. Shaw Research)](http://www.thesalmons.org/john/random123/papers/random123sc11.pdf). It makes torchcsprng both crypto-secure and parallel on both CPU and CUDA.
From 34442c2a09a6c3c2cf217d8a44295ac04f74c618 Mon Sep 17 00:00:00 2001 From: Woo Kim <39344090+wookim3@users.noreply.github.com> Date: Fri, 21 Aug 2020 13:44:33 -0700 Subject: [PATCH 4/7] Update 2020-08-20-torchcsprng-release-blog.md --- _posts/2020-08-20-torchcsprng-release-blog.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/_posts/2020-08-20-torchcsprng-release-blog.md b/_posts/2020-08-20-torchcsprng-release-blog.md index cf55dbf67355..121c2229508b 100644 --- a/_posts/2020-08-20-torchcsprng-release-blog.md +++ b/_posts/2020-08-20-torchcsprng-release-blog.md @@ -15,7 +15,7 @@ Historically, PyTorch had only two pseudorandom number generator implementations torchcsprng generates a random 128-bit key on the CPU using one of its generators and then runs AES128 in [CTR mode](https://en.wikipedia.org/wiki/Block_cipher_mode_of_operation#Counter_(CTR)) either on CPU or GPU using CUDA. This then generates a random 128-bit state and applies a transformation function to map it to target tensor values. This approach is based on [Parallel Random Numbers: As Easy as 1, 2, 3 (John K. Salmon, Mark A. Moraes, Ron O. Dror, and David E. Shaw, D. E. Shaw Research)](http://www.thesalmons.org/john/random123/papers/random123sc11.pdf). It makes torchcsprng both crypto-secure and parallel on both CPU and CUDA.
- +
Since torchcsprng is a PyTorch extension, it is available on the platforms where PyTorch is available (support for Windows-CUDA will be available in the coming months). From a846a511859a20ef29fc3d3c81adcdfe2d5fdbec Mon Sep 17 00:00:00 2001 From: Woo Kim <39344090+wookim3@users.noreply.github.com> Date: Fri, 21 Aug 2020 15:18:13 -0700 Subject: [PATCH 5/7] Update 2020-08-20-torchcsprng-release-blog.md --- _posts/2020-08-20-torchcsprng-release-blog.md | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/_posts/2020-08-20-torchcsprng-release-blog.md b/_posts/2020-08-20-torchcsprng-release-blog.md index 121c2229508b..9c7b19f36f1c 100644 --- a/_posts/2020-08-20-torchcsprng-release-blog.md +++ b/_posts/2020-08-20-torchcsprng-release-blog.md @@ -1,6 +1,6 @@ --- layout: blog_detail -title: 'PyTorch framework for crypto secure random number generation, torchcsprng, now available' +title: 'PyTorch framework for cryptographically secure random number generation, torchcsprng, now available' author: Team PyTorch --- @@ -36,8 +36,10 @@ pip: **Step 2: import packages as usual but add csprng** -`import torch` -`import torchcsprng as csprng` +```python +import torch +import torchcsprng as csprng + ``` **Step 3: Create a cryptographically secure pseudorandom number generator from /dev/urandom:** @@ -60,6 +62,7 @@ Another advantage of torchcsprng generators is that they are parallel on CPU unl The easiest way to get started with torchcsprng is by visiting the [GitHub page](https://github.com/pytorch/csprng) where you can find installation and build instructions, and more how-to examples. Cheers, + The PyTorch Team From 80320e4295ca3073e7f8891518e3a359dc4bcdfd Mon Sep 17 00:00:00 2001 From: Woo Kim <39344090+wookim3@users.noreply.github.com> Date: Sun, 23 Aug 2020 18:17:49 -0700 Subject: [PATCH 6/7] Update 2020-08-20-torchcsprng-release-blog.md Code block change and putting the citation --- _posts/2020-08-20-torchcsprng-release-blog.md | 26 +++++++++++++------ 1 file changed, 18 insertions(+), 8 deletions(-) diff --git a/_posts/2020-08-20-torchcsprng-release-blog.md b/_posts/2020-08-20-torchcsprng-release-blog.md index 9c7b19f36f1c..ab967ae6054c 100644 --- a/_posts/2020-08-20-torchcsprng-release-blog.md +++ b/_posts/2020-08-20-torchcsprng-release-blog.md @@ -6,7 +6,7 @@ author: Team PyTorch [torchcsprng](https://github.com/pytorch/csprng) is a PyTorch [C++/CUDA extension](https://pytorch.org/tutorials/advanced/cpp_extension.html) that provides [cryptographically secure pseudorandom number generators](https://en.wikipedia.org/wiki/Cryptographically_secure_pseudorandom_number_generator) for PyTorch. -One of the key components of modern cryptography is the pseudorandom number generator. The use of badly designed or inappropriate random number generators can often leave a good cryptosystem vulnerable to attack. Particular care must be taken to use a random number generator that is designed for cryptographic use, rather than a "general-purpose" random number generator which may be fine for some applications but not ones that are required to be cryptographically secure. Additionally, most pseudorandom number generators scale poorly to massively parallel high-performance computation because of their sequential nature. Others don’t satisfy cryptographically secure properties. +One of the key components of modern cryptography is the pseudorandom number generator. Katz and Lindell stated, "The use of badly designed or inappropriate random number generators can often leave a good cryptosystem vulnerable to attack. Particular care must be taken to use a random number generator that is designed for cryptographic use, rather than a 'general-purpose' random number generator which may be fine for some applications but not ones that are required to be cryptographically secure."[1] Additionally, most pseudorandom number generators scale poorly to massively parallel high-performance computation because of their sequential nature. Others don’t satisfy cryptographically secure properties. ## torchcsprng overview @@ -28,11 +28,15 @@ The torchcsprng API is very simple to use and is fully compatible with the PyTor Anaconda: -`conda install torchcsprng -c pytorch` +```python +conda install torchcsprng -c pytorch + ``` pip: -`pip install torchcsprng` +```python +pip install torchcsprng + ``` **Step 2: import packages as usual but add csprng** @@ -43,17 +47,23 @@ import torchcsprng as csprng **Step 3: Create a cryptographically secure pseudorandom number generator from /dev/urandom:** -`urandom_gen = csprng.create_random_device_generator('/dev/urandom')` - +```python +urandom_gen = csprng.create_random_device_generator('/dev/urandom') + ``` + and simply use it with the existing PyTorch methods: -`torch.randn(10, device='cpu', generator=urandom_gen)` +```python +torch.randn(10, device='cpu', generator=urandom_gen) + ``` **Step 4: Test with Cuda** One of the advantages of torchcsprng generators is that they can be used with both CPU and CUDA tensors: -`torch.randn(10, device='cuda', generator=urandom_gen)` +```python +torch.randn(10, device='cuda', generator=urandom_gen) + ``` Another advantage of torchcsprng generators is that they are parallel on CPU unlike the default PyTorch CPU generator. @@ -65,7 +75,7 @@ Cheers, The PyTorch Team - +[1] [Introduction to Modern Cryptography: Principles and Protocols (Chapman & Hall/CRC Cryptography and Network Security Series)](https://www.amazon.com/Introduction-Modern-Cryptography-Principles-Protocols/dp/1584885513) by Jonathan Katz and Yehuda Lindell From ba45d5217a64caa7dea509508e03015eab4b9811 Mon Sep 17 00:00:00 2001 From: andresruizfacebook <68402331+andresruizfacebook@users.noreply.github.com> Date: Mon, 24 Aug 2020 08:46:56 -0700 Subject: [PATCH 7/7] Rename 2020-08-20-torchcsprng-release-blog.md to 2020-08-24-torchcsprng-release-blog.md --- ...rng-release-blog.md => 2020-08-24-torchcsprng-release-blog.md} | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename _posts/{2020-08-20-torchcsprng-release-blog.md => 2020-08-24-torchcsprng-release-blog.md} (100%) diff --git a/_posts/2020-08-20-torchcsprng-release-blog.md b/_posts/2020-08-24-torchcsprng-release-blog.md similarity index 100% rename from _posts/2020-08-20-torchcsprng-release-blog.md rename to _posts/2020-08-24-torchcsprng-release-blog.md