⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 sha1.cc

📁 COPE the first practical network coding scheme which is developped on click
💻 CC
字号:
/* * sha1.{cc,hh} -- element implements IPsec SHA1 authentication (RFC 2404) * Benjie Chen * * Copyright (c) 1999-2000 Massachusetts Institute of Technology * * Permission is hereby granted, free of charge, to any person obtaining a * copy of this software and associated documentation files (the "Software"), * to deal in the Software without restriction, subject to the conditions * listed in the Click LICENSE file. These conditions include: you must * preserve this copyright notice, and you cannot mention the copyright * holders in advertising related to the Software without their permission. * The Software is provided WITHOUT ANY WARRANTY, EXPRESS OR IMPLIED. This * notice is a summary of the Click LICENSE file; the license in that file is * legally binding. */#include <click/config.h>#ifndef HAVE_IPSEC# error "Must #define HAVE_IPSEC in config.h"#endif#include "sha1.hh"#include "esp.hh"#include <click/ipaddress.hh>#include <click/confparse.hh>#include <clicknet/ip.h>#include <click/error.hh>#include <click/glue.hh>#include "elements/ipsec/sha1_impl.hh"CLICK_DECLS#define SHA_DIGEST_LEN 20IPsecAuthSHA1::IPsecAuthSHA1(){  add_input();  add_output();}IPsecAuthSHA1::~IPsecAuthSHA1(){}voidIPsecAuthSHA1::notify_noutputs(int n){   set_noutputs(n);}intIPsecAuthSHA1::configure(Vector<String> &conf, ErrorHandler *errh){  if (cp_va_parse(conf, this, errh,		  cpInteger, "Compute/Verify (0/1)", &_op, cpEnd) < 0)    return -1;  return 0;}intIPsecAuthSHA1::initialize(ErrorHandler *){  _drops = 0;  return 0;}Packet *IPsecAuthSHA1::simple_action(Packet *p){  // compute sha1  if (_op == COMPUTE_AUTH) {    unsigned char digest [SHA_DIGEST_LEN];    SHA1_ctx ctx;    SHA1_init (&ctx);    SHA1_update (&ctx, (u_char*) p->data(), p->length());    SHA1_final (digest, &ctx);    WritablePacket *q = p->put(12);    u_char *ah = ((u_char*)q->data())+q->length()-12;    memmove(ah, digest, 12);    return q;  }     else {    const u_char *ah = p->data()+p->length()-12;    unsigned char digest [SHA_DIGEST_LEN];    SHA1_ctx ctx;    SHA1_init (&ctx);    SHA1_update (&ctx, (u_char*) p->data(), p->length()-12);    SHA1_final (digest, &ctx);    if (memcmp(ah, digest, 12)) {      if (_drops == 0) 	click_chatter("Invalid SHA1 authentication digest");      _drops++;      if (noutputs() > 1) 	output(1).push(p);      else 	p->kill();       return 0;    }    p->take(12);    return p;  }}StringIPsecAuthSHA1::drop_handler(Element *e, void *){  IPsecAuthSHA1 *a = (IPsecAuthSHA1 *)e;  return String(a->_drops) + "\n";}voidIPsecAuthSHA1::add_handlers(){  add_read_handler("drops", drop_handler, 0);}CLICK_ENDDECLSEXPORT_ELEMENT(IPsecAuthSHA1)ELEMENT_MT_SAFE(IPsecAuthSHA1)

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -