ima_crypto.c (2d8ad8719591fa803b0d589ed057fa46f49b7155) | ima_crypto.c (2fe5d6def1672ae6635dd71867bf36dcfaa7434b) |
---|---|
1/* 2 * Copyright (C) 2005,2006,2007,2008 IBM Corporation 3 * 4 * Authors: 5 * Mimi Zohar <zohar@us.ibm.com> 6 * Kylene Hall <kjhall@us.ibm.com> 7 * 8 * This program is free software; you can redistribute it and/or modify --- 34 unchanged lines hidden (view full) --- 43 * Calculate the MD5/SHA1 file digest 44 */ 45int ima_calc_hash(struct file *file, char *digest) 46{ 47 struct hash_desc desc; 48 struct scatterlist sg[1]; 49 loff_t i_size, offset = 0; 50 char *rbuf; | 1/* 2 * Copyright (C) 2005,2006,2007,2008 IBM Corporation 3 * 4 * Authors: 5 * Mimi Zohar <zohar@us.ibm.com> 6 * Kylene Hall <kjhall@us.ibm.com> 7 * 8 * This program is free software; you can redistribute it and/or modify --- 34 unchanged lines hidden (view full) --- 43 * Calculate the MD5/SHA1 file digest 44 */ 45int ima_calc_hash(struct file *file, char *digest) 46{ 47 struct hash_desc desc; 48 struct scatterlist sg[1]; 49 loff_t i_size, offset = 0; 50 char *rbuf; |
51 int rc; | 51 int rc, read = 0; |
52 53 rc = init_desc(&desc); 54 if (rc != 0) 55 return rc; 56 57 rbuf = kzalloc(PAGE_SIZE, GFP_KERNEL); 58 if (!rbuf) { 59 rc = -ENOMEM; 60 goto out; 61 } | 52 53 rc = init_desc(&desc); 54 if (rc != 0) 55 return rc; 56 57 rbuf = kzalloc(PAGE_SIZE, GFP_KERNEL); 58 if (!rbuf) { 59 rc = -ENOMEM; 60 goto out; 61 } |
62 if (!(file->f_mode & FMODE_READ)) { 63 file->f_mode |= FMODE_READ; 64 read = 1; 65 } |
|
62 i_size = i_size_read(file->f_dentry->d_inode); 63 while (offset < i_size) { 64 int rbuf_len; 65 66 rbuf_len = kernel_read(file, offset, rbuf, PAGE_SIZE); 67 if (rbuf_len < 0) { 68 rc = rbuf_len; 69 break; --- 5 unchanged lines hidden (view full) --- 75 76 rc = crypto_hash_update(&desc, sg, rbuf_len); 77 if (rc) 78 break; 79 } 80 kfree(rbuf); 81 if (!rc) 82 rc = crypto_hash_final(&desc, digest); | 66 i_size = i_size_read(file->f_dentry->d_inode); 67 while (offset < i_size) { 68 int rbuf_len; 69 70 rbuf_len = kernel_read(file, offset, rbuf, PAGE_SIZE); 71 if (rbuf_len < 0) { 72 rc = rbuf_len; 73 break; --- 5 unchanged lines hidden (view full) --- 79 80 rc = crypto_hash_update(&desc, sg, rbuf_len); 81 if (rc) 82 break; 83 } 84 kfree(rbuf); 85 if (!rc) 86 rc = crypto_hash_final(&desc, digest); |
87 if (read) 88 file->f_mode &= ~FMODE_READ; |
|
83out: 84 crypto_free_hash(desc.tfm); 85 return rc; 86} 87 88/* 89 * Calculate the hash of a given template 90 */ --- 53 unchanged lines hidden --- | 89out: 90 crypto_free_hash(desc.tfm); 91 return rc; 92} 93 94/* 95 * Calculate the hash of a given template 96 */ --- 53 unchanged lines hidden --- |