in image/image.go [750:775]
func DecryptHw(img Image, secret []byte) (Image, error) {
dup := img.Clone()
tlvs := dup.FindProtTlvs(IMAGE_TLV_AES_NONCE)
if len(tlvs) != 1 {
// try to find legacy TLV
tlvs := dup.FindProtTlvs(IMAGE_TLV_AES_NONCE_LEGACY)
if len(tlvs) != 1 {
return dup, errors.Errorf(
"failed to decrypt hw-encrypted image: "+
"wrong count of AES nonce TLVs; have=%d want=1", len(tlvs))
}
}
nonce := tlvs[0].Data
body, err := sec.EncryptAES(dup.Body, secret, nonce)
if err != nil {
return dup, err
}
dup.Body = body
return dup, nil
}