gvisor.dev/gvisor@v0.0.0-20240520182842-f9d4d51c7e0f/pkg/crypto/crypto_stdlib.go (about) 1 // Copyright 2020 The gVisor Authors. 2 // 3 // Licensed under the Apache License, Version 2.0 (the "License"); 4 // you may not use this file except in compliance with the License. 5 // You may obtain a copy of the License at 6 // 7 // http://www.apache.org/licenses/LICENSE-2.0 8 // 9 // Unless required by applicable law or agreed to in writing, software 10 // distributed under the License is distributed on an "AS IS" BASIS, 11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 // See the License for the specific language governing permissions and 13 // limitations under the License. 14 15 //go:build !false 16 // +build !false 17 18 package crypto 19 20 import ( 21 "crypto/ecdsa" 22 "crypto/elliptic" 23 "crypto/sha512" 24 "fmt" 25 "math/big" 26 ) 27 28 // EcdsaP384Sha384Verify verifies the signature in r, s of hash using ECDSA 29 // P384 + SHA 384 and the public key, pub. Its return value records whether 30 // the signature is valid. 31 func EcdsaP384Sha384Verify(pub *ecdsa.PublicKey, data []byte, r, s *big.Int) (bool, error) { 32 if pub.Curve != elliptic.P384() { 33 return false, fmt.Errorf("unsupported key curve: want P-384, got %v", pub.Curve) 34 } 35 digest := sha512.Sum384(data) 36 return ecdsa.Verify(pub, digest[:], r, s), nil 37 } 38 39 // SumSha384 returns the SHA384 checksum of the data. 40 func SumSha384(data []byte) ([sha512.Size384]byte, error) { 41 return sha512.Sum384(data), nil 42 }