Skip to content

mbedtls with hardware SHA engine #976

Closed
@yoursunny

Description

@yoursunny

Hardware:

Board: Heltec WiFi Kit 32
Core Installation/update date: 70d0d46
IDE name: Arduino 1.8.5
Flash Frequency: 80Mhz
Upload Speed: 115200

Description:

CONFIG_MBEDTLS_HARDWARE_SHA option is disabled.
As a result, SHA256 computation is slow.

Sketch:

#include <mbedtls/sha256.h>

void setup() {
  Serial.begin(115200);
  Serial.println();
}

void loop() {
  unsigned long t0 = micros();
  mbedtls_sha256_context ctx;
  mbedtls_sha256_init(&ctx);
  for (int i = 0; i < 16777216; ++i) {
    Serial.printf("mode=%d\n", ctx.mode);
    mbedtls_sha256_update(&ctx, reinterpret_cast<const uint8_t*>("abcdefghbcdefghicdefghijdefghijkefghijklfghijklmghijklmnhijklmno"), 64);
  }
  uint8_t digest[32];
  mbedtls_sha256_finish(&ctx, digest);
  mbedtls_sha256_free(&ctx);
  unsigned long t1 = micros();

  for (int i = 0; i < sizeof(digest); ++i) {
    Serial.printf("%02x", digest[i]);
  }
  Serial.println();
  Serial.printf("duration=%lu\n", t1 - t0);
}

Debug Messages:

In "alt" version of mbedtls_sha256_context, there is a mode member that indicates whether hardware or software SHA engine is selected.
The sketch does not compile because the mbedtls_sha256_context only supports software implementation.

sha256-mbedtls:13: error: 'struct mbedtls_sha256_context' has no member named 'mode'

     Serial.printf("mode=%d\n", ctx.mode);

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    Status

    Done

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions