• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

mendersoftware / mender-mcu / 1642966090

27 Jan 2025 05:00PM UTC coverage: 25.951% (+0.3%) from 25.63%
1642966090

push

gitlab-ci

vpodzime
feat: Support platform-specific or custom allocators

And use Zephyr-specific allocation functions on Zephyr by
default, using either a separate heap (default) or the system
heap.

This means we have to use our memory management functions instead
of the standard ones everywhere, even if they can actually just
call the standard ones.

Ticket: MEN-7808
Changelog: none
Signed-off-by: Vratislav Podzimek <vratislav.podzimek@northern.tech>

70 of 185 new or added lines in 12 files covered. (37.84%)

2 existing lines in 2 files now uncovered.

737 of 2840 relevant lines covered (25.95%)

8.85 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

70.97
/platform/sha/generic/mbedtls/src/mender-sha.c
1
/**
2
 * @file      mender-sha.c
3
 * @brief     Mender SHA interface for MbedTLS platform
4
 *
5
 * Copyright Northern.tech AS
6
 *
7
 * Licensed under the Apache License, Version 2.0 (the "License");
8
 * you may not use this file except in compliance with the License.
9
 * You may obtain a copy of the License at
10
 *
11
 *     http://www.apache.org/licenses/LICENSE-2.0
12
 *
13
 * Unless required by applicable law or agreed to in writing, software
14
 * distributed under the License is distributed on an "AS IS" BASIS,
15
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16
 * See the License for the specific language governing permissions and
17
 * limitations under the License.
18
 */
19

20
#include "mender-alloc.h"
21
#include "mender-sha.h"
22
#include "mender-log.h"
23

24
#include <mbedtls/sha256.h>
25

26
mender_err_t
27
mender_sha256_begin(mender_sha256_context_t *context) {
23✔
28
    assert(NULL != context);
23✔
29

30
    mbedtls_sha256_context *ctx = mender_malloc(sizeof(mbedtls_sha256_context));
23✔
31
    if (NULL == ctx) {
23✔
32
        mender_log_error("Unable to allocate memory");
×
33
        return MENDER_FAIL;
×
34
    }
35

36
    mbedtls_sha256_init(ctx);
23✔
37
    if (0 != mbedtls_sha256_starts(ctx, 0 /* Use SHA-256, not SHA-224 */)) {
23✔
38
        mender_log_error("Failed to start SHA-256 checksum calculation");
×
NEW
39
        mender_free(ctx);
×
40
        return MENDER_FAIL;
×
41
    }
42

43
    *context = ctx;
23✔
44
    return MENDER_OK;
23✔
45
}
46

47
mender_err_t
48
mender_sha256_update(mender_sha256_context_t context, const unsigned char *input, size_t length) {
51✔
49
    assert(NULL != context);
51✔
50

51
    mbedtls_sha256_context *ctx = context;
51✔
52
    if (0 != mbedtls_sha256_update(ctx, input, length)) {
51✔
53
        mender_log_error("Failed to update SHA-256 checksum calculation");
×
54
        return MENDER_FAIL;
×
55
    }
56

57
    return MENDER_OK;
51✔
58
}
59

60
mender_err_t
61
mender_sha256_finish(mender_sha256_context_t context, unsigned char *output) {
27✔
62
    mender_err_t            ret = MENDER_OK;
27✔
63
    mbedtls_sha256_context *ctx = context;
27✔
64
    if (NULL != ctx) {
27✔
65
        if (NULL != output) {
23✔
66
            if (0 != mbedtls_sha256_finish(ctx, output)) {
4✔
67
                mender_log_error("Failed to finish SHA-256 checksum calculation");
×
68
                ret = MENDER_FAIL;
×
69
            }
70
        }
71
        mbedtls_sha256_free(ctx);
23✔
72
        mender_free(ctx);
23✔
73
    }
74
    return ret;
27✔
75
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc