헤더 파일에서의 #define 매크로 질문

anaud2의 이미지

안녕하세요 제가 짜고 있는 파일에 의문점이 있어서 질문드립니다.
/*test.c*/
#include

hmac_digest(ctx, &nettle_sha1, length,digest);
==============================================

기초 설명
test.c란 프로그램을 짜고 있고 그프로 그램은 nettle-meta.h(가져다씀)를 include하고 있는데요
nettle-meta.h를 구현해놓은 프로그램이 여러개가 있더라구요

test.c 에서 hmac_digest함수를 호출하면 인자값중 &nettle_sha1은 nettle-meta.h 헤더파일에
"extern const struct nettle_hash nettle_sha1;" 구문을 실행시켜
1.번 nettle_hash구조체를 가져다 쓴다 라고 생각이 됩니다.

첫번째 질문,
이때 sha-meta.c 에 const struct nettle_hash nettle_sha1 = _NETTLE_HASH(sha1, SHA1); 이부분이 있어서
이 실행이 될거 같은데 그렇다면 nettle-meta.h 1번 구조체에 2번 매크로 부분의 구조체(?)변수가 "=" 된다?
이렇게 해석이 됩니다. 그렇다면 이부분이 직접적으로 = 이걸로 각 1번 구조체에 대입이 되는건가요? 그렇게 가능한건가요?

두번째 질문,
첫번째 질문이 성공을 한다고 한다면 밑에 hmac.c에서
hmac.c
====================
void
hmac_digest(const void *outer, const void *inner, void *state,
const struct nettle_hash *hash,
unsigned length, uint8_t *dst)
nettle_hash 를 *hash 로 받고 있는데요

"hash->digest(state, hash->digest_size, digest);" 이부분을 실행을 한다면 첫번째 질문의 영향으로
hash->digest()함수가name##_digest(즉,sha1_digest())로바뀌어 다른곳에 있는 sha1_digest()함수를 호출할수 있게 될까요?

세번째 질문
#define 메크로 부분에서 #name과 ##NAME이부분에 대한 설명이 궁금합니다.

답변 부탁드립니다.
여러번들의 가르침이 저에게 큰힘이 된답니다.

================================================================================
헤더 파일 및 구현파일
================================================================================
/*nettle-meta.h */

typedef void (*nettle_hash_digest_func)(void *ctx,
unsigned length, uint8_t *dst);

extern const struct nettle_hash nettle_sha1;

void
hmac_digest(const void *outer, const void *inner, void *state,
const struct nettle_hash *hash,
unsigned length, uint8_t *dst)

/*1 */
struct nettle_hash
{
const char *name;
unsigned context_size;
unsigned digest_size;
unsigned block_size;
nettle_hash_init_func init;
nettle_hash_update_func update;
nettle_hash_digest_func digest;
};
/*2 */
#define _NETTLE_HASH(name, NAME) { \
#name, \
sizeof(struct name##_ctx), \
NAME##_DIGEST_SIZE, \
NAME##_DATA_SIZE, \
(nettle_hash_init_func) name##_init, \
(nettle_hash_update_func) name##_update, \
(nettle_hash_digest_func) name##_digest \
}
/*================================================*/

*/sha-meta.c
=============================================*/
#include

const struct nettle_hash nettle_sha1
= _NETTLE_HASH(sha1, SHA1);
/*=============================================*/

/*hmac.c*/
#include
void
hmac_digest(const void *outer, const void *inner, void *state,
const struct nettle_hash *hash,
unsigned length, uint8_t *dst)
{
uint8_t *digest = alloca(hash->digest_size);

hash->digest(state, hash->digest_size, digest);

memcpy(state, outer, hash->context_size);

hash->update(state, hash->digest_size, digest);
hash->digest(state, length, dst);

memcpy(state, inner, hash->context_size);
}
============================================================

댓글 달기

Filtered HTML

  • 텍스트에 BBCode 태그를 사용할 수 있습니다. URL은 자동으로 링크 됩니다.
  • 사용할 수 있는 HTML 태그: <p><div><span><br><a><em><strong><del><ins><b><i><u><s><pre><code><cite><blockquote><ul><ol><li><dl><dt><dd><table><tr><td><th><thead><tbody><h1><h2><h3><h4><h5><h6><img><embed><object><param><hr>
  • 다음 태그를 이용하여 소스 코드 구문 강조를 할 수 있습니다: <code>, <blockcode>, <apache>, <applescript>, <autoconf>, <awk>, <bash>, <c>, <cpp>, <css>, <diff>, <drupal5>, <drupal6>, <gdb>, <html>, <html5>, <java>, <javascript>, <ldif>, <lua>, <make>, <mysql>, <perl>, <perl6>, <php>, <pgsql>, <proftpd>, <python>, <reg>, <spec>, <ruby>. 지원하는 태그 형식: <foo>, [foo].
  • web 주소와/이메일 주소를 클릭할 수 있는 링크로 자동으로 바꿉니다.

BBCode

  • 텍스트에 BBCode 태그를 사용할 수 있습니다. URL은 자동으로 링크 됩니다.
  • 다음 태그를 이용하여 소스 코드 구문 강조를 할 수 있습니다: <code>, <blockcode>, <apache>, <applescript>, <autoconf>, <awk>, <bash>, <c>, <cpp>, <css>, <diff>, <drupal5>, <drupal6>, <gdb>, <html>, <html5>, <java>, <javascript>, <ldif>, <lua>, <make>, <mysql>, <perl>, <perl6>, <php>, <pgsql>, <proftpd>, <python>, <reg>, <spec>, <ruby>. 지원하는 태그 형식: <foo>, [foo].
  • 사용할 수 있는 HTML 태그: <p><div><span><br><a><em><strong><del><ins><b><i><u><s><pre><code><cite><blockquote><ul><ol><li><dl><dt><dd><table><tr><td><th><thead><tbody><h1><h2><h3><h4><h5><h6><img><embed><object><param>
  • web 주소와/이메일 주소를 클릭할 수 있는 링크로 자동으로 바꿉니다.

Textile

  • 다음 태그를 이용하여 소스 코드 구문 강조를 할 수 있습니다: <code>, <blockcode>, <apache>, <applescript>, <autoconf>, <awk>, <bash>, <c>, <cpp>, <css>, <diff>, <drupal5>, <drupal6>, <gdb>, <html>, <html5>, <java>, <javascript>, <ldif>, <lua>, <make>, <mysql>, <perl>, <perl6>, <php>, <pgsql>, <proftpd>, <python>, <reg>, <spec>, <ruby>. 지원하는 태그 형식: <foo>, [foo].
  • You can use Textile markup to format text.
  • 사용할 수 있는 HTML 태그: <p><div><span><br><a><em><strong><del><ins><b><i><u><s><pre><code><cite><blockquote><ul><ol><li><dl><dt><dd><table><tr><td><th><thead><tbody><h1><h2><h3><h4><h5><h6><img><embed><object><param><hr>

Markdown

  • 다음 태그를 이용하여 소스 코드 구문 강조를 할 수 있습니다: <code>, <blockcode>, <apache>, <applescript>, <autoconf>, <awk>, <bash>, <c>, <cpp>, <css>, <diff>, <drupal5>, <drupal6>, <gdb>, <html>, <html5>, <java>, <javascript>, <ldif>, <lua>, <make>, <mysql>, <perl>, <perl6>, <php>, <pgsql>, <proftpd>, <python>, <reg>, <spec>, <ruby>. 지원하는 태그 형식: <foo>, [foo].
  • Quick Tips:
    • Two or more spaces at a line's end = Line break
    • Double returns = Paragraph
    • *Single asterisks* or _single underscores_ = Emphasis
    • **Double** or __double__ = Strong
    • This is [a link](http://the.link.example.com "The optional title text")
    For complete details on the Markdown syntax, see the Markdown documentation and Markdown Extra documentation for tables, footnotes, and more.
  • web 주소와/이메일 주소를 클릭할 수 있는 링크로 자동으로 바꿉니다.
  • 사용할 수 있는 HTML 태그: <p><div><span><br><a><em><strong><del><ins><b><i><u><s><pre><code><cite><blockquote><ul><ol><li><dl><dt><dd><table><tr><td><th><thead><tbody><h1><h2><h3><h4><h5><h6><img><embed><object><param><hr>

Plain text

  • HTML 태그를 사용할 수 없습니다.
  • web 주소와/이메일 주소를 클릭할 수 있는 링크로 자동으로 바꿉니다.
  • 줄과 단락은 자동으로 분리됩니다.
댓글 첨부 파일
이 댓글에 이미지나 파일을 업로드 합니다.
파일 크기는 8 MB보다 작아야 합니다.
허용할 파일 형식: txt pdf doc xls gif jpg jpeg mp3 png rar zip.
CAPTCHA
이것은 자동으로 스팸을 올리는 것을 막기 위해서 제공됩니다.