Linux Box 에 설치된 암호화 알고리즘의 목록을 확인해 보려면 /proc/crypto 파일을 보면 된다. 

poplinux@poplinux:/proc$ cat crypto 
name         : hmac(sha1)
driver       : hmac(sha1-generic)
module       : kernel
priority     : 0
refcnt       : 1
selftest     : passed
type         : shash
blocksize    : 64
digestsize   : 20
.
.
.
nake        : md5
driver       : md5-generic
module       : kernel
priority     : 0
refcnt       : 9
selftest     : passed
type         : shash
blocksize    : 64
digestsize   : 16

 
 crypto 알고리즘을 등록할 때 사용하는 구조체인 struct crypto_alg 를 살펴보면 알고리즘 이름, 드라이버 이름을 지정하게 되어 있다.  

 하지만 md5 모듈을 보면 driver 이름은 지정하고 있지 않은 것을 확인 할 수 있다. 

crypto/md5.c

static struct shash_alg alg = {
  .digestsize = MD5_DIGEST_SIZE,
  .init          = md5_init,
  .update      = md5_update,
  .final         = md5_final,
  .export       = md5_export,
  .import       = md5_import,
  .descsize    = sizeof(struct md5_sate),
  .statesize    = sizeof(struct md5_state),
  .base         = {
     .cra_name  = "md5",
     .cra_flags   = CRYPTO_ALG_TYPE_SHASH,
     .cra_blocksize = MD5_HMAC_BLOCK_SIZE,
     .cra_module    = THIS_MODULE,
  }
};

 

 드라이버 이름을 지정하지 않았는데도 어떻게 "md5-generic" 라는 이름이 잡혀 있을까?

 그건 아래 코드와 같이 강제로 지정해 주기 때문이다. 
 
crypto/algapi.c

static inline int crypto_set_driver_name(struct crypto_alg *alg)
{
  static const char suffix[]= "-generic";
  char *driver_name = alg->cra_driver_name;
  int len;

  if(*driver_name)
      return 0;

  len = strlcpy(driver_name, alg->cra_name, CRYPTO_MAX_ALG_NAME);
  if(len + sizeof(suffix) > CRYPTO_MAX_ALG_NAME)
     return -ENAMETOLONG;

  memcpy(driver_name + len, suffix, sizeof(suffix));
  return 0;
}
 
 
블로그 이미지

김유석0

,
리눅스 커널의 이해(Understanding Linux Kenel 3rd Edition) 의 전자북 버전입니다. 

 
무료배포버전이니 편하게 사용하십시요.  
블로그 이미지

김유석0

,
 scatterlist 관련한 코드의 예시를 살펴보기 위해 커널 소스를 뒤져 보았는데 생각외로 광범위하게 사용되고 있어서 조금 놀랐다. 

 scatterlist 에 대해 알아보기 시작한 것이 crypto 쪽 작업 때문이었는데 crypto 뿐 아니라 filesystem, video driver, frame buffer 등등 분야를 가리지 않고 광범위하게 사용되고 있음을 확인 할 수 있었다. 

 그도 그럴것이 scatterlist 라는 것이 DMA 를 위한 것이니 DMA 를 사용하는 것에서는 모두 사용이 되고 있는 것이 당연할 것이다.

 무엇보다 scatterlist 의 가장 간단한 example 를 찾기 위해 구글을 뒤졌는데 아래와 같은 소스가 보기 쉽다는 답변을 확인 하였다.

 security/seclvl.c
 linux/fs/ecryptfs/ : eCryptfs file system 
 linux/drivers/staging/rtl8187se/ieee80211 : 802.11 wireless stack 

이중에서 가장 쉬운 코드가  security/seclvl.c 라는 설명이 있었는데 아쉽게도 kernel-2.6.18 이후론 없어진 것 같다. 
그래도 참조용으로 코드를 아래 정리해 보았다.
 

static int
plaintext_to_sha1(unsigned char *hash, const char *plaintext, unsigned int len)
{
  struct crypto_tfm *tfm;
  struct scatterlist sg;
  if (len > PAGE_SIZE) {
    seclvl_printk(0, KERN_ERR, "Plaintext password too large (%d "
            "characters).  Largest possible is %lu "
            "bytes.\n", len, PAGE_SIZE);
    return -EINVAL;
  }
  tfm = crypto_alloc_tfm("sha1", CRYPTO_TFM_REQ_MAY_SLEEP);
  if (tfm == NULL) {
    seclvl_printk(0, KERN_ERR,
            "Failed to load transform for SHA1\n");
    return -EINVAL;
  }
  sg_init_one(&sg, (u8 *)plaintext, len);
  crypto_digest_init(tfm);
  crypto_digest_update(tfm, &sg, 1);
  crypto_digest_final(tfm, hash);
  crypto_free_tfm(tfm);
  return 0; 
} 



아래 코드도 참조용으로 유용한 것으로 생각된다. (출처 : http://stackoverflow.com/questions/3869028/how-to-use-cryptoapi-in-the-linux-kernel-2-6)

struct crypto_hash *tfm = crypto_alloc_hash("sha1", 0, CRYPTO_ALG_ASYNC);
if (tfm == NULL)
    fail;
char *output_buf = kmalloc(crypto_hash_digestsize(tfm), GFP_KERNEL);
if (output_buf == NULL)
    fail;
struct scatterlist sg[2];
struct hash_desc desc = {.tfm = tfm};
ret = crypto_hash_init(&desc);
if (ret != 0)
    fail;
sg_init_table(sg, ARRAY_SIZE(sg));
sg_set_buf(&sg[0], "Hello", 5);
sg_set_buf(&sg[1], " World", 6);
ret = crypto_hash_digest(&desc, sg, 11, output_buf);
if (ret != 0)
    fail;

 
  참고로 scatterlist example 은 아니지만 암호화 테스트용 샘플 코드로써 암호화 API 를 사용하는 법을 쉽게 볼 수 있는 코드도 있다. 

  crypto/tcrypt.c


 
블로그 이미지

김유석0

,
넥스지에서 주어진 업무가 Crypto 기능을 Sync 에서 ASync 로 변경하는 일이어서 관련 문서들을 살펴보고 있다. 

Documentation/crypto/api-intro.txt 를 살펴보고 있는데 아래와 같이 시작을 하고 있다.


Scatterlist Cryptographic API

InTRODUCTION
The Scatterlist Crypto API takes page vectors(scatterlists) as arguments, and works directly on pages. In some cases(e.g. ECB mode ciphers), this will allow for pages to be encrypted in-place with no copying.
 
 
Scatter/gather 는 함께 움직이는 개념이다. 

Scatter 의 사전적 의미는
  scatter [skt]   단어장에 추가
  1.…을 뿌리다, 흩뿌리다, 살포하다, [씨]를 뿌리다[on, over, with ].
  2.흩어지다, 뿔뿔이 헤어지다, 분산하다.
  
 이고,

Gather 의 사전적 의미는

  gather
 [g]   단어장에 추가
  1.모으다, 끌어[긁어]모으다(in, up, together); [물건]을 하나하나 줍다.
 

DMA 전송에 있어서 데이터가 물리 메모리 상에 일렬로 정렬되어 있는 것은 아주 중요한 요소이다.

 커널 영역에서 메모리 관리를 할 때는 어렵긴 하지만(오버헤드가 크지만) 물리 메모리에 일렬로 정렬해서 사용하는 것이 가능하지만 사용자 영역에서는 이렇게 할 수가 없다.
 
 커널 영역에서 메모리를 물리 영역에 일렬로 정리해서 쓰는것이 가능하다고 했지만 여기 저기 흩어져 있는(Scatter) 메모리를 일렬로 정렬되어 있는 것처럼 사용할 수 있다면 좀더 편한 관리가 가능할 것이다. 

 다시 정리하면 Scatter/Gather 의 개념은 여기 저기 흩어져 있는 메모리(Scatter) 를 논리적으로 모아서(Gather) 연속된 물리적 메모리처럼 사용하는 것을 의미하며 Scatterlist 는 여기 저기 흩어져 있는 메모리(Scatter) 의 모음(array) 라고 보면 된다.

 DMA 전송에 사용되는 개념이다. 

    struct scatterlist{
      struct page *page;
      unsigned int offset;
      dma_addr_t dma_address;
      unsigned int length;
    } 

위 구조체를 보면 알겠지만 하나의 흩어져 있는 메모리의 정보를 담을 수 있도록 되어 있고 위 구조체가 여러개 모이면 마치 하나의 연속된 메모리처럼 동작시킬 수 있게 된다. 

아래 파일은 Scatter list 에 대한 간략한 diagram 이다. 
 

'development' 카테고리의 다른 글

[crypto] ASync crypto 와 Sync crypto api 함수명 특징  (0) 2011.10.10
[linux_kernel] scatterlist example  (0) 2011.09.27
[HW] TTL 과 RS232 에 대한 정리  (0) 2011.09.26
[HW] TTL Level 과 CMOS Level  (0) 2011.09.26
[crypto] IPSec  (0) 2011.09.23
블로그 이미지

김유석0

,

LFS(Linux From Scratch)

linux 2011. 9. 23. 09:47
 Linux 를 접하는 많은 개발자들은 자기만의 Linux 를 만들어 보고자 하는 소망을 가지는 것이 보통이다.

 하지만 "어디서부터 시작해서 어떻게 해야 할지" 를 모르기 때문에 결국 커널 컴파일 몇번 해보고 포기하는 것이 보통인 것이 현실이다.

 LFS(Linux From scratch) 를 처음 접한 것은 대학교 3학년 말이었던 것으로 기억한다.

 모든 팩키지를 Step by Step 으로 직접 configure 를 잡아서 컴파일하고 설치하면서 각종 의존성 문제 및 설정에 대한 기반 지식을 얻을 수 있었으며 LFS 를 해 본 경험은 아직까지도 나에게 큰 재산이 되고 있다.

 물론 LFS 이후에 젠투 라는 비슷한 팩키지가 나오긴 했다. 젠투와 LFS 의 공통점은 컴파일해서 설치한다는 것 뿐 LFS 는 그 복잡하고 어렵다는 젠투보다 더 하드코어라고 보면 된다.

 Linux 전문가가 되고 싶다면 꼭 한번 해 보길 바란다.

 http://www.linuxfromscratch.org/index.html


 

 

'linux' 카테고리의 다른 글

GNOME 설정  (0) 2011.09.27
Iconv 로 인코딩 변경하기  (0) 2011.09.26
우분투 run level 확인방법  (0) 2011.09.22
화면 캡쳐하는 방법  (0) 2011.09.21
svn+ssh 사용법  (0) 2011.09.21
블로그 이미지

김유석0

,

윈도우 공유 디렉토리를 Linux PC 에 마운트 시키는 방법.

1. 마운트 명령 사용

sudo mount -t cifs //192.168.1.250/rnd /home/poplinux/samba -o username=kay.kim,password=kay.kim,iocharset=euc-kr,rw,setuids,uid=1000

  cifs : 인터넷 파일 시스템
   //192.168.1.250/rnd : 마운트 하고 싶은 디렉토리 위치
   /home/poplinux/samba : 마운트할 위치
   -o : 이거 이하로는 옵션
   username:kay.kim : 삼바 디렉토리 사용자명
   password:kay.kim : 삼바 디렉토리 비밀번호
   iocharset=euc-kr : euc-kr 캐릭터 코드 사용
   rw : 읽고 쓰고 가능.
   setuids : 모름
   uid=1000 : 마운트할 삼바 디렉토리의 권한을 uid 1000 으로 지정. 참고로 uid 1000 은 내 계정(poplinux) 의 uid임

2. /etc/fstab 등록

 # /etc/fstab: static file system information.
#
# Use 'blkid -o value -s UUID' to print the universally unique identifier
# for a device; this may be used with UUID= as a more robust way to name
# devices that works even if disks are added and removed. See fstab(5).
#
# <file system> <mount point>   <type>  <options>       <dump>  <pass>
proc            /proc           proc    nodev,noexec,nosuid 0       0
# / was on /dev/sda1 during installation
UUID=1251eddf-bb2d-4249-828f-cb05d6686f55 /                     ext4    errors=remount-ro 0       1
# /home was on /dev/sda2 during installation
UUID=617694d7-93e6-4042-b549-bd8789bb75ea /home           ext4    defaults        0       2
# swap was on /dev/sda3 during installation
UUID=23621cd0-1719-44df-9f68-38999496a3c8 none                swap    sw              0       0
//192.168.1.250/rnd /home/poplinux/samba                         smbfs   username=kay.kim,password=kay.kim,rw,setuids,uid=1000,iocharset=euc-kr  0   0

'linux' 카테고리의 다른 글

삼바 마운트 하는법  (0) 2011.09.21
BuildRoot 시스템  (0) 2011.09.21
media player 개발  (0) 2011.02.07
X window programming site  (0) 2011.01.10
VLC player  (0) 2011.01.04
블로그 이미지

김유석0

,