[BACK]Return to mac.c CVS log [TXT][DIR] Up to [local] / src / usr.bin / ssh

Diff for /src/usr.bin/ssh/mac.c between version 1.21 and 1.22

version 1.21, 2012/12/11 22:51:45 version 1.22, 2013/04/19 01:06:50
Line 45 
Line 45 
 #define SSH_UMAC        2       /* UMAC (not integrated with OpenSSL) */  #define SSH_UMAC        2       /* UMAC (not integrated with OpenSSL) */
 #define SSH_UMAC128     3  #define SSH_UMAC128     3
   
 struct {  struct macalg {
         char            *name;          char            *name;
         int             type;          int             type;
         const EVP_MD *  (*mdfunc)(void);          const EVP_MD *  (*mdfunc)(void);
Line 53 
Line 53 
         int             key_len;        /* just for UMAC */          int             key_len;        /* just for UMAC */
         int             len;            /* just for UMAC */          int             len;            /* just for UMAC */
         int             etm;            /* Encrypt-then-MAC */          int             etm;            /* Encrypt-then-MAC */
 } macs[] = {  };
   
   static const struct macalg macs[] = {
         /* Encrypt-and-MAC (encrypt-and-authenticate) variants */          /* Encrypt-and-MAC (encrypt-and-authenticate) variants */
         { "hmac-sha1",                          SSH_EVP, EVP_sha1, 0, 0, 0, 0 },          { "hmac-sha1",                          SSH_EVP, EVP_sha1, 0, 0, 0, 0 },
         { "hmac-sha1-96",                       SSH_EVP, EVP_sha1, 96, 0, 0, 0 },          { "hmac-sha1-96",                       SSH_EVP, EVP_sha1, 96, 0, 0, 0 },
Line 80 
Line 82 
         { NULL,                                 0, NULL, 0, 0, 0, 0 }          { NULL,                                 0, NULL, 0, 0, 0, 0 }
 };  };
   
   /* Returns a comma-separated list of supported MACs. */
   char *
   mac_alg_list(void)
   {
           char *ret = NULL;
           size_t nlen, rlen = 0;
           const struct macalg *m;
   
           for (m = macs; m->name != NULL; m++) {
                   if (ret != NULL)
                           ret[rlen++] = '\n';
                   nlen = strlen(m->name);
                   ret = xrealloc(ret, 1, rlen + nlen + 2);
                   memcpy(ret + rlen, m->name, nlen + 1);
                   rlen += nlen;
           }
           return ret;
   }
   
 static void  static void
 mac_setup_by_id(Mac *mac, int which)  mac_setup_by_alg(Mac *mac, const struct macalg *macalg)
 {  {
         int evp_len;          int evp_len;
         mac->type = macs[which].type;  
           mac->type = macalg->type;
         if (mac->type == SSH_EVP) {          if (mac->type == SSH_EVP) {
                 mac->evp_md = (*macs[which].mdfunc)();                  mac->evp_md = macalg->mdfunc();
                 if ((evp_len = EVP_MD_size(mac->evp_md)) <= 0)                  if ((evp_len = EVP_MD_size(mac->evp_md)) <= 0)
                         fatal("mac %s len %d", mac->name, evp_len);                          fatal("mac %s len %d", mac->name, evp_len);
                 mac->key_len = mac->mac_len = (u_int)evp_len;                  mac->key_len = mac->mac_len = (u_int)evp_len;
         } else {          } else {
                 mac->mac_len = macs[which].len / 8;                  mac->mac_len = macalg->len / 8;
                 mac->key_len = macs[which].key_len / 8;                  mac->key_len = macalg->key_len / 8;
                 mac->umac_ctx = NULL;                  mac->umac_ctx = NULL;
         }          }
         if (macs[which].truncatebits != 0)          if (macalg->truncatebits != 0)
                 mac->mac_len = macs[which].truncatebits / 8;                  mac->mac_len = macalg->truncatebits / 8;
         mac->etm = macs[which].etm;          mac->etm = macalg->etm;
 }  }
   
 int  int
 mac_setup(Mac *mac, char *name)  mac_setup(Mac *mac, char *name)
 {  {
         int i;          const struct macalg *m;
   
         for (i = 0; macs[i].name; i++) {          for (m = macs; m->name != NULL; m++) {
                 if (strcmp(name, macs[i].name) == 0) {                  if (strcmp(name, m->name) != 0)
                         if (mac != NULL)                          continue;
                                 mac_setup_by_id(mac, i);                  if (mac != NULL)
                         debug2("mac_setup: found %s", name);                          mac_setup_by_alg(mac, m);
                         return (0);                  debug2("mac_setup: found %s", name);
                 }                  return (0);
         }          }
         debug2("mac_setup: unknown %s", name);          debug2("mac_setup: unknown %s", name);
         return (-1);          return (-1);

Legend:
Removed from v.1.21  
changed lines
  Added in v.1.22