Merge tag 'next-20220328' of https://source.denx.de/u-boot/custodians/u-boot-video...
[platform/kernel/u-boot.git] / include / u-boot / rsa.h
index fd08a61..b9634e3 100644 (file)
@@ -1,3 +1,4 @@
+/* SPDX-License-Identifier: GPL-2.0+ */
 /*
  * Copyright (c) 2013, Google Inc.
  *
@@ -5,8 +6,6 @@
  *
  * (C) Copyright 2000-2006
  * Wolfgang Denk, DENX Software Engineering, wd@denx.de.
- *
- * SPDX-License-Identifier:    GPL-2.0+
  */
 
 #ifndef _RSA_H
@@ -30,7 +29,8 @@ struct rsa_public_key {
        uint64_t exponent;      /* public exponent */
 };
 
-#if IMAGE_ENABLE_SIGN
+struct image_sign_info;
+
 /**
  * sign() - calculate and return signature for given input data
  *
@@ -61,26 +61,26 @@ int rsa_sign(struct image_sign_info *info,
  *
  * @info:      Specifies key and FIT information
  * @keydest:   Destination FDT blob for public key data
- * @return: 0, on success, -ENOSPC if the keydest FDT blob ran out of space,
-               other -ve value on error
+ * @return: node offset within the FDT blob where the data was written on
+ *     success, -ENOSPC if the keydest FDT blob ran out of space, other -ve
+ *     value on other error
 */
 int rsa_add_verify_data(struct image_sign_info *info, void *keydest);
-#else
-static inline int rsa_sign(struct image_sign_info *info,
-               const struct image_region region[], int region_count,
-               uint8_t **sigp, uint *sig_len)
-{
-       return -ENXIO;
-}
-
-static inline int rsa_add_verify_data(struct image_sign_info *info,
-                                     void *keydest)
-{
-       return -ENXIO;
-}
-#endif
 
-#if IMAGE_ENABLE_VERIFY
+/**
+ * rsa_verify_hash() - Verify a signature against a hash
+ *
+ * Verify a RSA PKCS1.5 signature against an expected hash.
+ *
+ * @info:      Specifies key and FIT information
+ * @hash:      Hash according to algorithm specified in @info
+ * @sig:       Signature
+ * @sig_len:   Number of bytes in signature
+ * Return: 0 if verified, -ve on error
+ */
+int rsa_verify_hash(struct image_sign_info *info,
+                   const uint8_t *hash, uint8_t *sig, uint sig_len);
+
 /**
  * rsa_verify() - Verify a signature against some data
  *
@@ -91,21 +91,27 @@ static inline int rsa_add_verify_data(struct image_sign_info *info,
  * @data_len:  Data length
  * @sig:       Signature
  * @sig_len:   Number of bytes in signature
- * @return 0 if verified, -ve on error
+ * Return: 0 if verified, -ve on error
  */
 int rsa_verify(struct image_sign_info *info,
               const struct image_region region[], int region_count,
               uint8_t *sig, uint sig_len);
-#else
-static inline int rsa_verify(struct image_sign_info *info,
-               const struct image_region region[], int region_count,
-               uint8_t *sig, uint sig_len)
-{
-       return -ENXIO;
-}
-#endif
+
+int rsa_verify_with_pkey(struct image_sign_info *info,
+                        const void *hash, uint8_t *sig, uint sig_len);
+
+int padding_pkcs_15_verify(struct image_sign_info *info,
+                          uint8_t *msg, int msg_len,
+                          const uint8_t *hash, int hash_len);
+
+int padding_pss_verify(struct image_sign_info *info,
+                      uint8_t *msg, int msg_len,
+                      const uint8_t *hash, int hash_len);
+
+#define RSA_DEFAULT_PADDING_NAME               "pkcs-1.5"
 
 #define RSA2048_BYTES  (2048 / 8)
+#define RSA3072_BYTES  (3072 / 8)
 #define RSA4096_BYTES  (4096 / 8)
 
 /* This is the minimum/maximum key size we support, in bits */