zoukankan      html  css  js  c++  java
  • 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 ); }
  • 相关阅读:
    Herny
    机器学习No.4
    机器学习No.3
    机器学习No.2
    机器学习No.1
    算法第五章上机实践报告
    算法第五章作业
    算法第四章实践报告
    算法第四章作业
    算法第三章作业
  • 原文地址:https://www.cnblogs.com/praiseslow/p/15720177.html
Copyright © 2011-2022 走看看