LCOV - code coverage report
Current view: top level - libavutil/tests - sha512.c (source / functions) Hit Total Coverage
Test: coverage.info Lines: 33 34 97.1 %
Date: 2017-10-18 21:45:51 Functions: 1 1 100.0 %

          Line data    Source code
       1             : /*
       2             :  * Copyright (C) 2007 Michael Niedermayer <michaelni@gmx.at>
       3             :  * Copyright (C) 2009 Konstantin Shishkov
       4             :  * Copyright (C) 2013 James Almer
       5             :  * based on BSD-licensed SHA-2 code by Aaron D. Gifford
       6             :  *
       7             :  * This file is part of FFmpeg.
       8             :  *
       9             :  * FFmpeg is free software; you can redistribute it and/or
      10             :  * modify it under the terms of the GNU Lesser General Public
      11             :  * License as published by the Free Software Foundation; either
      12             :  * version 2.1 of the License, or (at your option) any later version.
      13             :  *
      14             :  * FFmpeg is distributed in the hope that it will be useful,
      15             :  * but WITHOUT ANY WARRANTY; without even the implied warranty of
      16             :  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
      17             :  * Lesser General Public License for more details.
      18             :  *
      19             :  * You should have received a copy of the GNU Lesser General Public
      20             :  * License along with FFmpeg; if not, write to the Free Software
      21             :  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
      22             :  */
      23             : 
      24             : #include <stdio.h>
      25             : 
      26             : #include "libavutil/mem.h"
      27             : #include "libavutil/sha512.h"
      28             : 
      29           1 : int main(void)
      30             : {
      31             :     int i, j, k;
      32             :     struct AVSHA512 *ctx;
      33             :     unsigned char digest[64];
      34             :     static const int lengths[4] = { 224, 256, 384, 512 };
      35             : 
      36           1 :     ctx = av_sha512_alloc();
      37           1 :     if (!ctx)
      38           0 :         return 1;
      39             : 
      40           5 :     for (j = 0; j < 4; j++) {
      41           4 :         if (j < 2) printf("Testing SHA-512/%d\n", lengths[j]);
      42           2 :         else       printf("Testing SHA-%d\n", lengths[j]);
      43          16 :         for (k = 0; k < 3; k++) {
      44          12 :             av_sha512_init(ctx, lengths[j]);
      45          12 :             if (k == 0)
      46           4 :                 av_sha512_update(ctx, "abc", 3);
      47           8 :             else if (k == 1)
      48           4 :                 av_sha512_update(ctx, "abcdefghbcdefghicdefghijdefghijkefghijklfghijklmghijklmn"
      49             :                                        "hijklmnoijklmnopjklmnopqklmnopqrlmnopqrsmnopqrstnopqrstu", 112);
      50             :             else
      51     4000004 :                 for (i = 0; i < 1000*1000; i++)
      52     4000000 :                     av_sha512_update(ctx, "a", 1);
      53          12 :             av_sha512_final(ctx, digest);
      54         528 :             for (i = 0; i < lengths[j] >> 3; i++)
      55         516 :                 printf("%02X", digest[i]);
      56          12 :             putchar('\n');
      57             :         }
      58           4 :         switch (j) { //test vectors (from FIPS PUB 180-4 Apendix A)
      59           1 :         case 0:
      60           1 :             printf("4634270f 707b6a54 daae7530 460842e2 0e37ed26 5ceee9a4 3e8924aa\n"
      61             :                    "23fec5bb 94d60b23 30819264 0b0c4533 35d66473 4fe40e72 68674af9\n"
      62             :                    "37ab331d 76f0d36d e422bd0e deb22a28 accd487b 7a8453ae 965dd287\n");
      63           1 :             break;
      64           1 :         case 1:
      65           1 :             printf("53048e26 81941ef9 9b2e29b7 6b4c7dab e4c2d0c6 34fc6d46 e0e2f131 07e7af23\n"
      66             :                    "3928e184 fb8690f8 40da3988 121d31be 65cb9d3e f83ee614 6feac861 e19b563a\n"
      67             :                    "9a59a052 930187a9 7038cae6 92f30708 aa649192 3ef51943 94dc68d5 6c74fb21\n");
      68           1 :             break;
      69           1 :         case 2:
      70           1 :             printf("cb00753f 45a35e8b b5a03d69 9ac65007 272c32ab 0eded163 "
      71             :                    "1a8b605a 43ff5bed 8086072b a1e7cc23 58baeca1 34c825a7\n"
      72             :                    "09330c33 f71147e8 3d192fc7 82cd1b47 53111b17 3b3b05d2 "
      73             :                    "2fa08086 e3b0f712 fcc7c71a 557e2db9 66c3e9fa 91746039\n"
      74             :                    "9d0e1809 716474cb 086e834e 310a4a1c ed149e9c 00f24852 "
      75             :                    "7972cec5 704c2a5b 07b8b3dc 38ecc4eb ae97ddd8 7f3d8985\n");
      76           1 :             break;
      77           1 :         case 3:
      78           1 :             printf("ddaf35a1 93617aba cc417349 ae204131 12e6fa4e 89a97ea2 0a9eeee6 4b55d39a "
      79             :                    "2192992a 274fc1a8 36ba3c23 a3feebbd 454d4423 643ce80e 2a9ac94f a54ca49f\n"
      80             :                    "8e959b75 dae313da 8cf4f728 14fc143f 8f7779c6 eb9f7fa1 7299aead b6889018 "
      81             :                    "501d289e 4900f7e4 331b99de c4b5433a c7d329ee b6dd2654 5e96e55b 874be909\n"
      82             :                    "e718483d 0ce76964 4e2e42c7 bc15b463 8e1f98b1 3b204428 5632a803 afa973eb "
      83             :                    "de0ff244 877ea60a 4cb0432c e577c31b eb009c5c 2c49aa2e 4eadb217 ad8cc09b\n");
      84           1 :             break;
      85             :         }
      86             :     }
      87           1 :     av_free(ctx);
      88             : 
      89           1 :     return 0;
      90             : }

Generated by: LCOV version 1.13