From owner-svn-soc-all@FreeBSD.ORG Mon May 4 17:19:43 2015 Return-Path: Delivered-To: svn-soc-all@FreeBSD.org Received: from mx1.freebsd.org (mx1.freebsd.org [8.8.178.115]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by hub.freebsd.org (Postfix) with ESMTPS id 57BAF1C7 for ; Mon, 4 May 2015 17:19:43 +0000 (UTC) Received: from socsvn.freebsd.org (socsvn.freebsd.org [IPv6:2001:1900:2254:206a::50:2]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client did not present a certificate) by mx1.freebsd.org (Postfix) with ESMTPS id 46D251A12 for ; Mon, 4 May 2015 17:19:43 +0000 (UTC) Received: from socsvn.freebsd.org ([127.0.1.124]) by socsvn.freebsd.org (8.14.9/8.14.9) with ESMTP id t44HJhl6052622 for ; Mon, 4 May 2015 17:19:43 GMT (envelope-from def@FreeBSD.org) Received: (from www@localhost) by socsvn.freebsd.org (8.14.9/8.14.9/Submit) id t44HJgSl052605 for svn-soc-all@FreeBSD.org; Mon, 4 May 2015 17:19:42 GMT (envelope-from def@FreeBSD.org) Date: Mon, 4 May 2015 17:19:42 GMT Message-Id: <201505041719.t44HJgSl052605@socsvn.freebsd.org> X-Authentication-Warning: socsvn.freebsd.org: www set sender to def@FreeBSD.org using -f From: def@FreeBSD.org To: svn-soc-all@FreeBSD.org Subject: socsvn commit: r284997 - soc2013/def/crashdump-head/sbin/cryptcore MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-soc-all@freebsd.org X-Mailman-Version: 2.1.20 Precedence: list List-Id: SVN commit messages for the entire Summer of Code repository List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 04 May 2015 17:19:43 -0000 Author: def Date: Mon May 4 17:19:42 2015 New Revision: 284997 URL: http://svnweb.FreeBSD.org/socsvn/?view=rev&rev=284997 Log: Use arc4random_buf(3). Modified: soc2013/def/crashdump-head/sbin/cryptcore/cryptcore.c Modified: soc2013/def/crashdump-head/sbin/cryptcore/cryptcore.c ============================================================================== --- soc2013/def/crashdump-head/sbin/cryptcore/cryptcore.c Mon May 4 16:59:09 2015 (r284996) +++ soc2013/def/crashdump-head/sbin/cryptcore/cryptcore.c Mon May 4 17:19:42 2015 (r284997) @@ -9,13 +9,12 @@ #include #include +#include #include #include #include -#define CRYPTCORE_DEVRANDOM "/dev/random" - #define CRYPTCORE_CMD_GENKEY 0x01 #define CRYPTCORE_CMD_DECRYPT 0x02 @@ -35,7 +34,7 @@ uint8_t ciphertext[KERNELDUMP_CIPHERTEXT_SIZE]; FILE *fp; RSA *pubkey; - int err, fd, pubkeysize, size; + int err, pubkeysize; PJDLOG_ASSERT(pubkeyfile != NULL); @@ -43,18 +42,6 @@ if (pubkey == NULL) pjdlog_exit(1, "Unable to allocate an RSA structure"); - fd = open(CRYPTCORE_DEVRANDOM, O_RDONLY); - if (fd == -1) - pjdlog_exit(1, "Unable to open %s", CRYPTCORE_DEVRANDOM); - size = (int)read(fd, buf, KERNELDUMP_KEY_SIZE + KERNELDUMP_IV_SIZE); - err = errno; - close(fd); - if (size != KERNELDUMP_KEY_SIZE + KERNELDUMP_IV_SIZE) { - errno = err; - pjdlog_exit(1, "Unable to read data from %s", - CRYPTCORE_DEVRANDOM); - } - fp = fopen(pubkeyfile, "r"); if (fp == NULL) pjdlog_exit(1, "Unable to open %s", pubkeyfile); @@ -71,6 +58,7 @@ 8 * KERNELDUMP_CIPHERTEXT_SIZE); } + arc4random_buf(buf, sizeof(buf)); if (RSA_public_encrypt(KERNELDUMP_KEY_SIZE + KERNELDUMP_IV_SIZE, buf, ciphertext, pubkey, RSA_PKCS1_PADDING) != pubkeysize) { pjdlog_exit(1, "Unable to encrypt the one-time key");