Using SHA256 with Simple MQTT

Hello, i want to use SHA-256 to encrypt a Payload of my outgoing MQTT Messages.

I started to modify the NRF9160 MQTT Example. To test the encryption i copied Code from the sha256 Example.

The psa_crypto_init() will succeed but when i try to use psa_hash_compute with PSA_ALG_SHA256 i get the Error Code -134 which corresponds to "PSA_ERROR_NOT_SUPPORTED".

To fix this i tried to modify the prj.conf with configs i found in other Devzone Threads but it wont change the outcome.

Appreciate any Help

Philipp

  • I recreated my Project combining the mqtt_simple and sha256 examples.

    7870.mqtt_simple.zip

  • Hi

    When I run your project, this is the log I get, and it seems like it works fine.
    Do you get something else in the log?

    [00:00:00.544,158] <inf> mqtt_simple: The MQTT simple sample started
    [00:00:00.544,189] <inf> mqtt_simple: Starting SHA256 example...
    [00:00:00.544,189] <inf> mqtt_simple: Hashing using SHA256...
    [00:00:00.544,342] <inf> mqtt_simple: Hashing successful!
    [00:00:00.544,372] <inf> mqtt_simple: ---- Plaintext (len: 100): ----
    [00:00:00.544,403] <inf> mqtt_simple: Content:
                                          45 78 61 6d 70 6c 65 20  73 74 72 69 6e 67 20 74 |Example  string t
                                          6f 20 64 65 6d 6f 6e 73  74 72 61 74 65 20 62 61 |o demons trate ba
                                          73 69 63 20 75 73 61 67  65 20 6f 66 20 53 48 41 |sic usag e of SHA
                                          32 35 36 2e 00 00 00 00  00 00 00 00 00 00 00 00 |256..... ........
                                          00 00 00 00 00 00 00 00  00 00 00 00 00 00 00 00 |........ ........
                                          00 00 00 00 00 00 00 00  00 00 00 00 00 00 00 00 |........ ........
                                          00 00 00 00                                      |....             
    [00:00:00.544,403] <inf> mqtt_simple: ---- Plaintext end  ----
    [00:00:00.544,433] <inf> mqtt_simple: ---- SHA256 hash (len: 32): ----
    [00:00:00.544,433] <inf> mqtt_simple: Content:
                                          1f a2 7b 31 e2 4c c0 e3  f6 d8 d5 ab f6 1d 87 9f |..{1.L.. ........
                                          fb cb cc 2d d4 9c 49 ab  59 cf 9e 54 c2 80 65 56 |...-..I. Y..T..eV
    [00:00:00.544,464] <inf> mqtt_simple: ---- SHA256 hash end  ----
    [00:00:00.544,464] <inf> mqtt_simple: Verifying the SHA256 hash...
    [00:00:00.544,647] <inf> mqtt_simple: SHA256 verification successful!
    [00:00:00.544,647] <inf> mqtt_simple: Example finished successfully!
    [00:00:00.544,647] <inf> mqtt_simple: Disabling PSM and eDRX
    [00:00:00.551,605] <inf> mqtt_simple: LTE Link Connecting...
    [00:00:03.630,035] <inf> mqtt_simple: LTE Link Connected!
    [00:00:03.770,172] <inf> mqtt_simple: IPv4 Address found 137.135.83.217
    [00:00:03.770,629] <dbg> mqtt_simple: client_id_get: client_id = nrf-352656109434228
    [00:00:04.178,894] <inf> mqtt_simple: MQTT client connected
    [00:00:04.178,894] <inf> mqtt_simple: Subscribing to: my/subscribe/topic len 18
    [00:00:04.420,806] <inf> mqtt_simple: SUBACK packet id: 1234

    Regards,
    Sigurd Hellesvik

  • After i saw that the Example is working on your machine i reinstalled everything related to NRF and now it is working.

    Thanks for your Help

Related