mbedtls中sha256的使用特性



/*
* signv_sha256_calcu calculate the sha256 value upon one continous memory aera, there is no restriction on how many bytes the data are. * The SHA-256 method is a standard and the value can be calculated by mbedtls library. */ int sha256_calcu(const unsigned char *input, size_t len, unsigned char hash_value[]) { int ret = 0; // unsigned char *buf; mbedtls_sha256_context ctx; // buf = mbedtls_calloc( 1024, sizeof(unsigned char) ); mbedtls_sha256_init( &ctx ); do { /* SHA-256 */ if( ( ret = mbedtls_sha256_starts_ret( &ctx, 0 ) ) != 0 ) { mbedtls_sha256_free( &ctx ); // mbedtls_free( buf ); break; } ret = mbedtls_sha256_update_ret( &ctx, input, len); if( ret != 0 ) { mbedtls_sha256_free( &ctx ); // mbedtls_free( buf ); break; } if( ( ret = mbedtls_sha256_finish_ret( &ctx, hash_value ) ) != 0 ) { mbedtls_sha256_free( &ctx ); // mbedtls_free( buf ); break; } mbedtls_sha256_free( &ctx ); // mbedtls_free( buf ); }while(0); return( ret ); }

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM