"Fossies" - the Fresh Open Source Software Archive

Member "tin-2.4.1/libcanlock/t/canlocktest.c" (1 Jun 2016, 2889 Bytes) of archive /linux/misc/tin-2.4.1.tar.gz:


As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) C and C++ source code syntax highlighting (style: standard) with prefixed line numbers and code folding option. Alternatively you can here view or download the uninterpreted source code file. For more information about "canlocktest.c" see the Fossies "Dox" file reference documentation.

    1 /* 
    2  * canlocktest.c - just checking.
    3  * 
    4  * This program doesn't really do anything but lightly exercise all the
    5  * library functions, so you can make sure it all compiled correctly. 
    6  * Everything's kept simple so that you can also see how they would be
    7  * called in a real application.
    8  */
    9 #include <stdio.h>
   10 #include <stdlib.h>
   11 #include <string.h>
   12 #include <sys/types.h>
   13 #include "canlock.h"
   14 
   15 #define BUFFSIZE 512
   16 
   17 void checker(char *key, char *lock);
   18 
   19 void
   20 checker(char *key, char *lock)
   21 {
   22     char
   23         *rawkey,
   24         *rawlock;
   25     char
   26         keytype[BUFFSIZE],
   27         locktype[BUFFSIZE];
   28 
   29     printf("L %s K %s ", lock, key);
   30 
   31     rawkey = lock_strip_alpha(key, keytype);
   32     rawlock = lock_strip_alpha(lock, locktype);
   33 
   34     if (!strcmp(keytype, locktype)) {
   35         if (!strcmp(keytype, "sha1")) {
   36             if (!sha_verify(rawkey, rawlock))
   37                 printf("sha1 OK\n");
   38             else
   39                 printf("sha1 no\n");
   40         }
   41         else
   42             printf("unknown\n");
   43     }
   44     else
   45         printf("Mismatch %s %s\n", keytype, locktype);
   46 }
   47 
   48 
   49 int
   50 main(void)
   51 {
   52     char
   53         cankey[256],
   54         canlock[256],
   55         *lkey,
   56         *llock;
   57     unsigned char
   58         secret[] = "fluffy",
   59         message[] = "<lkr905851929.22670@meow.invalid>";
   60 
   61     printf("Secret %s\n", secret);
   62     printf("Message %s\n", message);
   63 
   64     llock = sha_lock(secret, strlen((char *) secret),
   65                      message, strlen((char *) message));
   66     lkey = sha_key(secret, strlen((char *) secret),
   67                    message, strlen((char *)message));
   68 
   69     printf("%s%s %s\n", "SHA Expect Lock/Key:\n",
   70            "L sha1:ScU1gyAi9bd/aFEOyzg4m99lwXs=",
   71            "K sha1:C1Me/4n0l/V778Ih3J2UnhAoHrA=");
   72 
   73     checker(lkey, llock);
   74     free((void *) llock);
   75     free((void *) lkey);
   76     printf("---\n");
   77 
   78 /*********/
   79 
   80     printf("Testing against usefor cancel lock draft 01 samples...\n");
   81 
   82     sprintf(canlock, "%s", "sha1:bNXHc6ohSmeHaRHHW56BIWZJt+4=");
   83     sprintf(cankey, "%s", "sha1:aaaBBBcccDDDeeeFFF");
   84     checker(cankey, canlock);
   85     printf("---above should have been OK---\n");
   86 
   87 /*********/
   88 
   89     sprintf(canlock, "%s", "SHA1:H7/zsCUemvbvSDyARDaMs6AQu5s=");
   90     sprintf(cankey, "%s", "sha1:chW8hNeDx3iNUsGBU6/ezDk88P4=");
   91     checker(cankey, canlock);
   92 
   93     sprintf(canlock, "%s", "SHA1:H7/zsCUemvbvSDyARDaMs6AQu5s=");
   94     sprintf(cankey, "%s", "sha1:4srkWaRIzvK51ArAP:Hc");
   95     checker(cankey, canlock);
   96     printf("---above should have been OK, no---\n");
   97 
   98 /*********/
   99 
  100     sprintf(canlock, "%s", "sha1:JyEBL4w9/abCBuzCxMIE/E73GM4=");
  101     sprintf(cankey, "%s", "sha1:K4rkWRjRcXmIzvK51ArAP:Jy");
  102     checker(cankey, canlock);
  103 
  104     sprintf(canlock, "%s", "sha1:2Bmg+zWaY1noRiCdy8k3IapwSDU=");
  105     sprintf(cankey, "%s", "sha1:K4rkWRjRcXmIzvK51ArAP:Jy");
  106     checker(cankey, canlock);
  107     printf("---above should have been OK, no---\n");
  108     
  109     return 0;
  110 }