Lines Matching refs:gw
676 static void gcm_walk_start(struct gcm_sg_walk *gw, struct scatterlist *sg,
679 memset(gw, 0, sizeof(*gw));
680 gw->walk_bytes_remain = len;
681 scatterwalk_start(&gw->walk, sg);
684 static inline unsigned int _gcm_sg_clamp_and_map(struct gcm_sg_walk *gw)
688 gw->walk_bytes = scatterwalk_clamp(&gw->walk, gw->walk_bytes_remain);
689 while (!gw->walk_bytes) {
690 nextsg = sg_next(gw->walk.sg);
693 scatterwalk_start(&gw->walk, nextsg);
694 gw->walk_bytes = scatterwalk_clamp(&gw->walk,
695 gw->walk_bytes_remain);
697 gw->walk_ptr = scatterwalk_map(&gw->walk);
698 return gw->walk_bytes;
701 static inline void _gcm_sg_unmap_and_advance(struct gcm_sg_walk *gw,
704 gw->walk_bytes_remain -= nbytes;
705 scatterwalk_unmap(gw->walk_ptr);
706 scatterwalk_advance(&gw->walk, nbytes);
707 scatterwalk_done(&gw->walk, 0, gw->walk_bytes_remain);
708 gw->walk_ptr = NULL;
711 static int gcm_in_walk_go(struct gcm_sg_walk *gw, unsigned int minbytesneeded)
715 if (gw->buf_bytes && gw->buf_bytes >= minbytesneeded) {
716 gw->ptr = gw->buf;
717 gw->nbytes = gw->buf_bytes;
721 if (gw->walk_bytes_remain == 0) {
722 gw->ptr = NULL;
723 gw->nbytes = 0;
727 if (!_gcm_sg_clamp_and_map(gw)) {
728 gw->ptr = NULL;
729 gw->nbytes = 0;
733 if (!gw->buf_bytes && gw->walk_bytes >= minbytesneeded) {
734 gw->ptr = gw->walk_ptr;
735 gw->nbytes = gw->walk_bytes;
740 n = min(gw->walk_bytes, AES_BLOCK_SIZE - gw->buf_bytes);
741 memcpy(gw->buf + gw->buf_bytes, gw->walk_ptr, n);
742 gw->buf_bytes += n;
743 _gcm_sg_unmap_and_advance(gw, n);
744 if (gw->buf_bytes >= minbytesneeded) {
745 gw->ptr = gw->buf;
746 gw->nbytes = gw->buf_bytes;
749 if (!_gcm_sg_clamp_and_map(gw)) {
750 gw->ptr = NULL;
751 gw->nbytes = 0;
757 return gw->nbytes;
760 static int gcm_out_walk_go(struct gcm_sg_walk *gw, unsigned int minbytesneeded)
762 if (gw->walk_bytes_remain == 0) {
763 gw->ptr = NULL;
764 gw->nbytes = 0;
768 if (!_gcm_sg_clamp_and_map(gw)) {
769 gw->ptr = NULL;
770 gw->nbytes = 0;
774 if (gw->walk_bytes >= minbytesneeded) {
775 gw->ptr = gw->walk_ptr;
776 gw->nbytes = gw->walk_bytes;
780 scatterwalk_unmap(gw->walk_ptr);
781 gw->walk_ptr = NULL;
783 gw->ptr = gw->buf;
784 gw->nbytes = sizeof(gw->buf);
787 return gw->nbytes;
790 static int gcm_in_walk_done(struct gcm_sg_walk *gw, unsigned int bytesdone)
792 if (gw->ptr == NULL)
795 if (gw->ptr == gw->buf) {
796 int n = gw->buf_bytes - bytesdone;
798 memmove(gw->buf, gw->buf + bytesdone, n);
799 gw->buf_bytes = n;
801 gw->buf_bytes = 0;
803 _gcm_sg_unmap_and_advance(gw, bytesdone);
808 static int gcm_out_walk_done(struct gcm_sg_walk *gw, unsigned int bytesdone)
812 if (gw->ptr == NULL)
815 if (gw->ptr == gw->buf) {
817 if (!_gcm_sg_clamp_and_map(gw))
819 n = min(gw->walk_bytes, bytesdone - i);
820 memcpy(gw->walk_ptr, gw->buf + i, n);
821 _gcm_sg_unmap_and_advance(gw, n);
824 _gcm_sg_unmap_and_advance(gw, bytesdone);