Blame view
crypto/scatterwalk.h
2.24 KB
1da177e4c
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 |
/* * Cryptographic API. * * Copyright (c) 2002 James Morris <jmorris@intercode.com.au> * Copyright (c) 2002 Adam J. Richter <adam@yggdrasil.com> * Copyright (c) 2004 Jean-Luc Cooke <jlcooke@certainkey.com> * * This program is free software; you can redistribute it and/or modify it * under the terms of the GNU General Public License as published by the Free * Software Foundation; either version 2 of the License, or (at your option) * any later version. * */ #ifndef _CRYPTO_SCATTERWALK_H #define _CRYPTO_SCATTERWALK_H |
5c64097aa
|
17 |
|
1da177e4c
|
18 |
#include <linux/mm.h> |
5c64097aa
|
19 |
#include <linux/scatterlist.h> |
1da177e4c
|
20 |
|
5c64097aa
|
21 |
#include "internal.h" |
1da177e4c
|
22 |
|
1da177e4c
|
23 24 |
static inline struct scatterlist *sg_next(struct scatterlist *sg) { |
055bcee31
|
25 |
return (++sg)->length ? sg : (void *)sg->page; |
1da177e4c
|
26 |
} |
5c64097aa
|
27 28 |
static inline unsigned long scatterwalk_samebuf(struct scatter_walk *walk_in, struct scatter_walk *walk_out) |
1da177e4c
|
29 |
{ |
5c64097aa
|
30 31 32 33 34 35 36 37 38 |
return !(((walk_in->sg->page - walk_out->sg->page) << PAGE_SHIFT) + (int)(walk_in->offset - walk_out->offset)); } static inline unsigned int scatterwalk_pagelen(struct scatter_walk *walk) { unsigned int len = walk->sg->offset + walk->sg->length - walk->offset; unsigned int len_this_page = offset_in_page(~walk->offset) + 1; return len_this_page > len ? len : len_this_page; |
1da177e4c
|
39 |
} |
c774e93e2
|
40 41 |
static inline unsigned int scatterwalk_clamp(struct scatter_walk *walk, unsigned int nbytes) |
1da177e4c
|
42 |
{ |
5c64097aa
|
43 44 |
unsigned int len_this_page = scatterwalk_pagelen(walk); return nbytes > len_this_page ? len_this_page : nbytes; |
1da177e4c
|
45 46 47 48 49 |
} static inline void scatterwalk_advance(struct scatter_walk *walk, unsigned int nbytes) { |
1da177e4c
|
50 |
walk->offset += nbytes; |
1da177e4c
|
51 |
} |
954773779
|
52 53 54 55 56 |
static inline unsigned int scatterwalk_aligned(struct scatter_walk *walk, unsigned int alignmask) { return !(walk->offset & alignmask); } |
5c64097aa
|
57 58 59 60 61 62 63 64 65 |
static inline struct page *scatterwalk_page(struct scatter_walk *walk) { return walk->sg->page + (walk->offset >> PAGE_SHIFT); } static inline void scatterwalk_unmap(void *vaddr, int out) { crypto_kunmap(vaddr, out); } |
1da177e4c
|
66 |
void scatterwalk_start(struct scatter_walk *walk, struct scatterlist *sg); |
5c64097aa
|
67 68 69 |
void scatterwalk_copychunks(void *buf, struct scatter_walk *walk, size_t nbytes, int out); void *scatterwalk_map(struct scatter_walk *walk, int out); |
1da177e4c
|
70 71 72 |
void scatterwalk_done(struct scatter_walk *walk, int out, int more); #endif /* _CRYPTO_SCATTERWALK_H */ |