• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

C++ sha1_update函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了C++中sha1_update函数的典型用法代码示例。如果您正苦于以下问题:C++ sha1_update函数的具体用法?C++ sha1_update怎么用?C++ sha1_update使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。



在下文中一共展示了sha1_update函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C++代码示例。

示例1: do_init

static void
do_init(void)
{
    uint8_t sha1[SHA1_DIGEST_SIZE];
    struct sha1_ctx sha1_ctx;
    uint8_t random_seed[16];
    struct timeval now;

    /* Get seed data. */
    get_entropy_or_die(random_seed, sizeof random_seed);
    xgettimeofday(&now);

    /* Convert seed into key. */
    sha1_init(&sha1_ctx);
    sha1_update(&sha1_ctx, random_seed, sizeof random_seed);
    sha1_update(&sha1_ctx, &now, sizeof now);
    sha1_update_int(&sha1_ctx, getpid());
#ifndef _WIN32
    sha1_update_int(&sha1_ctx, getppid());
    sha1_update_int(&sha1_ctx, getuid());
    sha1_update_int(&sha1_ctx, getgid());
#endif
    sha1_final(&sha1_ctx, sha1);

    /* Generate key. */
    BUILD_ASSERT(sizeof sha1 >= 16);
    aes128_schedule(&key, sha1);

    /* Generate initial counter. */
    get_entropy_or_die(counter, sizeof counter);
}
开发者ID:shettyg,项目名称:ovs,代码行数:31,代码来源:uuid.c


示例2: sha1_final

/* Add padding and return the message digest. */
static void sha1_final(struct crypto_tfm *tfm, u8 *out)
{
	struct sha1_ctx *sctx = crypto_tfm_ctx(tfm);
	__be32 *dst = (__be32 *)out;
	u32 i, index, padlen;
	__be64 bits;
	static const u8 padding[64] = { 0x80, };

	bits = cpu_to_be64(sctx->count << 3);

	/* Pad out to 56 mod 64 */
	index = sctx->count & 0x3f;
	padlen = (index < 56) ? (56 - index) : ((64+56) - index);
	sha1_update(tfm, padding, padlen);

	/* Append length */
	sha1_update(tfm, (const u8 *)&bits, sizeof(bits));

	/* Store state in digest */
	for (i = 0; i < 5; i++)
		dst[i] = cpu_to_be32(sctx->state[i]);

	/* Wipe context */
	memset(sctx, 0, sizeof *sctx);
}
开发者ID:PennPanda,项目名称:linux-repo,代码行数:26,代码来源:sha1_generic.c


示例3: test_one

static void
test_one(const struct test_vector *vec)
{
    uint8_t md[SHA1_DIGEST_SIZE];
    int i;

    /* All at once. */
    sha1_bytes(vec->data, vec->size, md);
    assert(!memcmp(md, vec->output, SHA1_DIGEST_SIZE));

    /* In two pieces. */
    for (i = 0; i < 20; i++) {
        int n0 = vec->size ? random_range(vec->size) : 0;
        int n1 = vec->size - n0;
        struct sha1_ctx sha1;

        sha1_init(&sha1);
        sha1_update(&sha1, vec->data, n0);
        sha1_update(&sha1, vec->data + n0, n1);
        sha1_final(&sha1, md);
        assert(!memcmp(md, vec->output, SHA1_DIGEST_SIZE));
    }

    putchar('.');
    fflush(stdout);
}
开发者ID:AlickHill,项目名称:Lantern,代码行数:26,代码来源:test-sha1.c


示例4: hmac_sha1_init

void
hmac_sha1_init(hmac_sha1_ctx *ctx, const void *key, size_t keylen)
{
	uint8_t keybuf[SHA1_BLOCK_LEN], pad[SHA1_BLOCK_LEN];

	/* prepare key */
	memset(keybuf, 0, sizeof keybuf);
        if (keylen > sizeof keybuf)
                sha1_complete(key, keylen, keybuf);
        else
                memcpy(keybuf, key, keylen);

	/* input pad */
	for (unsigned int i = 0; i < sizeof pad; ++i)
		pad[i] = 0x36 ^ keybuf[i];
	sha1_init(&ctx->ictx);
	sha1_update(&ctx->ictx, pad, sizeof pad);

	/* output pad */
	for (unsigned int i = 0; i < sizeof pad; ++i)
		pad[i] = 0x5c ^ keybuf[i];
	sha1_init(&ctx->octx);
	sha1_update(&ctx->octx, pad, sizeof pad);

	/* hide the evidence */
	memset(keybuf, 0, sizeof keybuf);
	memset(pad, 0, sizeof pad);
}
开发者ID:cryb-to,项目名称:cryb-to,代码行数:28,代码来源:cryb_hmac_sha1.c


示例5: sha1_hmac_init

void
sha1_hmac_init(struct sha1_hmac_context *ctx, const byte *key, uint keylen)
{
  byte keybuf[SHA1_BLOCK_SIZE], buf[SHA1_BLOCK_SIZE];

  /* Hash the key if necessary */
  if (keylen <= SHA1_BLOCK_SIZE)
  {
    memcpy(keybuf, key, keylen);
    memset(keybuf + keylen, 0, SHA1_BLOCK_SIZE - keylen);
  }
  else
  {
    sha1_hash_buffer(keybuf, key, keylen);
    memset(keybuf + SHA1_SIZE, 0, SHA1_BLOCK_SIZE - SHA1_SIZE);
  }

  /* Initialize the inner digest */
  sha1_init(&ctx->ictx);
  int i;
  for (i = 0; i < SHA1_BLOCK_SIZE; i++)
    buf[i] = keybuf[i] ^ 0x36;
  sha1_update(&ctx->ictx, buf, SHA1_BLOCK_SIZE);

  /* Initialize the outer digest */
  sha1_init(&ctx->octx);
  for (i = 0; i < SHA1_BLOCK_SIZE; i++)
    buf[i] = keybuf[i] ^ 0x5c;
  sha1_update(&ctx->octx, buf, SHA1_BLOCK_SIZE);
}
开发者ID:ColinBS,项目名称:bird,代码行数:30,代码来源:sha1.c


示例6: hmac_sha1_init

/* Begin SHA1 HMAC functions
*/
static void
hmac_sha1_init(hmac_sha1_ctx *ctx, const char *key, const int key_len)
{
    unsigned char  final_key[MAX_DIGEST_BLOCK_LEN] = {0};
    unsigned char  init_key[MAX_DIGEST_BLOCK_LEN]  = {0};
    int            final_len = key_len;

    if(key_len > MAX_DIGEST_BLOCK_LEN)
        final_len = MAX_DIGEST_BLOCK_LEN;

    memcpy(init_key, key, final_len);

    if(SHA1_BLOCK_LEN < key_len)
    {
        /* Calculate the digest of the key
        */
        sha1(final_key, init_key, final_len);
    }
    else
    {
        memcpy(final_key, init_key, key_len);
    }

    pad_init(ctx->block_inner_pad, ctx->block_outer_pad, final_key, final_len);

    sha1_init(&ctx->ctx_inside);
    sha1_update(&ctx->ctx_inside, ctx->block_inner_pad, SHA1_BLOCK_LEN);

    sha1_init(&ctx->ctx_outside);
    sha1_update(&ctx->ctx_outside, ctx->block_outer_pad, SHA1_BLOCK_LEN);

    return;
}
开发者ID:PHPDOTSQL,项目名称:fwknop,代码行数:35,代码来源:hmac.c


示例7: sha1_final

/*
 * The routine final terminates the computation and returns the digest. The
 * handle is prepared for a new cycle, but adding bytes to the handle will the
 * destroy the returned buffer.
 *
 * Returns: 20 bytes representing the digest.
 */
byte *
sha1_final(struct sha1_context *ctx)
{
  u32 t, msb, lsb;

  sha1_update(ctx, NULL, 0);	/* flush */

  t = ctx->nblocks;
  /* multiply by 64 to make a byte count */
  lsb = t << 6;
  msb = t >> 26;
  /* add the count */
  t = lsb;
  if ((lsb += ctx->count) < t)
    msb++;
  /* multiply by 8 to make a bit count */
  t = lsb;
  lsb <<= 3;
  msb <<= 3;
  msb |= t >> 29;

  if (ctx->count < 56)
  {
    /* enough room */
    ctx->buf[ctx->count++] = 0x80; /* pad */
    while (ctx->count < 56)
      ctx->buf[ctx->count++] = 0;  /* pad */
  }
  else
  {
    /* need one extra block */
    ctx->buf[ctx->count++] = 0x80; /* pad character */
    while (ctx->count < 64)
      ctx->buf[ctx->count++] = 0;
    sha1_update(ctx, NULL, 0);	/* flush */
    memset(ctx->buf, 0, 56); /* fill next block with zeroes */
  }

  /* append the 64 bit count */
  ctx->buf[56] = msb >> 24;
  ctx->buf[57] = msb >> 16;
  ctx->buf[58] = msb >>  8;
  ctx->buf[59] = msb;
  ctx->buf[60] = lsb >> 24;
  ctx->buf[61] = lsb >> 16;
  ctx->buf[62] = lsb >>  8;
  ctx->buf[63] = lsb;
  sha1_transform(ctx, ctx->buf);

  byte *p = ctx->buf;
#define X(a) do { put_u32(p, ctx->h##a); p += 4; } while(0)
  X(0);
  X(1);
  X(2);
  X(3);
  X(4);
#undef X

  return ctx->buf;
}
开发者ID:ColinBS,项目名称:bird,代码行数:67,代码来源:sha1.c


示例8: mppe_rekey

/*
 * Perform the MPPE rekey algorithm, from RFC 3078, sec. 7.3.
 * Well, not what's written there, but rather what they meant.
 */
static void mppe_rekey(ppp_mppe_state * state, int initial_key)
{
	sha1_context sha1_ctx;
	u8_t sha1_digest[SHA1_SIGNATURE_SIZE];

	/*
	 * Key Derivation, from RFC 3078, RFC 3079.
	 * Equivalent to Get_Key() for MS-CHAP as described in RFC 3079.
	 */
	sha1_starts(&sha1_ctx);
	sha1_update(&sha1_ctx, state->master_key, state->keylen);
	sha1_update(&sha1_ctx, mppe_sha1_pad1, SHA1_PAD_SIZE);
	sha1_update(&sha1_ctx, state->session_key, state->keylen);
	sha1_update(&sha1_ctx, mppe_sha1_pad2, SHA1_PAD_SIZE);
	sha1_finish(&sha1_ctx, sha1_digest);
	MEMCPY(state->session_key, sha1_digest, state->keylen);

	if (!initial_key) {
		arc4_setup(&state->arc4, sha1_digest, state->keylen);
		arc4_crypt(&state->arc4, state->session_key, state->keylen);
	}
	if (state->keylen == 8) {
		/* See RFC 3078 */
		state->session_key[0] = 0xd1;
		state->session_key[1] = 0x26;
		state->session_key[2] = 0x9e;
	}
	arc4_setup(&state->arc4, state->session_key, state->keylen);
}
开发者ID:EagleSmith,项目名称:ESP31B,代码行数:33,代码来源:mppe.c


示例9: sha1_finish

void sha1_finish(ctx_sha1* p_ctx,unsigned char digest[20])
{
	
	static unsigned char PADDING[64] =
	{
		0x80, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
		   0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
		   0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
		   0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0
	};
    unsigned char ml[8];	
    unsigned int hi = ( p_ctx->_count[0] >> 29 ) | ( p_ctx->_count[1] <<  3 );
    unsigned int lo = ( p_ctx->_count[0] <<  3 );
    unsigned int last,padn; 	

    PUT_UINT32(hi, ml, 0);
    PUT_UINT32(lo, ml, 4);

    last = p_ctx->_count[0] & 0x3F;
    padn = ( last < 56 ) ? ( 56 - last ) : ( 120 - last );

    sha1_update(p_ctx,PADDING, padn);
    sha1_update(p_ctx,ml, 8);

    PUT_UINT32(p_ctx->_state[0], digest,  0);
    PUT_UINT32(p_ctx->_state[1], digest,  4);
    PUT_UINT32(p_ctx->_state[2], digest,  8);
    PUT_UINT32(p_ctx->_state[3], digest, 12);
    PUT_UINT32(p_ctx->_state[4], digest, 16);

	/* Zeroize sensitive information.	*/
	sha1_initialize(p_ctx);
}
开发者ID:chenbk85,项目名称:reactor-9,代码行数:33,代码来源:sha1.c


示例10: hmac_sha1

void hmac_sha1(const uint8_t *key, int keyLength,
               const uint8_t *data, int dataLength,
               uint8_t *result, int resultLength) {
  SHA1_INFO ctx;
  uint8_t hashed_key[SHA1_DIGEST_LENGTH];
  if (keyLength > 64) {
    // The key can be no bigger than 64 bytes. If it is, we'll hash it down to
    // 20 bytes.
    sha1_init(&ctx);
    sha1_update(&ctx, key, keyLength);
    sha1_final(&ctx, hashed_key);
    key = hashed_key;
    keyLength = SHA1_DIGEST_LENGTH;
  }

  // The key for the inner digest is derived from our key, by padding the key
  // the full length of 64 bytes, and then XOR'ing each byte with 0x36.
  uint8_t tmp_key[64];
  for (int i = 0; i < keyLength; ++i) {
    tmp_key[i] = key[i] ^ 0x36;
  }
  if (keyLength < 64) {
    memset(tmp_key + keyLength, 0x36, 64 - keyLength);
  }

  // Compute inner digest
  sha1_init(&ctx);
  sha1_update(&ctx, tmp_key, 64);
  sha1_update(&ctx, data, dataLength);
  uint8_t sha[SHA1_DIGEST_LENGTH];
  sha1_final(&ctx, sha);

  // The key for the outer digest is derived from our key, by padding the key
  // the full length of 64 bytes, and then XOR'ing each byte with 0x5C.
  for (int i = 0; i < keyLength; ++i) {
    tmp_key[i] = key[i] ^ 0x5C;
  }
  memset(tmp_key + keyLength, 0x5C, 64 - keyLength);

  // Compute outer digest
  sha1_init(&ctx);
  sha1_update(&ctx, tmp_key, 64);
  sha1_update(&ctx, sha, SHA1_DIGEST_LENGTH);
  sha1_final(&ctx, sha);

  // Copy result to output buffer and truncate or pad as necessary
  memset(result, 0, resultLength);
  if (resultLength > SHA1_DIGEST_LENGTH) {
    resultLength = SHA1_DIGEST_LENGTH;
  }
  memcpy(result, sha, resultLength);

  // Zero out all internal data structures
  memset(hashed_key, 0, sizeof(hashed_key));
  memset(sha, 0, sizeof(sha));
  memset(tmp_key, 0, sizeof(tmp_key));
}
开发者ID:42p,项目名称:google-authenticator,代码行数:57,代码来源:hmac.c


示例11: verify_response_auth

/**
 * Verify an authentication block in a response.
 * Since this func updates the nonce_even in the session data it has to be
 * called when receiving a succesfull AUTH response.
 * This func can verify the first as well as the second auth block (for
 * double authorized commands).
 *
 * @param command_code	command code of the request
 * @param response	pointer to the request (w/ uninitialised auth data)
 * @param handles_len	length of the handles area in response
 * @param auth_session	pointer to the (valid) auth session to be used
 * @param response_auth	pointer to the auth block of the response to be verified
 * @param auth		authentication data (HMAC key)
 */
static u32 verify_response_auth(u32 command_code, const void *response,
				size_t response_len0, size_t handles_len,
				struct session_data *auth_session,
				const void *response_auth, const void *auth)
{
	u8 hmac_data[DIGEST_LENGTH * 3 + 1];
	u8 computed_auth[DIGEST_LENGTH];
	sha1_context hash_ctx;
	const size_t return_code_offset = 6;
	const size_t auth_continue_offset = 20;
	const size_t auth_auth_offset = 21;
	u8 auth_continue;

	if (!auth_session || !auth_session->valid)
		return TPM_AUTHFAIL;
	if (pack_byte_string(hmac_data, sizeof(hmac_data), "d",
			     0, command_code))
		return TPM_LIB_ERROR;
	if (response_len0 < TPM_RESPONSE_HEADER_LENGTH)
		return TPM_LIB_ERROR;

	sha1_starts(&hash_ctx);
	sha1_update(&hash_ctx, response + return_code_offset, 4);
	sha1_update(&hash_ctx, hmac_data, 4);
	if (response_len0 > TPM_RESPONSE_HEADER_LENGTH + handles_len)
		sha1_update(&hash_ctx,
			    response + TPM_RESPONSE_HEADER_LENGTH + handles_len,
			    response_len0 - TPM_RESPONSE_HEADER_LENGTH
			    - handles_len);
	sha1_finish(&hash_ctx, hmac_data);

	memcpy(auth_session->nonce_even, response_auth, DIGEST_LENGTH);
	auth_continue = ((u8 *)response_auth)[auth_continue_offset];
	if (pack_byte_string(hmac_data, sizeof(hmac_data), "ssb",
			     DIGEST_LENGTH,
			     response_auth,
			     DIGEST_LENGTH,
			     2 * DIGEST_LENGTH,
			     auth_session->nonce_odd,
			     DIGEST_LENGTH,
			     3 * DIGEST_LENGTH,
			     auth_continue))
		return TPM_LIB_ERROR;

	sha1_hmac(auth, DIGEST_LENGTH, hmac_data, sizeof(hmac_data),
		  computed_auth);

	if (memcmp(computed_auth, response_auth + auth_auth_offset,
		   DIGEST_LENGTH))
		return TPM_AUTHFAIL;

	return TPM_SUCCESS;
}
开发者ID:Noltari,项目名称:u-boot,代码行数:67,代码来源:tpm-v1.c


示例12: create_sha1

void create_sha1(char* secret_hex, uint8_t* text, int clen, uint8_t * sha){
//SHA1 generates 20B string
	SHA1_INFO ctx;
	sha1_init(&ctx);
 	char str[50];
	sha1_update(&ctx, secret_hex, strlen(secret_hex));
	// keep calling sha1_update if you have more data to hash...
	sha1_update(&ctx, text, clen);
	sha1_final(&ctx, sha);
        int i = 0;
 	return;
}
开发者ID:tahia-khan,项目名称:ece568,代码行数:12,代码来源:validateQRcode.c


示例13: main

int
main(int argc, char *argv[])
{
	unsigned int i;
	struct sha1_context ctx;
	char digest[SHA1_DIGEST_LENGTH];
	char output[2*SHA1_DIGEST_LENGTH + 5];

	/* silence gcc -Wextra */
	(void)argc;
	(void)argv;

	printf("Verifying SHA-1 implementation... ");
	fflush(stdout);

	for (i = 0; i < sizeof(test_data) / sizeof(test_data[0]); i++) {
		sha1_init(&ctx);
		sha1_update(&ctx, test_data[i], strlen(test_data[i]));
		sha1_final(&ctx, digest);
		digest_to_hex(digest, output);

		if (strcmp(output, test_results[i])) {
			fprintf(stdout, "FAIL\n");
			fprintf(stderr, "* hash of \"%s\" incorrect:\n"
			                "\t%s returned\n"
			                "\t%s is correct\n",
			                test_data[i], output, test_results[i]);
			return EXIT_FAILURE;
		}
	}

	/* the million 'a' vector we feed separately */
	sha1_init(&ctx);
	for (i = 0; i < 1000000; i++)
		sha1_update(&ctx, "a", 1);
	sha1_final(&ctx, digest);
	digest_to_hex(digest, output);

	if (strcmp(output, "34AA973C D4C4DAA4 F61EEB2B DBAD2731 6534016F")) {
		fprintf(stdout, "FAIL\n");
		fprintf(stderr, "* hash of a million a's is incorrect:\n"
		                "\t%s returned\n"
		                "\t34AA973C D4C4DAA4 F61EEB2B DBAD2731 6534016F"
		                " is correct\n", output);
		return 1;
	}

	printf("OK\n");
	fflush(stdout);

	return EXIT_SUCCESS;
}
开发者ID:timgarbos,项目名称:doorduino,代码行数:52,代码来源:sha1.c


示例14: websocket_derive_key

const char* websocket_derive_key(const char* key){
	static char hex[512] = {0,};
	static char magic[] = "258EAFA5-E914-47DA-95CA-C5AB0DC85B11";

	/* compute concaternated hash */
	sha1_t sha = sha1_new();
	sha1_update(sha, key, strlen(key));
	sha1_update(sha, magic, strlen(magic));

	/* encode hash as base64 */
	base64encode(sha1_hash_bytes(sha), 20, hex, sizeof(hex));

	sha1_free(sha);
	return hex;
}
开发者ID:frobnicators,项目名称:tweaklib,代码行数:15,代码来源:websocket.c


示例15: getFunctionId

u32 getFunctionId(const char* name)
{
	const char* suffix = "\x67\x59\x65\x99\x04\x25\x04\x90\x56\x64\x27\x49\x94\x89\x74\x1A"; // Symbol name suffix
	u8 output[20];

	// Compute SHA-1 hash
	sha1_context ctx;

	sha1_starts(&ctx);
	sha1_update(&ctx, (const u8*)name, strlen(name));
	sha1_update(&ctx, (const u8*)suffix, strlen(suffix));
	sha1_finish(&ctx, output);

	return (u32&)output[0];
}
开发者ID:FadzLeb,项目名称:rpcs3,代码行数:15,代码来源:Modules.cpp


示例16: ap_keying_material_pubkey_derivate

char *
ap_keying_material_pubkey_derivate(apr_pool_t *p, 
                                   const char *key, const char *pub)
{
	sha1_context sha1;
	sha1_init(&sha1);

	sha1_update(&sha1, (byte *)key, strlen(key));
	sha1_update(&sha1, (byte *)pub, strlen(pub));

	char *hash = (char *)sha1_final(&sha1);
	char *sec  = apr_palloc(p, SHA1_HEX_SIZE);
	mem_to_hex(sec, hash, SHA1_SIZE, 0);
	return sec;
}
开发者ID:n13l,项目名称:openaaa,代码行数:15,代码来源:ssl.c


示例17: create_request_auth

/**
 * Fill an authentication block in a request.
 * This func can create the first as well as the second auth block (for
 * double authorized commands).
 *
 * @param request	pointer to the request (w/ uninitialised auth data)
 * @param request_len0	length of the request without auth data
 * @param handles_len	length of the handles area in request
 * @param auth_session	pointer to the (valid) auth session to be used
 * @param request_auth	pointer to the auth block of the request to be filled
 * @param auth		authentication data (HMAC key)
 */
static u32 create_request_auth(const void *request, size_t request_len0,
			       size_t handles_len,
			       struct session_data *auth_session,
			       void *request_auth, const void *auth)
{
	u8 hmac_data[DIGEST_LENGTH * 3 + 1];
	sha1_context hash_ctx;
	const size_t command_code_offset = 6;
	const size_t auth_nonce_odd_offset = 4;
	const size_t auth_continue_offset = 24;
	const size_t auth_auth_offset = 25;

	if (!auth_session || !auth_session->valid)
		return TPM_LIB_ERROR;

	sha1_starts(&hash_ctx);
	sha1_update(&hash_ctx, request + command_code_offset, 4);
	if (request_len0 > TPM_REQUEST_HEADER_LENGTH + handles_len)
		sha1_update(&hash_ctx,
			    request + TPM_REQUEST_HEADER_LENGTH + handles_len,
			    request_len0 - TPM_REQUEST_HEADER_LENGTH
			    - handles_len);
	sha1_finish(&hash_ctx, hmac_data);

	sha1_starts(&hash_ctx);
	sha1_update(&hash_ctx, auth_session->nonce_odd, DIGEST_LENGTH);
	sha1_update(&hash_ctx, hmac_data, sizeof(hmac_data));
	sha1_finish(&hash_ctx, auth_session->nonce_odd);

	if (pack_byte_string(request_auth, TPM_REQUEST_AUTH_LENGTH, "dsb",
			     0, auth_session->handle,
			     auth_nonce_odd_offset, auth_session->nonce_odd,
			     DIGEST_LENGTH,
			     auth_continue_offset, 1))
		return TPM_LIB_ERROR;
	if (pack_byte_string(hmac_data, sizeof(hmac_data), "ss",
			     DIGEST_LENGTH,
			     auth_session->nonce_even,
			     DIGEST_LENGTH,
			     2 * DIGEST_LENGTH,
			     request_auth + auth_nonce_odd_offset,
			     DIGEST_LENGTH + 1))
		return TPM_LIB_ERROR;
	sha1_hmac(auth, DIGEST_LENGTH, hmac_data, sizeof(hmac_data),
		  request_auth + auth_auth_offset);

	return TPM_SUCCESS;
}
开发者ID:Noltari,项目名称:u-boot,代码行数:60,代码来源:tpm-v1.c


