LCOV - code coverage report
Current view: top level - src/common - sha2_openssl.c (source / functions) Hit Total Coverage
Test: PostgreSQL 12beta2 Lines: 36 36 100.0 %
Date: 2019-06-19 16:07:09 Functions: 12 12 100.0 %
Legend: Lines: hit not hit

          Line data    Source code
       1             : /*-------------------------------------------------------------------------
       2             :  *
       3             :  * sha2_openssl.c
       4             :  *    Set of wrapper routines on top of OpenSSL to support SHA-224
       5             :  *    SHA-256, SHA-384 and SHA-512 functions.
       6             :  *
       7             :  * This should only be used if code is compiled with OpenSSL support.
       8             :  *
       9             :  * Portions Copyright (c) 2016-2019, PostgreSQL Global Development Group
      10             :  *
      11             :  * IDENTIFICATION
      12             :  *        src/common/sha2_openssl.c
      13             :  *
      14             :  *-------------------------------------------------------------------------
      15             :  */
      16             : 
      17             : #ifndef FRONTEND
      18             : #include "postgres.h"
      19             : #else
      20             : #include "postgres_fe.h"
      21             : #endif
      22             : 
      23             : #include <openssl/sha.h>
      24             : 
      25             : #include "common/sha2.h"
      26             : 
      27             : 
      28             : /* Interface routines for SHA-256 */
      29             : void
      30      770694 : pg_sha256_init(pg_sha256_ctx *ctx)
      31             : {
      32      770694 :     SHA256_Init((SHA256_CTX *) ctx);
      33      770694 : }
      34             : 
      35             : void
      36     1509026 : pg_sha256_update(pg_sha256_ctx *ctx, const uint8 *data, size_t len)
      37             : {
      38     1509026 :     SHA256_Update((SHA256_CTX *) ctx, data, len);
      39     1509026 : }
      40             : 
      41             : void
      42      770694 : pg_sha256_final(pg_sha256_ctx *ctx, uint8 *dest)
      43             : {
      44      770694 :     SHA256_Final(dest, (SHA256_CTX *) ctx);
      45      770694 : }
      46             : 
      47             : /* Interface routines for SHA-512 */
      48             : void
      49           8 : pg_sha512_init(pg_sha512_ctx *ctx)
      50             : {
      51           8 :     SHA512_Init((SHA512_CTX *) ctx);
      52           8 : }
      53             : 
      54             : void
      55           8 : pg_sha512_update(pg_sha512_ctx *ctx, const uint8 *data, size_t len)
      56             : {
      57           8 :     SHA512_Update((SHA512_CTX *) ctx, data, len);
      58           8 : }
      59             : 
      60             : void
      61           8 : pg_sha512_final(pg_sha512_ctx *ctx, uint8 *dest)
      62             : {
      63           8 :     SHA512_Final(dest, (SHA512_CTX *) ctx);
      64           8 : }
      65             : 
      66             : /* Interface routines for SHA-384 */
      67             : void
      68           8 : pg_sha384_init(pg_sha384_ctx *ctx)
      69             : {
      70           8 :     SHA384_Init((SHA512_CTX *) ctx);
      71           8 : }
      72             : 
      73             : void
      74           8 : pg_sha384_update(pg_sha384_ctx *ctx, const uint8 *data, size_t len)
      75             : {
      76           8 :     SHA384_Update((SHA512_CTX *) ctx, data, len);
      77           8 : }
      78             : 
      79             : void
      80           8 : pg_sha384_final(pg_sha384_ctx *ctx, uint8 *dest)
      81             : {
      82           8 :     SHA384_Final(dest, (SHA512_CTX *) ctx);
      83           8 : }
      84             : 
      85             : /* Interface routines for SHA-224 */
      86             : void
      87           8 : pg_sha224_init(pg_sha224_ctx *ctx)
      88             : {
      89           8 :     SHA224_Init((SHA256_CTX *) ctx);
      90           8 : }
      91             : 
      92             : void
      93           8 : pg_sha224_update(pg_sha224_ctx *ctx, const uint8 *data, size_t len)
      94             : {
      95           8 :     SHA224_Update((SHA256_CTX *) ctx, data, len);
      96           8 : }
      97             : 
      98             : void
      99           8 : pg_sha224_final(pg_sha224_ctx *ctx, uint8 *dest)
     100             : {
     101           8 :     SHA224_Final(dest, (SHA256_CTX *) ctx);
     102           8 : }

Generated by: LCOV version 1.13