Skip to content

Commit 80320e4

Browse files
authored
Update 2020-08-20-torchcsprng-release-blog.md
Code block change and putting the citation
1 parent a846a51 commit 80320e4

File tree

1 file changed

+18
-8
lines changed

1 file changed

+18
-8
lines changed

_posts/2020-08-20-torchcsprng-release-blog.md

+18-8
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ author: Team PyTorch
66

77
[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.
88

9-
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.
9+
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.
1010

1111
## torchcsprng overview
1212

@@ -28,11 +28,15 @@ The torchcsprng API is very simple to use and is fully compatible with the PyTor
2828

2929
Anaconda:
3030

31-
`conda install torchcsprng -c pytorch`
31+
```python
32+
conda install torchcsprng -c pytorch
33+
```
3234

3335
pip:
3436

35-
`pip install torchcsprng`
37+
```python
38+
pip install torchcsprng
39+
```
3640

3741
**Step 2: import packages as usual but add csprng**
3842

@@ -43,17 +47,23 @@ import torchcsprng as csprng
4347

4448
**Step 3: Create a cryptographically secure pseudorandom number generator from /dev/urandom:**
4549

46-
`urandom_gen = csprng.create_random_device_generator('/dev/urandom')`
47-
50+
```python
51+
urandom_gen = csprng.create_random_device_generator('/dev/urandom')
52+
```
53+
4854
and simply use it with the existing PyTorch methods:
4955

50-
`torch.randn(10, device='cpu', generator=urandom_gen)`
56+
```python
57+
torch.randn(10, device='cpu', generator=urandom_gen)
58+
```
5159

5260
**Step 4: Test with Cuda**
5361

5462
One of the advantages of torchcsprng generators is that they can be used with both CPU and CUDA tensors:
5563

56-
`torch.randn(10, device='cuda', generator=urandom_gen)`
64+
```python
65+
torch.randn(10, device='cuda', generator=urandom_gen)
66+
```
5767

5868
Another advantage of torchcsprng generators is that they are parallel on CPU unlike the default PyTorch CPU generator.
5969

@@ -65,7 +75,7 @@ Cheers,
6575

6676
The PyTorch Team
6777

68-
78+
[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
6979

7080

7181

0 commit comments

Comments
 (0)