示例18: stub_sha1_update_fd

CAMLprim value stub_sha1_update_fd(value ctx, value fd, value len)
{
	CAMLparam3(ctx, fd, len);

	unsigned char buf[BLKSIZE];

	struct sha1_ctx ctx_dup = *GET_CTX_STRUCT(ctx);

	intnat ret, rest = Long_val(len);

	caml_release_runtime_system();
	do {
	    ret = rest < sizeof(buf) ? rest : sizeof(buf);
	    ret = read(Long_val(fd), buf, ret);
	    if (ret <= 0) break;
	    rest -= ret;
	    sha1_update(&ctx_dup, buf, ret);
	} while (ret > 0 && rest > 0);
	caml_acquire_runtime_system();

	if (ret < 0)
	    caml_failwith("read error");

	*GET_CTX_STRUCT(ctx) = ctx_dup;
	CAMLreturn(Val_long(Long_val(len) - rest));
}
开发者ID:madroach,项目名称:ocaml-sha,代码行数:26,代码来源:sha1_stubs.c


示例19: calculate_chunk_sha1

static int
calculate_chunk_sha1(struct filedes *in_fd, size_t this_chunk_size,
		     off_t offset, u8 sha1_md[])
{
	u8 buf[BUFFER_SIZE];
	SHA_CTX ctx;
	size_t bytes_remaining;
	size_t bytes_to_read;
	int ret;

	bytes_remaining = this_chunk_size;
	sha1_init(&ctx);
	do {
		bytes_to_read = min(bytes_remaining, sizeof(buf));
		ret = full_pread(in_fd, buf, bytes_to_read, offset);
		if (ret) {
			ERROR_WITH_ERRNO("Read error while calculating "
					 "integrity checksums");
			return ret;
		}
		sha1_update(&ctx, buf, bytes_to_read);
		bytes_remaining -= bytes_to_read;
		offset += bytes_to_read;
	} while (bytes_remaining);
	sha1_final(sha1_md, &ctx);
	return 0;
}
开发者ID:APBaltic,项目名称:wimlib,代码行数:27,代码来源:integrity.c


示例20: rsa_sign_msg

void
rsa_sign_msg(struct rsa_private_key *priv,mpz_t s,  uint8_t *msg, const size_t len)
{
      uint8_t digest[SHA1_DIGEST_SIZE];
      struct sha1_ctx sha1ctx;
      int i = 0,nloop = 0;
      

      if(priv == NULL || msg == NULL || len == 0) {
            die("priv == NULL || msg == NULL || len == 0");
      }

      //printf("\nMSG_LEN: %d\n",len);
      bzero(&sha1ctx,sizeof(struct sha1_ctx));
      bzero(&digest[0],SHA1_DIGEST_SIZE);

      mpz_init(s);
      sha1_init(&sha1ctx);
      sha1_update(&sha1ctx,len,msg);
      sha1_digest(&sha1ctx,SHA1_DIGEST_SIZE,digest);
            
      if (!rsa_sha1_sign_digest(priv, digest, s)) {
      //      out("rsa_sha1_sign...try again\n");
            rsa_sign_msg(priv,s,msg,len);
      }
}
开发者ID:icsecurity,项目名称:pbgp,代码行数:26,代码来源:test_nettle.c



注:本文中的sha1_update函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
C++ sha256函数代码示例发布时间:2022-05-30
下一篇:
C++ sha1_to_hex函数代码示例发布时间:2022-05-30
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap