Move psa_crypto_init() after other init calls

Signed-off-by: Przemek Stekiel <przemyslaw.stekiel@mobica.com>
This commit is contained in:
Przemek Stekiel 2023-04-17 11:10:05 +02:00
parent 6260ee9cab
commit a0a1c1eab5
13 changed files with 119 additions and 118 deletions

View file

@ -145,15 +145,6 @@ int main(int argc, char *argv[])
char *p, *q;
const char *pers = "cert_app";
#if defined(MBEDTLS_USE_PSA_CRYPTO)
psa_status_t status = psa_crypto_init();
if (status != PSA_SUCCESS) {
mbedtls_fprintf(stderr, "Failed to initialize PSA Crypto implementation: %d\n",
(int) status);
goto exit;
}
#endif /* MBEDTLS_USE_PSA_CRYPTO */
/*
* Set to sane values
*/
@ -171,6 +162,15 @@ int main(int argc, char *argv[])
memset(&cacrl, 0, sizeof(mbedtls_x509_crl));
#endif
#if defined(MBEDTLS_USE_PSA_CRYPTO)
psa_status_t status = psa_crypto_init();
if (status != PSA_SUCCESS) {
mbedtls_fprintf(stderr, "Failed to initialize PSA Crypto implementation: %d\n",
(int) status);
goto exit;
}
#endif /* MBEDTLS_USE_PSA_CRYPTO */
if (argc < 2) {
usage:
mbedtls_printf(USAGE);

View file

@ -172,6 +172,15 @@ int main(int argc, char *argv[])
const char *pers = "csr example app";
mbedtls_x509_san_list *cur, *prev;
/*
* Set to sane values
*/
mbedtls_x509write_csr_init(&req);
mbedtls_pk_init(&key);
mbedtls_ctr_drbg_init(&ctr_drbg);
memset(buf, 0, sizeof(buf));
mbedtls_entropy_init(&entropy);
#if defined(MBEDTLS_USE_PSA_CRYPTO)
psa_status_t status = psa_crypto_init();
if (status != PSA_SUCCESS) {
@ -181,14 +190,6 @@ int main(int argc, char *argv[])
}
#endif /* MBEDTLS_USE_PSA_CRYPTO */
/*
* Set to sane values
*/
mbedtls_x509write_csr_init(&req);
mbedtls_pk_init(&key);
mbedtls_ctr_drbg_init(&ctr_drbg);
memset(buf, 0, sizeof(buf));
if (argc < 2) {
usage:
mbedtls_printf(USAGE);
@ -397,7 +398,6 @@ usage:
mbedtls_printf(" . Seeding the random number generator...");
fflush(stdout);
mbedtls_entropy_init(&entropy);
if ((ret = mbedtls_ctr_drbg_seed(&ctr_drbg, mbedtls_entropy_func, &entropy,
(const unsigned char *) pers,
strlen(pers))) != 0) {

View file

@ -315,15 +315,6 @@ int main(int argc, char *argv[])
mbedtls_ctr_drbg_context ctr_drbg;
const char *pers = "crt example app";
#if defined(MBEDTLS_USE_PSA_CRYPTO)
psa_status_t status = psa_crypto_init();
if (status != PSA_SUCCESS) {
mbedtls_fprintf(stderr, "Failed to initialize PSA Crypto implementation: %d\n",
(int) status);
goto exit;
}
#endif /* MBEDTLS_USE_PSA_CRYPTO */
/*
* Set to sane values
*/
@ -339,6 +330,15 @@ int main(int argc, char *argv[])
memset(buf, 0, sizeof(buf));
memset(serial, 0, sizeof(serial));
#if defined(MBEDTLS_USE_PSA_CRYPTO)
psa_status_t status = psa_crypto_init();
if (status != PSA_SUCCESS) {
mbedtls_fprintf(stderr, "Failed to initialize PSA Crypto implementation: %d\n",
(int) status);
goto exit;
}
#endif /* MBEDTLS_USE_PSA_CRYPTO */
if (argc < 2) {
usage:
mbedtls_printf(USAGE);

View file

@ -65,6 +65,11 @@ int main(int argc, char *argv[])
int i;
char *p, *q;
/*
* Set to sane values
*/
mbedtls_x509_crl_init(&crl);
#if defined(MBEDTLS_USE_PSA_CRYPTO)
psa_status_t status = psa_crypto_init();
if (status != PSA_SUCCESS) {
@ -74,11 +79,6 @@ int main(int argc, char *argv[])
}
#endif /* MBEDTLS_USE_PSA_CRYPTO */
/*
* Set to sane values
*/
mbedtls_x509_crl_init(&crl);
if (argc < 2) {
usage:
mbedtls_printf(USAGE);

View file

@ -65,6 +65,11 @@ int main(int argc, char *argv[])
int i;
char *p, *q;
/*
* Set to sane values
*/
mbedtls_x509_csr_init(&csr);
#if defined(MBEDTLS_USE_PSA_CRYPTO)
psa_status_t status = psa_crypto_init();
if (status != PSA_SUCCESS) {
@ -74,11 +79,6 @@ int main(int argc, char *argv[])
}
#endif /* MBEDTLS_USE_PSA_CRYPTO */
/*
* Set to sane values
*/
mbedtls_x509_csr_init(&csr);
if (argc < 2) {
usage:
mbedtls_printf(USAGE);