File: keysize.go

package info (click to toggle)
acmetool 0.2.2-3
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 792 kB
  • sloc: sh: 349; makefile: 105
file content (48 lines) | stat: -rw-r--r-- 900 bytes parent folder | download | duplicates (6)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
package storageops

import "crypto/elliptic"

const (
	minRSASize     = 2048
	defaultRSASize = 2048
	maxRSASize     = 4096
)

func clampRSAKeySize(sz int) int {
	if sz == 0 {
		return defaultRSASize
	}
	if sz < minRSASize {
		return minRSASize
	}
	if sz > maxRSASize {
		return maxRSASize
	}
	return sz
}

const defaultCurve = "nistp256"

// Make sure the curve name is valid and use a default curve name. "clamp" is
// not the sanest name here but is consistent with clampRSAKeySize.
func clampECDSACurve(curveName string) string {
	switch curveName {
	case "nistp256", "nistp384", "nistp521":
		return curveName
	default:
		return defaultCurve
	}
}

func getECDSACurve(curveName string) elliptic.Curve {
	switch clampECDSACurve(curveName) {
	case "nistp256":
		return elliptic.P256()
	case "nistp384":
		return elliptic.P384()
	case "nistp521":
		return elliptic.P521()
	default:
		return nil
	}
}