'android ota sha'에 해당되는 글 1건

  1. 2013.11.04 [안드로이드]Android OTA image verification 관련 SHA 초기화 부분


xref: /system/core/libmincrypt/sha.c

286void SHA_init(SHA_CTX* ctx) {
287    ctx->state[0] = 0x67452301;
288    ctx->state[1] = 0xEFCDAB89;
289    ctx->state[2] = 0x98BADCFE;
290    ctx->state[3] = 0x10325476;
291    ctx->state[4] = 0xC3D2E1F0;
292    ctx->count = 0;
293}


/system/core/include/mincrypt/sha.h

37typedef struct SHA_CTX {
38    uint64_t count;
39    uint32_t state[5];
40#if defined(HAVE_ENDIAN_H) && defined(HAVE_LITTLE_ENDIAN)
41    union {
42        uint8_t b[64];
43        uint32_t w[16];
44    } buf;
45#else
46    uint8_t buf[64];
47#endif
48} SHA_CTX;


xref: /system/core/libmincrypt/sha.c

147void SHA_update(SHA_CTX* ctx, const void* data, int len) {
148    int i = ctx->count % sizeof(ctx->buf);
149    const uint8_t* p = (const uint8_t*)data;
150
151    ctx->count += len;
152
153    while (len > sizeof(ctx->buf) - i) {
154        memcpy(&ctx->buf.b[i], p, sizeof(ctx->buf) - i);
155        len -= sizeof(ctx->buf) - i;
156        p += sizeof(ctx->buf) - i;
157        SHA1_Transform(ctx);
158        i = 0;
159    }
160
161    while (len--) {
162        ctx->buf.b[i++] = *p++;
163        if (i == sizeof(ctx->buf)) {
164            SHA1_Transform(ctx);
165            i = 0;
166        }
167    }
168}


Posted by code cat