rsa_common.go 625 Bytes
Newer Older
1 2 3
package crypto

import (
4
	"fmt"
5
	"os"
6 7
)

8
// WeakRsaKeyEnv is an environment variable which, when set, lowers the
9 10
// minimum required bits of RSA keys to 512. This should be used exclusively in
// test situations.
tavit ohanian's avatar
tavit ohanian committed
11
const WeakRsaKeyEnv = "P2P_ALLOW_WEAK_RSA_KEYS"
12 13

var MinRsaKeyBits = 2048
14

15
// ErrRsaKeyTooSmall is returned when trying to generate or parse an RSA key
16 17 18 19
// that's smaller than MinRsaKeyBits bits. In test
var ErrRsaKeyTooSmall error

func init() {
20
	if _, ok := os.LookupEnv(WeakRsaKeyEnv); ok {
21 22 23 24 25
		MinRsaKeyBits = 512
	}

	ErrRsaKeyTooSmall = fmt.Errorf("rsa keys must be >= %d bits to be useful", MinRsaKeyBits)
}