LCOV - code coverage report
Current view: top level - common/utils - ripemd160.c (source / functions) Hit Total Coverage
Test: coverage.info Lines: 26 41 63.4 %
Date: 2024-04-25 23:25:41 Functions: 3 3 100.0 %

          Line data    Source code
       1             : /*
       2             :  * SPDX-License-Identifier: MPL-2.0
       3             :  *
       4             :  * This Source Code Form is subject to the terms of the Mozilla Public
       5             :  * License, v. 2.0.  If a copy of the MPL was not distributed with this
       6             :  * file, You can obtain one at http://mozilla.org/MPL/2.0/.
       7             :  *
       8             :  * Copyright 2024 MonetDB Foundation;
       9             :  * Copyright August 2008 - 2023 MonetDB B.V.;
      10             :  * Copyright 1997 - July 2008 CWI.
      11             :  */
      12             : 
      13             : #include "monetdb_config.h"
      14             : #include "rmd160.h"
      15             : #include "ripemd160.h"
      16             : 
      17             : void
      18       39100 : RIPEMD160Reset(RIPEMD160Context *ctxt)
      19             : {
      20       39100 :         MDinit(ctxt->digest);
      21       39100 :         ctxt->noverflow = 0;
      22       39100 :         ctxt->length = 0;
      23       39100 : }
      24             : 
      25             : void
      26       78199 : RIPEMD160Input(RIPEMD160Context *ctxt, const uint8_t *bytes, unsigned bytecount)
      27             : {
      28       78199 :         dword X[16];
      29             : 
      30       78199 :         ctxt->length += bytecount;
      31       78199 :         if (ctxt->noverflow > 0) {
      32           0 :                 assert(ctxt->noverflow < 64);
      33           0 :                 if (ctxt->noverflow + bytecount < 64) {
      34           0 :                         memcpy(ctxt->overflow + ctxt->noverflow, bytes, bytecount);
      35           0 :                         ctxt->noverflow += bytecount;
      36           0 :                         return;
      37             :                 }
      38           0 :                 unsigned l = 64 - ctxt->noverflow;
      39           0 :                 memcpy(ctxt->overflow + ctxt->noverflow, bytes, l);
      40           0 :                 const uint8_t *x = ctxt->overflow;
      41           0 :                 for (int i = 0; i < 16; i++) {
      42           0 :                         X[i] = BYTES_TO_DWORD(x);
      43           0 :                         x += 4;
      44             :                 }
      45           0 :                 bytecount -= l;
      46           0 :                 bytes += l;
      47           0 :                 ctxt->noverflow = 0;
      48           0 :                 MDcompress(ctxt->digest, X);
      49             :         }
      50      156397 :         while (bytecount >= 64) {
      51     1329366 :                 for (int i = 0; i < 16; i++) {
      52     1251168 :                         X[i] = BYTES_TO_DWORD(bytes);
      53     1251168 :                         bytes += 4;
      54             :                 }
      55       78198 :                 bytecount -= 64;
      56       78198 :                 MDcompress(ctxt->digest, X);
      57             :         }
      58       78199 :         if (bytecount > 0)
      59       39100 :                 memcpy(ctxt->overflow, bytes, bytecount);
      60       78199 :         ctxt->noverflow = bytecount;
      61             : }
      62             : 
      63             : void
      64       39100 : RIPEMD160Result(RIPEMD160Context *ctxt, uint8_t digest[RIPEMD160_DIGEST_LENGTH])
      65             : {
      66       39100 :         MDfinish(ctxt->digest, ctxt->overflow, (dword) ctxt->length, 0);
      67      234590 :         for (int i = 0; i < RIPEMD160_DIGEST_LENGTH; i += 4) {
      68      195490 :                 digest[i] = (uint8_t) ctxt->digest[i >> 2];
      69      195490 :                 digest[i + 1] = (uint8_t) (ctxt->digest[i >> 2] >> 8);
      70      195490 :                 digest[i + 2] = (uint8_t) (ctxt->digest[i >> 2] >> 16);
      71      195490 :                 digest[i + 3] = (uint8_t) (ctxt->digest[i >> 2] >> 24);
      72             :         }
      73       39099 : }

Generated by: LCOV version 1.14